/
MainWindow.xaml.cs
106 lines (88 loc) · 3.79 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace CamFootprintTester
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
bool enableSlider = false;
public MainWindow()
{
InitializeComponent();
acHeight.Value = 50.0;
vfv.Value = 30;
hfv.Value = 60;
PointCollection pointCol = new PointCollection(4);
pointCol.Add(new Point(0, 0));
pointCol.Add(new Point(150, 150));
pointCol.Add(new Point(300, 150));
pointCol.Add(new Point(150, 0));
footprint.Points = pointCol;
enableSlider = true;
genNewFootprint();
}
private void SliderValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (enableSlider)
genNewFootprint();
}
private void genNewFootprint()
{
var TR = new Quaternion(-hfv.Value / 2, vfv.Value / 2, 0, true);
var TL = new Quaternion( hfv.Value / 2, vfv.Value / 2, 0, true);
var BR = new Quaternion(-hfv.Value / 2, -vfv.Value / 2, 0, true);
var BL = new Quaternion( hfv.Value / 2, -vfv.Value / 2, 0, true);
var gimRot = new Quaternion(gimRoll.Value, gimPitch.Value, gimYaw.Value, true);
var acRot = new Quaternion(acRoll.Value, acPitch.Value, acYaw.Value, true);
double r, p, y;
Quaternion TR1 = acRot.Multiply(gimRot.Multiply(TR));
Quaternion TL1 = acRot.Multiply(gimRot.Multiply(TL));
Quaternion BR1 = acRot.Multiply(gimRot.Multiply(BR));
Quaternion BL1 = acRot.Multiply(gimRot.Multiply(BL));
var pc = new PointCollection(4);
pc.Add(getPointOnGround(TR1));
pc.Add(getPointOnGround(TL1));
pc.Add(getPointOnGround(BL1));
pc.Add(getPointOnGround(BR1));
var boundPc = bindToViewerDimensions(pc);
footprint.Points = boundPc;
Canvas.SetLeft(toprightcorner, boundPc[0].X - (toprightcorner.Width / 2));
Canvas.SetTop(toprightcorner, boundPc[0].Y - (toprightcorner.Height / 2));
Canvas.SetLeft(topleftcorner, boundPc[1].X - (topleftcorner.Width / 2));
Canvas.SetTop(topleftcorner, boundPc[1].Y - (topleftcorner.Height / 2));
}
private Point getPointOnGround(Quaternion q)
{
double r;
double p;
double y;
q.ConvertToEuler(out r, out p, out y, true);
r = limit(r, -anglelimit.Value, anglelimit.Value);
p = limit(p, -anglelimit.Value, anglelimit.Value);
double dx = acHeight.Value * Math.Tan(q.Radians(r));
double dy = acHeight.Value * Math.Tan(q.Radians(p));
double utmx = dx * Math.Cos(q.Radians(y)) - dy * Math.Sin(q.Radians(y)) + 150; // 150 is the centre of viewer. (-) sign is required on dy due to viewer
double utmy = -dx * Math.Sin(q.Radians(y)) - dy * Math.Cos(q.Radians(y)) + 150; // 150 is the centre of viewer. (-) sign is required on dx due to viewer
return new Point(utmx , utmy );
}
private PointCollection bindToViewerDimensions(PointCollection pc)
{
var outpc = new PointCollection(4);
foreach(Point p in pc)
{
outpc.Add(new Point(limit(p.X, 0, 300), limit(p.Y, 0, 300)));
}
return outpc;
}
public double limit(double value, double min, double max)
{
if (value < min) { return min; }
if (value > max) { return max; }
return value;
}
}
}