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


C# Matrix.Decompose方法代码示例

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


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

示例1: GetRotation

 public static float GetRotation(ref Matrix matrix)
 {
     Vector3 position3, scale3;
     Quaternion rotationQ;
     matrix.Decompose(out scale3, out rotationQ, out position3);
     Vector2 direction = Vector2.Transform(Vector2.UnitX, rotationQ);
     return (float)Math.Atan2(direction.Y, direction.X);
 }
开发者ID:raycrasher,项目名称:Fell-Sky,代码行数:8,代码来源:Utilities.cs

示例2: Transform

		/// <summary>
		/// Construct this transform from a matrix
		/// </summary>
		/// <param name="matrix"></param>
		/// <param name="performValidityCheck">When true, the matrix will be checked to make sure it will produce a valid transform</param>
		public Transform(ref Matrix matrix, bool performValidityCheck)
		{
			if (performValidityCheck)
			{
				//validate the matrix is not sheered or inverted on a single axis.
				Vector3 x = new Vector3(matrix.M11, matrix.M12, matrix.M13);
				Vector3 y = new Vector3(matrix.M21, matrix.M22, matrix.M23);
				Vector3 z = new Vector3(matrix.M31, matrix.M32, matrix.M33);

				float xl = x.Length();
				float yl = y.Length();
				float zl = z.Length();

				float maxl = Math.Max(xl, Math.Max(yl, zl));
				float minl = Math.Min(xl, Math.Min(yl, zl));

				if ((maxl - minl) > maxl / 10)
					throw new ArgumentException("The input matrix is not uniformly scaled");

				if (xl > 0.000001f) x /= xl;
				if (yl > 0.000001f) y /= yl;
				if (zl > 0.000001f) z /= zl;

				Vector3 zc = Vector3.Cross(x, y);
				Vector3 yc = Vector3.Cross(z, x);
				Vector3 xc = Vector3.Cross(y, zc);

				if (Vector3.Dot(x, xc) < 0.975f || Vector3.Dot(z, zc) * Vector3.Dot(y, yc) < 0.95f)
					throw new ArgumentException("The input matrix is skewed, sheered or non uniformly scaled");
			}

			Vector3 scale;
			matrix.Decompose(out scale, out Rotation, out Translation);

			//if one or two components are negative, then the Decompose messed up.
			if (scale.X * scale.Y * scale.Z < 0)
			{
				Matrix copy = matrix;
				copy.M11 = -copy.M11;
				copy.M12 = -copy.M12;
				copy.M13 = -copy.M13;
				copy.M21 = -copy.M21;
				copy.M22 = -copy.M22;
				copy.M23 = -copy.M23;
				copy.M31 = -copy.M31;
				copy.M32 = -copy.M32;
				copy.M33 = -copy.M33;
				copy.Decompose(out scale, out Rotation, out Translation);
				scale = -scale;
			}

			this.Scale = Math.Min(Math.Min(scale.X, scale.Y), scale.Z);

			if (Scale > 0.999f && Scale < 1.001f)
				Scale = 1;

			this.Rotation.Normalize();
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:63,代码来源:Transform.cs

示例3: DecomposeMatrix2D

 public static void DecomposeMatrix2D(ref Matrix matrix, out Vector2 position, out float rotation, out Vector2 scale)
 {
     Vector3 position3, scale3;
     Quaternion rotationQ;
     matrix.Decompose(out scale3, out rotationQ, out position3);
     Vector2 direction = Vector2.Transform(Vector2.UnitX, rotationQ);
     rotation = (float)Math.Atan2(direction.Y, direction.X);
     position = new Vector2(position3.X, position3.Y);
     scale = new Vector2(scale3.X, scale3.Y);
 }
开发者ID:raycrasher,项目名称:Fell-Sky,代码行数:10,代码来源:Utilities.cs

示例4: SetTransform

 public virtual void SetTransform(Matrix m)
 {
     Vector3 pos;
     Quaternion quat;
     Vector3 scale;
     m.Decompose(out scale,out quat,out pos);
     Vector3 rot = MathUtils.QuaternionToEuler(quat);
     transform.Set(new Vector2(pos.X,pos.Y), (float)rot.Z);
     SetScale(new Vector2(scale.X,scale.Y));
 }
开发者ID:solidhope,项目名称:TManQuest,代码行数:10,代码来源:AbstractCollider.cs

示例5: SetTransform

        public void SetTransform(ref Matrix transform)
        {
            transform.Decompose(out scale, out rotation, out translation);

            if (scale.X > 0.9999f && scale.X <= 1.0001f)
                scale.X = 1;
            if (scale.Y > 0.9999f && scale.Y <= 1.0001f)
                scale.Y = 1;
            if (scale.Z > 0.9999f && scale.Z <= 1.0001f)
                scale.Z = 1;
        }
开发者ID:zfedoran,项目名称:helium,代码行数:11,代码来源:keyframe.cs

示例6: MatrixToEulerAngleVector3

        // Converts a Rotation Matrix to a quaternion, then into a Vector3 containing
        // Euler angles (X: Pitch, Y: Yaw, Z: Roll)
        public Vector3 MatrixToEulerAngleVector3(Matrix Rotation)
        {
            Vector3 translation, scale;
            Quaternion rotation;

            Rotation.Decompose(out scale, out rotation, out translation);

            Vector3 eulerVec = QuaternionToEulerAngleVector3(rotation);

            return eulerVec;
        }
开发者ID:tuannsofta,项目名称:kinect4bag,代码行数:13,代码来源:RotationHelper.cs

示例7: FromMatrix

        /// <summary>
        /// 指定された行列から生成する
        /// </summary>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public static SQTTransformContent FromMatrix(Matrix matrix)
        {
            // 行列の分解
            Quaternion rotation;
            Vector3 translation;
            Vector3 scale;
            matrix.Decompose(out scale, out rotation, out translation);

            
            return new SQTTransformContent(scale, rotation, translation);
        }
开发者ID:himapo,项目名称:ccm,代码行数:16,代码来源:SQTTransformContent.cs

示例8: JointAnimationKeyFrame

        /// <summary>
        /// Creates a new keyframe from given time and transformation matrix.
        /// Since internally the joint transformation is stored in form of its
        /// scale, rotation and translation components the matrix has to be 
        /// decomposed within this constructor.
        /// </summary>
        /// <param name="time">Time of keyframe</param>
        /// <param name="transform">Transformation</param>
        public JointAnimationKeyFrame(float time, Matrix transform)
        {
            _time = time;

            if (!transform.Decompose(out _scale, out _rotation, out _translation))
            {
                throw new ApplicationException("Could not decompose transformation matrix");
            }

            _transform = transform;
        }
开发者ID:Bunkerbewohner,项目名称:ColladaXna,代码行数:19,代码来源:JointAnimationKeyFrame.cs

示例9: Transform

        public static BoundingSphere Transform(this BoundingSphere source, Matrix transformation)
        {
            Vector3 translation;
            Vector3 scaling;
            Quaternion rotation;
            transformation.Decompose(out scaling, out rotation, out translation);

            var transformedSphereRadius = source.Radius * new[] { scaling.X, scaling.Y, scaling.Z }.Max();
            var transformedSphereCenter = Vector3.Transform(source.Center, transformation);

            return new BoundingSphere(transformedSphereCenter, transformedSphereRadius);
        }
开发者ID:naighes,项目名称:AsteroidChallenge,代码行数:12,代码来源:BoundingSphereExtensions.cs

示例10: GetInfo

        public static string GetInfo(Matrix matrix)
        {
            Vector3 scales;
            Quaternion quaternion;
            Vector3 translation;
            matrix.Decompose(out scales, out quaternion, out translation);

            return string.Format("Scales:{0}; Angles:{1}; Trans:{2}", scales,
                //GetAngles(matrix),
                QuaternionToEuler2(quaternion),
                translation);
        }
开发者ID:DagonGD,项目名称:Game3,代码行数:12,代码来源:Workarea.cs

示例11: DrawShield

        public void DrawShield(Matrix world)
        {
            Vector3 scale, translation;
            Quaternion rotation;

            //should actually be up...
            Vector3 side = world.Right;
            Vector3 forward = world.Up;

            world.Decompose(out scale, out rotation, out translation);

            scale.Z *= .8f;
            scale *= 1.5f;
            // scale.X *= 3f;
            //translation -= world.Right;

            rotation = Quaternion.Concatenate(rotation, Quaternion.CreateFromAxisAngle(world.Right, MathHelper.ToRadians(90)));

            Matrix.CreateFromQuaternion(ref rotation, out world);
            world = Matrix.CreateScale(scale) * world;
            world *= Matrix.CreateTranslation(translation);

            // world = Matrix.CreateScale(scale*2) * Matrix.CreateFromQuaternion(rotation) * Matrix.CreateRotationZ((float)(Math.PI / 2)) * Matrix.CreateTranslation(translation);

            Matrix[] ModelTransforms = new Matrix[shieldModel.Bones.Count];
            shieldModel.CopyAbsoluteBoneTransformsTo(ModelTransforms);

            foreach (ModelMesh mesh in shieldModel.Meshes)
            {
                foreach (Effect currentEffect in mesh.Effects)
                {
                    currentEffect.CurrentTechnique = currentEffect.Techniques["Colored"];
                    currentEffect.Parameters["xWorld"].SetValue(ModelTransforms[mesh.ParentBone.Index] * world);
                    currentEffect.Parameters["xView"].SetValue(viewMatrix);
                    currentEffect.Parameters["xProjection"].SetValue(projectionMatrix);

                    Vector3 lightDirection = new Vector3(3, -1, 0);
                    lightDirection.Normalize();

                    currentEffect.Parameters["xLightDirection"].SetValue(lightDirection);
                    currentEffect.Parameters["xShieldP1"].SetValue(P1shieldDirection);
                    currentEffect.Parameters["xShieldP2"].SetValue(P2shieldDirection);
                    currentEffect.Parameters["xShipSide"].SetValue(side);
                    currentEffect.Parameters["xShipForward"].SetValue(forward);
                    //   currentEffect.Parameters["xTexture"].SetValue(texture);

                }
                mesh.Draw();
            }
        }
开发者ID:rmtmckenzie,项目名称:colony-coalition,代码行数:50,代码来源:DrawingComponents.cs

示例12: Transform

        public Transform(Matrix matrix)
        {
            matrix.Decompose(out scale, out rotation, out translation);

            if (scale.X > 0.9999f && scale.X <= 1.0001f)
                scale.X = 1;
            if (scale.Y > 0.9999f && scale.Y <= 1.0001f)
                scale.Y = 1;
            if (scale.Z > 0.9999f && scale.Z <= 1.0001f)
                scale.Z = 1;

            #if DEBUG
            this.Validate();
            #endif
        }
开发者ID:zfedoran,项目名称:bubblebound,代码行数:15,代码来源:Transform.cs

示例13: TransformBox

        public static BoundingBox TransformBox(BoundingBox aabb, Matrix transform)
        {
            Vector3 scale;
            Quaternion rotation;
            Vector3 translation;

            transform.Decompose(out scale, out rotation, out translation);

            if (rotation != Quaternion.Identity)
                throw new ArgumentException("Rotation of AABBs is not supported.");

            Vector3 center = 0.5f * (aabb.Max + aabb.Min) + translation;
            Vector3 extent = 0.5f * (aabb.Max - aabb.Min) * scale;

            //return new BoundingBox(center - extent, center + extent);
            return BoundingBox.CreateFromPoints(new Vector3[] { center - extent, center + extent });
        }
开发者ID:Tengato,项目名称:Mechadrone1,代码行数:17,代码来源:BoundingBoxNode.cs

示例14: FromMatrix

        /// <summary>
        /// 指定された行列から生成する
        /// </summary>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public static QuatTransform FromMatrix( Matrix matrix )
        {
            // 行列の分解
            Quaternion rotation;
            Vector3 translation;
            Vector3 scale;
            matrix.Decompose( out scale, out rotation, out translation );

            // 一意のスケールか?
            if ( !CloseEnough( scale.X, scale.Y ) || !CloseEnough( scale.X, scale.Z ) )
            {
                throw new InvalidOperationException(
                    "一意のスケール(X,Y,Zが同じスケール値)ではありません" );
            }

            if ( !CloseEnough( scale.X, 1.0f ) )
                throw new InvalidOperationException( "スケール値が1以外です" );

            return new QuatTransform( rotation, translation );
        }
开发者ID:himapo,项目名称:ccm,代码行数:25,代码来源:QuatTransform.cs

示例15: TransformBoundingSphere

        public static BoundingSphere TransformBoundingSphere(BoundingSphere originalBoundingSphere, Matrix transformationMatrix)
        {
            Vector3 trans;
            Vector3 scaling;
            Quaternion rot;
            transformationMatrix.Decompose(out scaling, out rot, out trans);

            float maxScale = scaling.X;
            if (maxScale < scaling.Y)
                maxScale = scaling.Y;
            if (maxScale < scaling.Z)
                maxScale = scaling.Z;

            float transformedSphereRadius = originalBoundingSphere.Radius * maxScale;
            Vector3 transformedSphereCenter = Vector3.Transform(originalBoundingSphere.Center, transformationMatrix);

            BoundingSphere transformedBoundingSphere = new BoundingSphere(transformedSphereCenter, transformedSphereRadius);

            return transformedBoundingSphere;
        }
开发者ID:patrykos91,项目名称:Laikos,代码行数:20,代码来源:XNAUtils.cs


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