當前位置: 首頁>>代碼示例>>C#>>正文


C# Media3D.Quaternion類代碼示例

本文整理匯總了C#中System.Windows.Media.Media3D.Quaternion的典型用法代碼示例。如果您正苦於以下問題:C# Quaternion類的具體用法?C# Quaternion怎麽用?C# Quaternion使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Quaternion類屬於System.Windows.Media.Media3D命名空間,在下文中一共展示了Quaternion類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: UpdateSlaves

        // Updates the matrices of the slaves using the rotation quaternion.
        private void UpdateSlaves(Quaternion q, double s, Vector3D t)
        {

            if (_slaves != null)
            {
                foreach (Viewport3D i in _slaves)
                {
                    ModelVisual3D mv = i.Children[0] as ModelVisual3D;
                    Transform3DGroup t3dg = mv.Transform as Transform3DGroup;

                    ScaleTransform3D _GroupScaleTransform = t3dg.Children[0] as ScaleTransform3D;
                    RotateTransform3D _GroupRotateTransform = t3dg.Children[1] as RotateTransform3D;
                    TranslateTransform3D _GroupTranslateTransform = t3dg.Children[2] as TranslateTransform3D;

                    _GroupScaleTransform.ScaleX = s;
                    _GroupScaleTransform.ScaleY = s;
                    _GroupScaleTransform.ScaleZ = s;
                    _GroupRotateTransform.Rotation = new AxisAngleRotation3D(q.Axis, q.Angle);
                    _GroupTranslateTransform.OffsetX = t.X;
                    _GroupTranslateTransform.OffsetY = t.Y;
                    _GroupTranslateTransform.OffsetZ = t.Z;

                }
            }
        }
開發者ID:xs2ranjeet,項目名稱:13ns9-1spr,代碼行數:26,代碼來源:Trackball.cs

示例2: NewtonQuaternion

		public NewtonQuaternion(Quaternion pQuaternion)
		{
			NWQuaternion[ 0 ] = (float)pQuaternion.X;
			NWQuaternion[ 1 ] = (float)pQuaternion.Y;
			NWQuaternion[ 2 ] = (float)pQuaternion.Z;
			NWQuaternion[ 3 ] = (float)pQuaternion.W;
		}
開發者ID:charlierix,項目名稱:AsteroidMiner,代碼行數:7,代碼來源:StructuresConverter.cs

示例3: Track

		private void Track(Point currentPosition)
		{
			var currentPosition3D = this.ProjectToTrackball(this.ActualWidth, this.ActualHeight, currentPosition);

			var axis = Vector3D.CrossProduct(this._previousPosition3D, currentPosition3D);
			var angle = Vector3D.AngleBetween(this._previousPosition3D, currentPosition3D);

			// quaterion will throw if this happens - sometimes we can get 3D positions that
			// are very similar, so we avoid the throw by doing this check and just ignoring
			// the event 
			if (axis.Length == 0)
				return;

			var delta = new Quaternion(axis, -angle);

			// Get the current orientantion from the RotateTransform3D
			var r = this._rotation;
			var q = new Quaternion(this._rotation.Axis, this._rotation.Angle);

			// Compose the delta with the previous orientation
			q *= delta;

			// Write the new orientation back to the Rotation3D
			this._rotation.Axis = q.Axis;
			this._rotation.Angle = q.Angle;

			this._previousPosition3D = currentPosition3D;
		}
開發者ID:g-yonchev,項目名稱:Telerik-Academy,代碼行數:28,代碼來源:TrackballDecorator.cs

示例4: MyPosition

 public MyPosition(int possessingId, Vector3D position, Quaternion rotation, EnumMobileState mobileState)
 {
     PossessingId = possessingId;
     Position = position;
     Rotation = rotation;
     MobileState = mobileState;
 }
開發者ID:timothypratley,項目名稱:Strive.NET,代碼行數:7,代碼來源:Position.cs

