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


C# Matrix.Decompose方法代碼示例

本文整理匯總了C#中System.Matrix.Decompose方法的典型用法代碼示例。如果您正苦於以下問題:C# Matrix.Decompose方法的具體用法?C# Matrix.Decompose怎麽用?C# Matrix.Decompose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Matrix的用法示例。


在下文中一共展示了Matrix.Decompose方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Keyframe

 public Keyframe(Bone bone, float time, Matrix output, InterpolationType interpolation)
 {
     Bone = bone;
     Time = time;
     Transform = output;
     Interpolation = interpolation;
     Transform.Decompose(out Scale, out Rotation, out Translation);
 }
開發者ID:RomanHodulak,項目名稱:DeferredLightingD3D11,代碼行數:8,代碼來源:Keyframe.cs

示例2: AnimationData

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="matrix">Matrix to decompose</param>
        public AnimationData(Matrix matrix)
        {
            Vector3 s;
            Vector3 t;
            Quaternion r;
            matrix.Decompose(out s, out r, out t);

            Rotation = r;
            Scaling = s;
            Translation = t;
        }
開發者ID:chantsunman,項目名稱:SharpDX_Demo,代碼行數:15,代碼來源:AnimationManager.cs

示例3: CreateBoneList

        public static remSkin CreateBoneList(ImportedMesh mesh, Matrix lMeshMatrixInv)
        {
            if (mesh.BoneList == null || mesh.BoneList.Count == 0)
            {
                return null;
            }

            Dictionary<int, float>[] boneDic = new Dictionary<int, float>[mesh.BoneList.Count];
            for (int i= 0; i < mesh.BoneList.Count; i++)
            {
                boneDic[i] = new Dictionary<int, float>();
            }
            int vertexOffset = 0;
            foreach (ImportedSubmesh submesh in mesh.SubmeshList)
            {
                List<ImportedVertex> vertices = submesh.VertexList;
                for (int i = 0; i < vertices.Count; i++)
                {
                    ImportedVertex vert = vertices[i];
                    for (int j = 0; j < vert.BoneIndices.Length; j++)
                    {
                        if (vert.BoneIndices[j] == 0xFF)
                            continue;

                        boneDic[vert.BoneIndices[j]].Add(vertexOffset + i, vert.Weights[j]);
                    }
                }
                vertexOffset += vertices.Count;
            }

            remSkin remBoneList = new remSkin(mesh.BoneList.Count);
            remBoneList.mesh = new remId(mesh.Name);
            Vector3 scale, translate;
            Quaternion rotate;
            lMeshMatrixInv.Decompose(out scale, out rotate, out translate);
            scale.X = Math.Abs(scale.X);
            scale.Y = Math.Abs(scale.Y);
            scale.Z = Math.Abs(scale.Z);
            Matrix combinedCorrection = Matrix.Scaling(-1f / scale.X, 1f / scale.Y, -1f / scale.Z) * lMeshMatrixInv;
            for (int i = 0; i < mesh.BoneList.Count; i++)
            {
                remBoneWeights boneWeights = new remBoneWeights();
                boneWeights.bone = new remId(mesh.BoneList[i].Name);
                Matrix lMatrix = Matrix.Invert(mesh.BoneList[i].Matrix);
                boneWeights.matrix = Matrix.Invert(lMatrix * combinedCorrection);
                boneWeights.vertexIndices = new int[boneDic[i].Count];
                boneDic[i].Keys.CopyTo(boneWeights.vertexIndices, 0);
                boneWeights.vertexWeights = new float[boneDic[i].Count];
                boneDic[i].Values.CopyTo(boneWeights.vertexWeights, 0);
                remBoneList.AddChild(boneWeights);
            }
            return remBoneList;
        }
開發者ID:hejob,項目名稱:SB3Utility,代碼行數:53,代碼來源:remReplace.cs

示例4: SceneGraph

        public SceneGraph(Matrix transformMatrix, IRenderable renderable = null)
        {
            //
            // Setup dirtyables...
            //
            D_Transform = new Dirtyable<Matrix>(() => { return Matrix.Transformation(Vector3.Zero, Quaternion.Identity, Scale, Vector3.Zero, Rotation, Translation); });
            D_WorldTransform = new Dirtyable<Matrix>(() =>
            {
                if (Parent == null)
                {
                    return D_Transform.Value;
                }
                else
                {
                    // TODO KAM: I'm not sure if this is the proper order in which to multiply matrices to find the WorldTransform
                    return D_Transform.Value * Parent.D_WorldTransform.Value;
                }
            });

            //
            // Setup transformation data...
            //
            Vector3 trans;
            Quaternion rot;
            Vector3 scale;
            transformMatrix.Decompose(out scale, out rot, out trans);
            Translation = trans;
            Rotation = rot;
            Scale = scale;

            //
            // Setup other data...
            //
            Parent = null;
            Children = new Dictionary<string, SceneGraph>();
            Renderable = renderable;
        }
