本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}