示例5: CalculateCurrentQuaternion

        private void CalculateCurrentQuaternion(double timeFactor)
        {
            if (LERPActivated)
            {
                var x = startQuaternion.X * (1 - timeFactor) + endQuaternion.X * timeFactor;
                var y = startQuaternion.Y * (1 - timeFactor) + endQuaternion.Y * timeFactor;
                var z = startQuaternion.Z * (1 - timeFactor) + endQuaternion.Z * timeFactor;
                var w = startQuaternion.W * (1 - timeFactor) + endQuaternion.W * timeFactor;
                currentQuaternion = new Quaternion(x, y, z, w);
                currentQuaternion.Normalize();
            }
            else
            {
                currentQuaternion = Quaternion.Slerp(startQuaternion, endQuaternion, timeFactor);

                double dotProduct = startQuaternion.X * endQuaternion.Y + startQuaternion.Y * endQuaternion.Y
                    + startQuaternion.Z * endQuaternion.Z + startQuaternion.W * endQuaternion.W;

                var theta = Math.Acos(dotProduct);
                if (theta < 0.0) theta = -theta;

                var startFactor = Math.Sin((1 - timeFactor) * theta) / Math.Sin(theta);
                var endFactor = Math.Sin(timeFactor * theta) / Math.Sin(theta);
                var x = startFactor * startQuaternion.X + endFactor * endQuaternion.X;
                var y = startFactor * startQuaternion.Y + endFactor * endQuaternion.Y;
                var z = startFactor * startQuaternion.Z + endFactor * endQuaternion.Z;
                var w = startFactor * startQuaternion.W + endFactor * endQuaternion.W;
                currentQuaternion = new Quaternion(x, y, z, w);
                currentQuaternion.Normalize();
            }
        }
開發者ID:Arkady92,項目名稱:PUSN,代碼行數:31,代碼來源:MainWindow.xaml.cs

示例6: UpdateModel

        /// <summary>
        /// Updates the quadcopter model based on roll pitch and yaw (in radians.)
        /// </summary>
        /// <param name="roll"></param>
        /// <param name="pitch"></param>
        /// <param name="yaw"></param>
        public void UpdateModel(float roll, float pitch, float yaw)
        {
            //Credit to http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm
            // for the math

            double heading = -1 * yaw;
            //double heading = 0.0;
            double attitude = -1 * roll;
            double bank = pitch;

            double c1 = Math.Cos(heading / 2.0);
            double s1 = Math.Sin(heading / 2.0);
            double c2 = Math.Cos(attitude / 2.0);
            double s2 = Math.Sin(attitude / 2.0);
            double c3 = Math.Cos(bank / 2.0);
            double s3 = Math.Sin(bank / 2.0);
            double c1c2 = c1 * c2;
            double s1s2 = s1 * s2;
            double w = c1c2 * c3 - s1s2 * s3;
            double x = c1c2 * s3 + s1s2 * c3;
            double y = s1 * c2 * c3 + c1 * s2 * s3;
            double z = c1 * s2 * c3 - s1 * c2 * s3;

            Quaternion q = new Quaternion(x, y, z, w);
            this.angleRotation.Angle = q.Angle;
            this.angleRotation.Axis = q.Axis;

            this.Label_Roll.Content = "Roll: " + (roll * 180.0 / Math.PI).ToString("#0.00");
            this.Label_Pitch.Content = "Pitch: " + (pitch * 180.0 / Math.PI).ToString("#0.00");
            this.Label_Yaw.Content = "Yaw: " + (yaw * 180.0 / Math.PI).ToString("#0.00");
        }
開發者ID:cboseak,項目名稱:GUI,代碼行數:37,代碼來源:QuadcopterModel.xaml.cs