開發者ID:sessamekesh,項目名稱:OutsideSimulator,代碼行數:37,代碼來源:SceneGraph.cs

示例5: RotateVector

 public static void RotateVector(ref Vector3 vec, ref Matrix m, ref Vector3 output)
 {
     Quaternion rotation;
     Vector3 scale;
     Vector3 translation;
     m.Decompose(out scale, out rotation, out translation);
     output = Vector3.Transform(vec, rotation);
 }
開發者ID:HaKDMoDz,項目名稱:InVision,代碼行數:8,代碼來源:MathUtil.cs

示例6: MatrixToEuler

 public static Vector3 MatrixToEuler(ref Matrix m)
 {
     Vector3 translate;
     Vector3 scale;
     Quaternion rotate;
     m.Decompose(out scale, out rotate, out translate);
     return quaternionToEuler(ref rotate);
 }
開發者ID:HaKDMoDz,項目名稱:InVision,代碼行數:8,代碼來源:MathUtil.cs

示例7: MatrixToSRT

 public static Vector3[] MatrixToSRT(Matrix m)
 {
     Quaternion q;
     Vector3[] srt = new Vector3[3];
     m.Decompose(out srt[0], out q, out srt[2]);
     srt[1] = QuaternionToEuler(q);
     return srt;
 }
開發者ID:anhlehoang410,項目名稱:SB3Utility,代碼行數:8,代碼來源:Fbx.cs

示例8: UpdateBoneTransformation

        /// <summary>
        /// Updades the graphics transformation from the given physics transformation
        /// </summary>
        /// <param name="physicsTransform"></param>
        internal void UpdateBoneTransformation(ref Matrix physicsTransform)
        {
            if (ColliderShape.LocalOffset != Vector3.Zero || ColliderShape.LocalRotation != Quaternion.Identity)
            {
                physicsTransform = Matrix.Multiply(ColliderShape.NegativeCenterMatrix, physicsTransform);
            }

            //we need to extract scale only..
            Vector3 scale, translation;
            Matrix rotation;
            BoneWorldMatrix.Decompose(out scale, out rotation, out translation);

            var scaling = Matrix.Scaling(scale);
            Matrix.Multiply(ref scaling, ref physicsTransform, out BoneWorldMatrixOut);

            //todo propagate to other bones? need to review this.

            if (DebugEntity == null) return;

            if (ColliderShape.LocalOffset != Vector3.Zero || ColliderShape.LocalRotation != Quaternion.Identity)
            {
                physicsTransform = Matrix.Multiply(ColliderShape.PositiveCenterMatrix, physicsTransform);
            }

            physicsTransform.Decompose(out scale, out rotation, out translation);
            DebugEntity.Transform.Position = translation;
            DebugEntity.Transform.Rotation = Quaternion.RotationMatrix(rotation);
        }
開發者ID:Kryptos-FR,項目名稱:xenko-reloaded,代碼行數:32,代碼來源:PhysicsComponent.cs

示例9: UpdateTransformationComponent

        /// <summary>
        /// Updades the graphics transformation from the given physics transformation
        /// </summary>
        /// <param name="physicsTransform"></param>
        internal void UpdateTransformationComponent(ref Matrix physicsTransform)
        {
            var entity = Entity;

            if (ColliderShape.LocalOffset != Vector3.Zero || ColliderShape.LocalRotation != Quaternion.Identity)
            {
                physicsTransform = Matrix.Multiply(ColliderShape.NegativeCenterMatrix, physicsTransform);
            }

            //we need to extract scale only..
            Vector3 scale, translation;
            Matrix rotation;
            entity.Transform.WorldMatrix.Decompose(out scale, out rotation, out translation);

            var scaling = Matrix.Scaling(scale);
            Matrix.Multiply(ref scaling, ref physicsTransform, out entity.Transform.WorldMatrix);

            if (entity.Transform.Parent == null)
            {
                entity.Transform.LocalMatrix = entity.Transform.WorldMatrix;
            }
            else
            {
                //We are not root so we need to derive the local matrix as well
                var inverseParent = entity.Transform.Parent.WorldMatrix;
                inverseParent.Invert();
                Matrix.Multiply(ref entity.Transform.WorldMatrix, ref inverseParent, out entity.Transform.LocalMatrix);
            }

            Quaternion rotQuat;
            entity.Transform.LocalMatrix.Decompose(out scale, out rotQuat, out translation);
            entity.Transform.Position = translation;
            entity.Transform.Rotation = rotQuat;

            if (DebugEntity == null) return;

            if (ColliderShape.LocalOffset != Vector3.Zero || ColliderShape.LocalRotation != Quaternion.Identity)
            {
                physicsTransform = Matrix.Multiply(ColliderShape.PositiveCenterMatrix, physicsTransform);
            }

            physicsTransform.Decompose(out scale, out rotation, out translation);
            DebugEntity.Transform.Position = translation;
            DebugEntity.Transform.Rotation = Quaternion.RotationMatrix(rotation);
        }
