@@ -22,10 +22,10 @@ public GimbalVisual3D()
22
22
{
23
23
var group = new Model3DGroup ( ) ;
24
24
group . Children . Add ( PsiRing . Model ) ;
25
- //BetaRing.Model.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90));
26
25
group . Children . Add ( ThetaRing . Model ) ;
27
26
group . Children . Add ( PhiRing . Model ) ;
28
27
this . Visual3DModel = group ;
28
+ OrientationChanged ( ) ;
29
29
}
30
30
31
31
@@ -42,6 +42,11 @@ public double Diameter
42
42
set { SetValue ( DiameterProperty , value ) ; }
43
43
}
44
44
45
+ /// <summary>
46
+ /// If the size of the Gimbal is changed, the rings must be resized as well
47
+ /// </summary>
48
+ /// <param name="d"></param>
49
+ /// <param name="e"></param>
45
50
private static void DiameterChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
46
51
{
47
52
var gimb = d as GimbalVisual3D ;
@@ -52,63 +57,57 @@ private static void DiameterChanged(DependencyObject d, DependencyPropertyChange
52
57
gimb . ThetaRing . RingDiameter = dia * 0.9 ;
53
58
gimb . PhiRing . RingDiameter = dia * 0.8 ;
54
59
}
60
+
55
61
56
-
57
-
58
-
59
- //private Transform3DGroup PhiRingTransform => { var ret = new Transform3DGroup(); return ret; }
60
-
61
-
62
-
63
-
62
+ /// <summary>
63
+ /// Transform individual rings accordingly
64
+ /// </summary>
64
65
private void OrientationChanged ( )
65
66
{
66
67
67
- var rotation = TransformationHelper . GetEulerangle ( Orientation ) ;
68
+ var rotation = TransformationHelper . QuaternionToEuler ( Orientation ) ;
68
69
69
70
70
71
rotation *= 180 / Math . PI ; // RAD to Degree converstion
71
72
72
-
73
-
74
-
73
+ var q = new Quaternion ( new Vector3D ( 0 , 0 , - 1 ) , rotation . Z ) ;
75
74
var tgPsiRing = new Transform3DGroup ( ) ;
76
- tgPsiRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( new Vector3D ( 0 , 0 , 1 ) , rotation . X ) ) ) ;
77
-
75
+ tgPsiRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( q . Axis , q . Angle ) ) ) ;
78
76
this . PsiRing . Model . Transform = tgPsiRing ;
77
+
78
+
79
+
79
80
80
81
var tgthetaRing = new Transform3DGroup ( ) ;
82
+ q *= new Quaternion ( new Vector3D ( 0 , - 1 , 0 ) , rotation . Y ) ;
81
83
tgthetaRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( new Vector3D ( 1 , 0 , 0 ) , 90 ) ) ) ;
82
- tgthetaRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( new Vector3D ( 0 , 0 , 1 ) , rotation . X ) ) ) ;
83
- tgthetaRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( new Vector3D ( 0 , 1 , 0 ) , rotation . Y ) ) ) ;
84
+ tgthetaRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( q . Axis , q . Angle ) ) ) ;
85
+
84
86
85
87
this . ThetaRing . Model . Transform = tgthetaRing ;
86
-
88
+ q *= new Quaternion ( new Vector3D ( 1 , 0 , 0 ) , rotation . X ) ;
87
89
var tgPhiRing = new Transform3DGroup ( ) ;
88
90
tgPhiRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( new Vector3D ( 0 , 1 , 0 ) , - 90 ) ) ) ;
89
- tgPhiRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( new Vector3D ( 0 , 0 , 1 ) , rotation . X ) ) ) ;
90
- tgPhiRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( new Vector3D ( 0 , 1 , 0 ) , rotation . Y ) ) ) ;
91
- tgPhiRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( new Vector3D ( 1 , 0 , 0 ) , rotation . Z ) ) ) ;
92
-
91
+ tgPhiRing . Children . Add ( new RotateTransform3D ( new AxisAngleRotation3D ( q . Axis , q . Angle ) ) ) ;
93
92
this . PhiRing . Model . Transform = tgPhiRing ;
94
93
95
94
}
96
95
97
96
98
97
public static readonly DependencyProperty OrientationProperty =
99
- DependencyProperty . Register ( nameof ( Orientation ) , typeof ( Matrix3D ) , typeof ( GimbalVisual3D ) ,
100
- new UIPropertyMetadata ( new Matrix3D ( ) , ( s , d ) => ( s as GimbalVisual3D ) . OrientationChanged ( ) ) ) ;
98
+ DependencyProperty . Register ( nameof ( Orientation ) , typeof ( Quaternion ) , typeof ( GimbalVisual3D ) ,
99
+ new UIPropertyMetadata ( new Quaternion ( ) , ( s , d ) => ( s as GimbalVisual3D ) . OrientationChanged ( ) ) ) ;
101
100
102
101
103
- public Matrix3D Orientation
102
+ /// <summary>
103
+ /// Property for the current flight orientation
104
+ /// </summary>
105
+ public Quaternion Orientation
104
106
{
105
- get => ( Matrix3D ) GetValue ( OrientationProperty ) ;
107
+ get => ( Quaternion ) GetValue ( OrientationProperty ) ;
106
108
set { SetValue ( OrientationProperty , value ) ; }
107
109
}
108
110
109
-
110
-
111
-
112
111
113
112
114
113
#endregion
0 commit comments