示例7: QuaternionToEulerAnglesInRad

        //Source: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm
        public static Vector3D QuaternionToEulerAnglesInRad(Quaternion q)
        {
            q = FormatQuaternion(q);

            var sqw = Math.Pow(q.W,2);
            var sqx = Math.Pow(q.X,2);
            var sqy = Math.Pow(q.Y, 2);
            var sqz = Math.Pow(q.Z, 2);
	        var unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
	        var test = q.X*q.Y + q.Z*q.W;
	        if (test > 0.499*unit) 
            { // singularity at north pole
	            return new Vector3D
	                {
	                    Y = 2*Math.Atan2(q.X, q.W),
	                    Z = Math.PI/2,
	                    X = 0
	                };
	        }
	        if (test < -0.499*unit) 
            { // singularity at south pole
	            return new Vector3D
	                {
	                    Y = -2*Math.Atan2(q.X, q.W),
	                    Z = -Math.PI/2,
	                    X = 0
	                };
	        }
            return new Vector3D
                {
                    Y = -Math.Atan2(2*q.Y*q.W - 2*q.X*q.Z, sqx - sqy - sqz + sqw),
                    Z = Math.Asin(2 * test / unit),
                    X = -Math.Atan2(2 * q.X * q.W - 2 * q.Y * q.Z, -sqx + sqy - sqz + sqw)
            };
        }
開發者ID:NGenesis,項目名稱:VrPlayer.Trackers.OSVRTracker,代碼行數:36,代碼來源:QuaternionHelper.cs

示例8: BuildMatrix3DFromQuaternion

        public Matrix3D BuildMatrix3DFromQuaternion(Quaternion q)
        {
            double sqw = q.W * q.W;
            double sqx = q.X * q.X;
            double sqy = q.Y * q.Y;
            double sqz = q.Z * q.Z;

            // invs (inverse square length) is only required if quaternion is not already normalised
            double invs = 1 / (sqx + sqy + sqz + sqw);
            double m00 = (sqx - sqy - sqz + sqw) * invs; // since sqw + sqx + sqy + sqz =1/invs*invs
            double m11 = (-sqx + sqy - sqz + sqw) * invs;
            double m22 = (-sqx - sqy + sqz + sqw) * invs;

            double tmp1 = q.X * q.Y;
            double tmp2 = q.Z * q.W;
            double m10 = 2.0 * (tmp1 + tmp2) * invs;
            double m01 = 2.0 * (tmp1 - tmp2) * invs;

            tmp1 = q.X * q.Z;
            tmp2 = q.Y * q.W;
            double m20 = 2.0 * (tmp1 - tmp2) * invs;
            double m02 = 2.0 * (tmp1 + tmp2) * invs;
            tmp1 = q.Y * q.Z;
            tmp2 = q.X * q.W;
            double m21 = 2.0 * (tmp1 + tmp2) * invs;
            double m12 = 2.0 * (tmp1 - tmp2) * invs;

            return new Matrix3D(
                m00, m01, m02, 0,
                m10, m11, m12, 0,
                m20, m21, m22, 0,
                0, 0, 0, 1
                );
        }
開發者ID:Arkady92,項目名稱:PUSN,代碼行數:34,代碼來源:Maths.cs

示例9: SetupInterpolator

        public void SetupInterpolator(double StartAngleR, double StartAngleP, double StartAngleY, double EndAngleR,
            double EndAngleP, double EndAngleY, double StartPositionX,
         double StartPositionY,
         double StartPositionZ,
         double EndPositionX,
         double EndPositionY,
         double EndPositionZ,
            Quaternion startQuaternion,
            Quaternion endQuaternion
            )
        {
            this.StartAngleP = StartAngleP;
            this.StartAngleR = StartAngleR;
            this.StartAngleY = StartAngleY;

            this.EndAngleR = EndAngleR;
            this.EndAngleP = EndAngleP;
            this.EndAngleY = EndAngleY;

            this.StartPositionX = StartPositionX;
            this.StartPositionY = StartPositionY;
            this.StartPositionZ = StartPositionZ;

            this.EndPositionX = EndPositionX;
            this.EndPositionY = EndPositionY;
            this.EndPositionZ = EndPositionZ;

            this.startQuaternion = startQuaternion;
            this.endQuaternion = endQuaternion;
        }
開發者ID:Arkady92,項目名稱:PUSN,代碼行數:30,代碼來源:Interpolators.cs

