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


C# Quaternion.ToAxisAngle方法代码示例

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


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

示例1: Cube3D

        public Cube3D()
            : base(600, 400, GraphicsMode.Default, "1-2:Camera")
        {
            VSync = VSyncMode.On;

            Keyboard.KeyUp += (sender, e) =>
            {
                //Escapeキーで終了
                if (e.Key == Key.Escape)
                {
                    this.Exit();
                }
            };

            RenderFrame += (sender, e) =>
            {
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                GL.MatrixMode(MatrixMode.Modelview);
                Vector3 eyepoint = new Vector3(0, 0, -3);
                Matrix4 modelview = Matrix4.LookAt(eyepoint, Vector3.UnitZ, Vector3.UnitY);
                GL.LoadMatrix(ref modelview);

                Quaternion q = new Quaternion(Form1.AHRS.Quaternion[1],
                    Form1.AHRS.Quaternion[2],
                    Form1.AHRS.Quaternion[3],
                    Form1.AHRS.Quaternion[0]);
                q.ToAxisAngle(out vec3, out angle);
                GL.Rotate((float)(angle * 180 / Math.PI), vec3);

                //GL.Rotate(deg, Vector3d.UnitY);
                //deg += 1;

                DrawCube();

                SwapBuffers();
            };
        }
开发者ID:shintamainjp,项目名称:NinjaScan_GUI,代码行数:38,代码来源:Cube3D.cs

示例2: QuaternionToEuler

		static public Vector3 QuaternionToEuler(Quaternion rotation)
		{
			Vector4 v = rotation.ToAxisAngle();
			return new Vector3(v.X, v.Y, v.Z);
		}
开发者ID:KurtLoeffler,项目名称:EnvyEngine,代码行数:5,代码来源:Transform.cs

