当前位置: 首页>>代码示例>>C#>>正文


C# Quaternion.ToUnit方法代码示例

本文整理汇总了C#中System.Windows.Media.Media3D.Quaternion.ToUnit方法的典型用法代码示例。如果您正苦于以下问题:C# Quaternion.ToUnit方法的具体用法?C# Quaternion.ToUnit怎么用?C# Quaternion.ToUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.Media3D.Quaternion的用法示例。


在下文中一共展示了Quaternion.ToUnit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OrbitCamera

        private void OrbitCamera(Point currentPosition, Vector3D currentPosition3D)
        {
            #region Get Mouse Movement - Spherical

            // Figure out a rotation axis and angle
            Vector3D axis = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D);
            double angle = Vector3D.AngleBetween(_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;
            }

            // Now need to rotate the axis into the camera's coords
            // Get the camera's current view matrix.
            Matrix3D viewMatrix = MathUtils.GetViewMatrix(_camera);
            viewMatrix.Invert();

            // Transform the trackball rotation axis relative to the camera orientation.
            axis = viewMatrix.Transform(axis);

            Quaternion deltaRotation = new Quaternion(axis, -angle);
            Quaternion deltaRotationExternal = new Quaternion(axis, angle);

            #endregion

            // This can't be calculated each mose move.  It causes a wobble when the look direction isn't pointed directly at the origin
            //if (_orbitRadius == null)
            //{
            //    _orbitRadius = OnGetOrbitRadius();
            //}

            // Figure out the offset in world coords
            Vector3D lookLine = _camera.LookDirection;
            lookLine.Normalize();
            lookLine = lookLine * _camera.Position.ToVector().Length;		//_orbitRadius.Value;		// the camera is always pointed to the origin, so this shortcut works

            Point3D orbitPointWorld = _camera.Position + lookLine;

            // Get the opposite of the look line (the line from the orbit center to the camera's position)
            Vector3D lookLineOpposite = lookLine * -1d;

            // Rotate
            Vector3D[] vectors = new Vector3D[] { lookLineOpposite, _camera.UpDirection, _camera.LookDirection };

            deltaRotation.GetRotatedVector(vectors);

            // Apply the changes
            _camera.Position = orbitPointWorld + vectors[0];
            _camera.UpDirection = vectors[1];
            _camera.LookDirection = vectors[2];

            _quaternion = _quaternion.ToUnit() * deltaRotationExternal.ToUnit();
            _transform = new RotateTransform3D(new QuaternionRotation3D(_quaternion));

            OnRotationChanged();
        }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:59,代码来源:TrackballGrabber.cs

示例2: RotateBy

 /// <summary>
 /// This returns the current quaternion rotated by the delta
 /// </summary>
 /// <remarks>
 /// This method is really simple, but I'm tired of trial and error with multiplication order every time I need
 /// to rotate quaternions
 /// </remarks>
 public static Quaternion RotateBy(this Quaternion quaternion, Quaternion delta)
 {
     //return delta.ToUnit() * quaternion.ToUnit();		// this is the one that's backward (I think)
     return quaternion.ToUnit() * delta.ToUnit();
 }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:12,代码来源:Extenders.cs

示例3: GetJointBodyPair

        private void GetJointBodyPair(out Body body1, out Body body2, AddJointBodyType bodyType1, AddJointBodyType bodyType2, Point3D centerPoint, Quaternion rotation, double separationDistance, Color color)
        {
            #region Body 1

            double distanceToPermiter;
            Quaternion localRotation;
            GetJointBodyPairSprtOffset(out distanceToPermiter, out localRotation, bodyType1);

            Vector3D offset = new Vector3D(distanceToPermiter + (separationDistance / 2d), 0, 0);		// adding to the separation distance because I don't want centerpoint to centerpoint, I want edge to edge
            offset = rotation.GetRotatedVector(offset);

            Point3D shiftedCenter = centerPoint + offset;


            localRotation = rotation.ToUnit() * localRotation.ToUnit();
            RotateTransform3D finalRotation = new RotateTransform3D(new QuaternionRotation3D(localRotation));


            body1 = GetJointBodyPairSprtBody(GetJointBodyPairSprtHullType(bodyType1), shiftedCenter, finalRotation, color);

            #endregion

            #region Body 2

            GetJointBodyPairSprtOffset(out distanceToPermiter, out localRotation, bodyType2);
            offset = new Vector3D(distanceToPermiter + (separationDistance / 2d), 0, 0);
            offset = rotation.GetRotatedVector(offset);
            shiftedCenter = centerPoint - offset;		// subtracting instead of adding


            localRotation = new Quaternion(new Vector3D(0, 0, 1), 180d).ToUnit() * rotation.ToUnit() * localRotation.ToUnit();		// throwing in an extra 180 degrees of spin
            finalRotation = new RotateTransform3D(new QuaternionRotation3D(localRotation));


            body2 = GetJointBodyPairSprtBody(GetJointBodyPairSprtHullType(bodyType2), shiftedCenter, finalRotation, color);

            #endregion
        }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:38,代码来源:Newt2Tester.xaml.cs


注:本文中的System.Windows.Media.Media3D.Quaternion.ToUnit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。