示例10: ODESolverFunction

        public void ODESolverFunction(double[] y, double x, double[] dy, object obj)
        {
            var odeSolverData = obj as ODESolverData;
            var N = CalculateCubeTorque(new Quaternion(y[3], y[4], y[5], y[6]));
            var I = odeSolverData.tensor;
            var IInv = odeSolverData.invertTensor;
            var W = new Vector3D(y[0], y[1], y[2]);
            var IW = MatrixVectorMultiply(I, W);
            var IWW = Vector3D.CrossProduct(IW, W);
            var NIWW = N + IWW;
            var WT = MatrixVectorMultiply(IInv, NIWW);

            var Q = new Quaternion(y[3], y[4], y[5], y[6]);
            var WQ = new Quaternion(y[0], y[1], y[2], 0);
            var QT = Quaternion.Multiply(Q, WQ);
            QT = new Quaternion(QT.X / 2, QT.Y / 2, QT.Z / 2, QT.W / 2);

            dy[0] = WT.X;
            dy[1] = WT.Y;
            dy[2] = WT.Z;
            dy[3] = QT.X;
            dy[4] = QT.Y;
            dy[5] = QT.Z;
            dy[6] = QT.W;
        }
開發者ID:Arkady92,項目名稱:VR,代碼行數:25,代碼來源:MainWindow.xaml.cs

示例11: getQuaternion

        public static Quaternion getQuaternion(Vector3D v0, Vector3D v1)
        {
            Quaternion q = new Quaternion();
            // Copy, since cannot modify local
            v0.Normalize();
            v1.Normalize();

            double d = Vector3D.DotProduct(v0, v1);
            // If dot == 1, vectors are the same
            if (d >= 1.0f)
            {
                return Quaternion.Identity;
            }

            double s = Math.Sqrt((1 + d) * 2);
            double invs = 1 / s;

            Vector3D c = Vector3D.CrossProduct(v0, v1);

            q.X = c.X * invs;
            q.Y = c.Y * invs;
            q.Z = c.Z * invs;
            q.W = s * 0.5f;
            q.Normalize();

            return q;
        }
開發者ID:Randophilus,項目名稱:KinectToBVH,代碼行數:27,代碼來源:KinectDataConverter.cs

示例12: SpatialEntity

 public SpatialEntity(string name, string model, Vector3D position, Quaternion rotation)
 {
     Name = name;
     Model = model;
     Position = position;
     Rotation = rotation;
 }
開發者ID:timothypratley,項目名稱:locstream,代碼行數:7,代碼來源:SpatialEntity.cs

示例13: PdbViewState

 /// <summary>
 /// Initializes a new instance of the <see cref="PdbViewState"/> class.
 /// </summary>
 internal PdbViewState()
 {
     this.translation = new Vector3D();
     this.scale = 1;
     this.rotation = Quaternion.Identity;
     this.clip = 1;
     this.slab = 0;
 }
開發者ID:alkampfergit,項目名稱:BaktunShell,代碼行數:11,代碼來源:PdbViewState.cs

示例14: Convert

 public void Convert(double R, double P, double Y, ref Quaternion startQuaternion)
 {
     //convert from euler angles to radians
     Singleton<MathHelper>.Instance.EulerToRadian(ref R);
     Singleton<MathHelper>.Instance.EulerToRadian(ref P);
     Singleton<MathHelper>.Instance.EulerToRadian(ref Y);
     startQuaternion = ChangeAngles(P, Y, R);
 }
開發者ID:Arkady92,項目名稱:PUSN,代碼行數:8,代碼來源:Maths.cs

示例15: CalibrateManually

        public void CalibrateManually(Quaternion quaternion)
        {
            //CalibrationSystem.Transform = new RotateTransform3D(new QuaternionRotation3D(quaternion));

            // Fire event that calibration happened
            if (Calibrated != null)
                Calibrated(this, new CalibratedEventArgs() { CalibrationQuaternion = quaternion });
        }
開發者ID:philipdaubmeier,項目名稱:BodyOrientation,代碼行數:8,代碼來源:PhoneModel.xaml.cs


注:本文中的System.Windows.Media.Media3D.Quaternion類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。