示例3: Drag

        //Mouse drag, calculate rotation
        private Matrix4 Drag(Point newPosition)
        {
            //Only allows rotation around x and y, z is not allowed
            //Map the point to the sphere
            MapToSphere(newPosition, ref _endVector);
            //Calculate x-axis rotate angle
            Vector3 xStartVector = new Vector3(0, _startVector.Y, _startVector.Z);
            Vector3 xEndVector = new Vector3(0, _endVector.Y, _endVector.Z);

            Vector3 xPerp;
            Vector3.Cross(ref xStartVector, ref xEndVector, out xPerp);
            Quaternion xRotation = new Quaternion();
            //Compute the length of the perpendicular vector
            if (xPerp.Length > Epsilon)
            //if its non-zero
            {
                //We're ok, so return the perpendicular vector as the transform after all
                xRotation.X = xPerp.X;
                xRotation.Y = xPerp.Y;
                xRotation.Z = xPerp.Z;
                //In the quaternion values, w is cosine (theta / 2), where theta is the rotation angle
                xRotation.W = Vector3.Dot(xStartVector, xEndVector);
            }
            //if it is zero
            else
            {
                //The begin and end vectors coincide, so return an identity transform
                xRotation.X = xRotation.Y = xRotation.Z = 0.0f;
                xRotation.W = 1.0f;
            }
            float xAngle;
            Vector3 xAxis;
            xRotation.ToAxisAngle(out xAxis, out xAngle);
            float xDegree = MathHelper.RadiansToDegrees(xAngle);
            xDegree = xDegree *0.01f;
            xAngle = MathHelper.DegreesToRadians(xDegree);
            var xMatrix = Matrix4.CreateFromAxisAngle(xAxis, xAngle); //Matrix4.Rotate(rotation);

            //float xAngle = (float)Math.Acos(Vector3.Dot(xStartVector, xEndVector));
            //float xdegree = MathHelper.RadiansToDegrees(xAngle);
            //xdegree = xdegree / 10;
            //xAngle = MathHelper.DegreesToRadians(xdegree);
            //Matrix4 xMatrix = Matrix4.CreateFromAxisAngle(Vector3.UnitX, xAngle);
            //Calculate y_axis rotate angle
            Vector3 yStartVector = new Vector3(_startVector.X, 0, _startVector.Z);
            Vector3 yEndVector = new Vector3(_endVector.X, 0, _endVector.Z);

            Vector3 yPerp;
            Vector3.Cross(ref yStartVector, ref yEndVector, out yPerp);
            Quaternion yRotation = new Quaternion();
            //Compute the length of the perpendicular vector
            if (yPerp.Length > Epsilon)
            //if its non-zero
            {
                //We're ok, so return the perpendicular vector as the transform after all
                yRotation.X = yPerp.X;
                yRotation.Y = yPerp.Y;
                yRotation.Z = yPerp.Z;
                //In the quaternion values, w is cosine (theta / 2), where theta is the rotation angle
                yRotation.W = Vector3.Dot(yStartVector, yEndVector);
            }
            //if it is zero
            else
            {
                //The begin and end vectors coincide, so return an identity transform
                yRotation.X = yRotation.Y = yRotation.Z = 0.0f;
                yRotation.W = 1.0f;
            }
            float yAngle;
            Vector3 yAxis;
            yRotation.ToAxisAngle(out yAxis, out yAngle);
            float yDegree = MathHelper.RadiansToDegrees(yAngle);
            yDegree = yDegree *0.01f ;
            yAngle = MathHelper.DegreesToRadians(yDegree);
            var yMatrix = Matrix4.CreateFromAxisAngle(yAxis, yAngle); //Matrix4.Rotate(rotation);

            //float yAngle = (float)Math.Acos(Vector3.Dot(yStartVector, yEndVector));
            //float ydegree = MathHelper.RadiansToDegrees(yAngle);
            //ydegree = ydegree / 10;
            //yAngle = MathHelper.DegreesToRadians(ydegree);
            //Matrix4 yMatrix = Matrix4.CreateFromAxisAngle(Vector3.UnitY, yAngle);
            //z_axis is not allowed for rotation
            ////////////////////////////////
            return yMatrix;
            //return rotateMatrix;
            //return Matrix4.Mult(yMatrix, xMatrix);

            ////Return the quaternion equivalent to the rotation

            //Vector3 perp;

            ////Compute the vector perpendicular to the begin and end vectors
            //Vector3.Cross(ref _startVector, ref _endVector, out perp);
            //Quaternion rotation = new Quaternion();
            ////Compute the length of the perpendicular vector
            //if (perp.Length > Epsilon)
            ////if its non-zero
            //{
            //    //We're ok, so return the perpendicular vector as the transform after all
//.........这里部分代码省略.........
开发者ID:vicancy,项目名称:VisualWorld,代码行数:101,代码来源:Arcball.cs

示例4: Rotate

 /// <summary>
 /// Build a rotation matrix from a quaternion
 /// </summary>
 /// <param name="q">the quaternion</param>
 /// <returns>A rotation matrix</returns>
 public static Matrix4 Rotate(Quaternion q)
 {
     float3 axis;
     float angle;
     q.ToAxisAngle(out axis, out angle);
     return Rotate(axis, angle);
 }
开发者ID:Wiladams,项目名称:NewTOAPIA,代码行数:12,代码来源:Matrix4.cs

示例5: Small_Changes_Single_Axis

        public void Small_Changes_Single_Axis()
        {
            var q1 = Quaternion.FromAxisAngle(new AxisAngle { Axis = Vector3.UnitX, Angle = Angle.FromDegrees(0.1) });

            var q2 = new Quaternion();

            for (var i = 0; i < 2700; i++)
            {
                q2 *= q1;
            }

            var a = q2.ToAxisAngle();

            Assert.Equal(270, a.Angle.RawDegrees.SigFig(3));
            Assert.Equal(Vector3.UnitX, a.Axis.SigFig(3));
        }
开发者ID:rho24,项目名称:Rho.Robot,代码行数:16,代码来源:Quaternion_Tests.cs


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