開發者ID:Kryptos-FR,項目名稱:xenko-reloaded,代碼行數:49,代碼來源:PhysicsComponent.cs

示例10: DeriveBonePhysicsTransformation

        /// <summary>
        /// Computes the physics transformation from the TransformComponent values
        /// </summary>
        /// <returns></returns>
        internal void DeriveBonePhysicsTransformation(out Matrix derivedTransformation)
        {
            Matrix rotation;
            Vector3 translation;
            Vector3 scale;
            BoneWorldMatrix.Decompose(out scale, out rotation, out translation);

            var translationMatrix = Matrix.Translation(translation);
            Matrix.Multiply(ref rotation, ref translationMatrix, out derivedTransformation);

            //handle dynamic scaling if allowed (aka not using assets)
            if (CanScaleShape)
            {
                if (ColliderShape.Scaling != scale)
                {
                    ColliderShape.Scaling = scale;
                }
            }

            //Handle collider shape offset
            if (ColliderShape.LocalOffset != Vector3.Zero || ColliderShape.LocalRotation != Quaternion.Identity)
            {
                derivedTransformation = Matrix.Multiply(ColliderShape.PositiveCenterMatrix, derivedTransformation);
            }

            if (DebugEntity == null) return;

            derivedTransformation.Decompose(out scale, out rotation, out translation);
            DebugEntity.Transform.Position = translation;
            DebugEntity.Transform.Rotation = Quaternion.RotationMatrix(rotation);
        }
開發者ID:Kryptos-FR,項目名稱:xenko-reloaded,代碼行數:35,代碼來源:PhysicsComponent.cs

示例11: SetFrameMatrix

        public void SetFrameMatrix(int id,
			double m11, double m12, double m13, double m14,
			double m21, double m22, double m23, double m24,
			double m31, double m32, double m33, double m34,
			double m41, double m42, double m43, double m44)
        {
            Transform frame = Frames[id];
            Matrix m = new Matrix();

            m.M11 = (float)m11;
            m.M12 = (float)m12;
            m.M13 = (float)m13;
            m.M14 = (float)m14;

            m.M21 = (float)m21;
            m.M22 = (float)m22;
            m.M23 = (float)m23;
            m.M24 = (float)m24;

            m.M31 = (float)m31;
            m.M32 = (float)m32;
            m.M33 = (float)m33;
            m.M34 = (float)m34;

            m.M41 = (float)m41;
            m.M42 = (float)m42;
            m.M43 = (float)m43;
            m.M44 = (float)m44;

            Vector3 s, t;
            Quaternion q;
            m.Decompose(out s, out q, out t);
            frame.m_LocalPosition = t;
            frame.m_LocalRotation = q;
            frame.m_LocalScale = s;
            Changed = true;
        }
開發者ID:hejob,項目名稱:SB3Utility,代碼行數:37,代碼來源:AnimatorEditor.cs

示例12: RigidBodyGetWorldTransform

        //This is valid for Dynamic rigidbodies (called once at initialization)
        //and Kinematic rigidbodies, called every simulation tick (if body not sleeping) to let the physics engine know where the kinematic body is.
        private void RigidBodyGetWorldTransform(out Matrix physicsTransform)
        {
            Data.PhysicsComponent.Simulation.SimulationProfiler.Mark();
            Data.PhysicsComponent.Simulation.UpdatedRigidbodies++;

            if (BoneIndex == -1)
            {
                DerivePhysicsTransformation(out physicsTransform);
            }
            else
            {
                DeriveBonePhysicsTransformation(out physicsTransform);
            }

            if (DebugEntity == null) return;

            Vector3 scale, pos;
            Quaternion rot;
            physicsTransform.Decompose(out scale, out rot, out pos);
            DebugEntity.Transform.Position = pos;
            DebugEntity.Transform.Rotation = rot;
        }
開發者ID:cg123,項目名稱:xenko,代碼行數:24,代碼來源:RigidbodyComponent.cs


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