예제 #1
0
        private void UpdateRotation(object sender, EventArgs e)
        {
            //Clear prior values
            //find a cleaner way to do this--loop?
            QuaternionWText.Clear();
            QuaternionXText.Clear();
            QuaternionYText.Clear();
            QuaternionZText.Clear();

            M11Text.Clear();
            M21Text.Clear();
            M31Text.Clear();
            OffsetXText.Clear();
            M12Text.Clear();
            M22Text.Clear();
            M32Text.Clear();
            OffsetYText.Clear();
            M13Text.Clear();
            M23Text.Clear();
            M33Text.Clear();
            OffsetZText.Clear();
            M14Text.Clear();
            M24Text.Clear();
            M34Text.Clear();
            M44Text.Clear();

            //<SnippetMatrixTransform3DView3DN2>

            Double axisX = System.Convert.ToDouble(RotationAxisXText.Text);
            Double axisY = System.Convert.ToDouble(RotationAxisYText.Text);
            Double axisZ = System.Convert.ToDouble(RotationAxisZText.Text);
            Double angle = System.Convert.ToDouble(RotationAngleText.Text);

            Vector3D axis = new Vector3D(axisX, axisY, axisZ);

            try
            {
                myAxisAngleRotation3D = new AxisAngleRotation3D(axis, angle);
            }
            catch
            {
                MessageBox.Show("Set non-null values for the axis Vector3D.");
            }

            myRotateTransform3D.Rotation = myAxisAngleRotation3D;

            //</SnippetMatrixTransform3DView3DN2>

            //update matrix display
            //<SnippetMatrixTransform3DView3DN13>
            rotationMatrix3D = myRotateTransform3D.Value;
            M11Text.Text     = rotationMatrix3D.M11.ToString();
            //</SnippetMatrixTransform3DView3DN13>
            M21Text.Text     = rotationMatrix3D.M21.ToString();
            M31Text.Text     = rotationMatrix3D.M31.ToString();
            OffsetXText.Text = rotationMatrix3D.OffsetX.ToString();
            M12Text.Text     = rotationMatrix3D.M12.ToString();
            M22Text.Text     = rotationMatrix3D.M22.ToString();
            M32Text.Text     = rotationMatrix3D.M32.ToString();
            OffsetYText.Text = rotationMatrix3D.OffsetY.ToString();
            M13Text.Text     = rotationMatrix3D.M13.ToString();
            M23Text.Text     = rotationMatrix3D.M23.ToString();
            M33Text.Text     = rotationMatrix3D.M33.ToString();
            OffsetZText.Text = rotationMatrix3D.OffsetZ.ToString();
            M14Text.Text     = rotationMatrix3D.M14.ToString();
            M24Text.Text     = rotationMatrix3D.M24.ToString();
            M34Text.Text     = rotationMatrix3D.M34.ToString();
            M44Text.Text     = rotationMatrix3D.M44.ToString();

            myprocTransformGroup.Children.Clear();
            myprocTransformGroup.Children.Add(myRotateTransform3D);
            topModelVisual3D.Transform = myprocTransformGroup;

            //<SnippetMatrixTransform3DView3DN3>
            //convert to quaternion and update display
            try
            {
                Quaternion tempQuaternion = new Quaternion(axis, angle);
                QuaternionWText.Text = tempQuaternion.W.ToString();
                QuaternionXText.Text = tempQuaternion.X.ToString();
                QuaternionYText.Text = tempQuaternion.Y.ToString();
                QuaternionZText.Text = tempQuaternion.Z.ToString();
            }
            catch
            {
                MessageBox.Show("Set non-null values for the axis Vector3D.");
            }
            //</SnippetMatrixTransform3DView3DN3>
        }
예제 #2
0
        private void UpdateQuaternionRotation3D(object sender, EventArgs e)
        {
            //Clear prior values
            //find a cleaner way to do this--loop?
            RotationAxisXText.Clear();
            RotationAxisYText.Clear();
            RotationAxisZText.Clear();
            RotationAngleText.Clear();

            M11Text.Clear();
            M21Text.Clear();
            M31Text.Clear();
            OffsetXText.Clear();
            M12Text.Clear();
            M22Text.Clear();
            M32Text.Clear();
            OffsetYText.Clear();
            M13Text.Clear();
            M23Text.Clear();
            M33Text.Clear();
            OffsetZText.Clear();
            M14Text.Clear();
            M24Text.Clear();
            M34Text.Clear();
            M44Text.Clear();

            //<SnippetMatrixTransform3DView3DN4>
            //Read new settings
            try
            {
                Double WValue = System.Convert.ToDouble(QuaternionWText.Text);
                Double XValue = System.Convert.ToDouble(QuaternionXText.Text);
                Double YValue = System.Convert.ToDouble(QuaternionYText.Text);
                Double ZValue = System.Convert.ToDouble(QuaternionZText.Text);

                endQuaternion = new Quaternion(XValue, YValue, ZValue, WValue);
            }
            catch
            {
                MessageBox.Show("Set non-null values for the quaternion.");
            }

            myQuaternionRotation3D       = new QuaternionRotation3D(endQuaternion);
            myRotateTransform3D.Rotation = myQuaternionRotation3D;

            //update matrix display
            qrotationMatrix3D = myRotateTransform3D.Value;
            //</SnippetMatrixTransform3DView3DN4>

            M11Text.Text     = qrotationMatrix3D.M11.ToString();
            M21Text.Text     = qrotationMatrix3D.M21.ToString();
            M31Text.Text     = qrotationMatrix3D.M31.ToString();
            OffsetXText.Text = qrotationMatrix3D.OffsetX.ToString();
            M12Text.Text     = qrotationMatrix3D.M12.ToString();
            M22Text.Text     = qrotationMatrix3D.M22.ToString();
            M32Text.Text     = qrotationMatrix3D.M32.ToString();
            OffsetYText.Text = qrotationMatrix3D.OffsetY.ToString();
            M13Text.Text     = qrotationMatrix3D.M13.ToString();
            M23Text.Text     = qrotationMatrix3D.M23.ToString();
            M33Text.Text     = qrotationMatrix3D.M33.ToString();
            OffsetZText.Text = qrotationMatrix3D.OffsetZ.ToString();
            M14Text.Text     = qrotationMatrix3D.M14.ToString();
            M24Text.Text     = qrotationMatrix3D.M24.ToString();
            M34Text.Text     = qrotationMatrix3D.M34.ToString();
            M44Text.Text     = qrotationMatrix3D.M44.ToString();

            //apply transform
            myprocTransformGroup.Children.Clear();
            myprocTransformGroup.Children.Add(myRotateTransform3D);
            topModelVisual3D.Transform = myprocTransformGroup;

            //convert to axis/angle and display results
            RotationAxisXText.Text = endQuaternion.Axis.X.ToString();
            RotationAxisYText.Text = endQuaternion.Axis.X.ToString();
            RotationAxisZText.Text = endQuaternion.Axis.X.ToString();
            RotationAngleText.Text = endQuaternion.Angle.ToString();
        }