public InstanceModel(Model model) { Model = model; PlaySpeed = 1; CurrentFrame = model.FrameStart; // orientation Position = Vector3.Zero; Scale = Vector3.One; Rotation = Matrix3.Identity; // objects Objects = new InstanceObject[model.Objects.Length]; for (int i = 0; i != Objects.Length; ++i) { var type = model.Objects[i].GetType(); if (type == typeof(ObjectMesh)) Objects[i] = new InstanceObjectMesh((ObjectMesh)model.Objects[i]); else if (type == typeof(ObjectArmature)) Objects[i] = new InstanceObjectArmature((ObjectArmature)model.Objects[i]); else Debug.ThrowError("InstanceModel", "Unsuported Object type: " + type); } for (int i = 0; i != Objects.Length; ++i) { Objects[i].bindObjects(model.Objects[i]); } }
public InstanceBone(Bone bone) { Bone = bone; Position = bone.Position; RotationMatrix = bone.RotationMatrix; Childeren = new List<InstanceBone>(); }
public Bone(BinaryReader reader) { Name = reader.ReadString(); parentName = reader.ReadString(); InheritScale = reader.ReadBoolean(); InheritRotation = reader.ReadBoolean(); Position = reader.ReadVector3(); RotationMatrix = reader.ReadMatrix3(); Rotation = Quaternion.FromMatrix3(RotationMatrix); }
public SoftwareBone(RMX_ArmatureBone bone) { Name = bone.Name; InheritScale = bone.InheritScale; InheritRotation = bone.InheritRotation; Position = new Vector3(bone.Position.Values[0], bone.Position.Values[1], bone.Position.Values[2]); Rotation = new Matrix3 ( new Vector3(bone.Rotation.Values[0], bone.Rotation.Values[1], bone.Rotation.Values[2]), new Vector3(bone.Rotation.Values[3], bone.Rotation.Values[4], bone.Rotation.Values[5]), new Vector3(bone.Rotation.Values[6], bone.Rotation.Values[7], bone.Rotation.Values[8]) ); }
public static Matrix4 FromMatrix3(Matrix3 matrix) { return new Matrix4 ( new Vector4(matrix.X.X, matrix.X.Y, matrix.X.Z, 0), new Vector4(matrix.Y.X, matrix.Y.Y, matrix.Y.Z, 0), new Vector4(matrix.Z.X, matrix.Z.Y, matrix.Z.Z, 0), new Vector4(0, 0, 0, 1) ); }
public static void FromMatrix3(ref Matrix3 matrix, out Matrix4 result) { result.X.X = matrix.X.X; result.X.Y = matrix.X.Y; result.X.Z = matrix.X.Z; result.X.W = 0; result.Y.X = matrix.Y.X; result.Y.Y = matrix.Y.Y; result.Y.Z = matrix.Y.Z; result.Y.W = 0; result.Z.X = matrix.Z.X; result.Z.Y = matrix.Z.Y; result.Z.Z = matrix.Z.Z; result.Z.W = 0; result.W.X = 0; result.W.Y = 0; result.W.Z = 0; result.W.W = 1; }
public Vector3 TransformTranspose(Matrix3 matrix) { return new Vector3 ( (X * matrix.X.X) + (Y * matrix.X.Y) + (Z * matrix.X.Z), (X * matrix.Y.X) + (Y * matrix.Y.Y) + (Z * matrix.Y.Z), (X * matrix.Z.X) + (Y * matrix.Z.Y) + (Z * matrix.Z.Z) ); }
public static void RotateAroundWorldAxisZ(ref Matrix3 matrix, float angle, out Matrix3 result) { angle = -angle; float tCos = (float)Math.Cos(angle), tSin = (float)Math.Sin(angle); result.X.X = (matrix.X.X*tCos) - (matrix.X.Y*tSin); result.X.Y = (matrix.X.X*tSin) + (matrix.X.Y*tCos); result.X.Z = matrix.X.Z; result.Y.X = (matrix.Y.X*tCos) - (matrix.Y.Y*tSin); result.Y.Y = (matrix.Y.X*tSin) + (matrix.Y.Y*tCos); result.Y.Z = matrix.Y.Z; result.Z.X = (matrix.Z.X*tCos) - (matrix.Z.Y*tSin); result.Z.Y = (matrix.Z.X*tSin) + (matrix.Z.Y*tCos); result.Z.Z = matrix.Z.Z; }
public static void Multiply(ref Matrix2x3 matrix1, ref Matrix3 matrix2, out Matrix2x3 result) { result.X.X = (matrix1.X.X * matrix2.X.X) + (matrix1.X.Y * matrix2.Y.X) + (matrix1.X.Z * matrix2.Z.X); result.X.Y = (matrix1.X.X * matrix2.X.Y) + (matrix1.X.Y * matrix2.Y.Y) + (matrix1.X.Z * matrix2.Z.Y); result.X.Z = (matrix1.X.X * matrix2.X.Z) + (matrix1.X.Y * matrix2.Y.Z) + (matrix1.X.Z * matrix2.Z.Z); result.Y.X = (matrix1.Y.X * matrix2.X.X) + (matrix1.Y.Y * matrix2.Y.X) + (matrix1.Y.Z * matrix2.Z.X); result.Y.Y = (matrix1.Y.X * matrix2.X.Y) + (matrix1.Y.Y * matrix2.Y.Y) + (matrix1.Y.Z * matrix2.Z.Y); result.Y.Z = (matrix1.Y.X * matrix2.X.Z) + (matrix1.Y.Y * matrix2.Y.Z) + (matrix1.Y.Z * matrix2.Z.Z); }
public static void TransformTranspose(ref Vector3 vector, ref Matrix3 matrix, out Vector3 result) { result.X = (vector.X * matrix.X.X) + (vector.Y * matrix.X.Y) + (vector.Z * matrix.X.Z); result.Y = (vector.X * matrix.Y.X) + (vector.Y * matrix.Y.Y) + (vector.Z * matrix.Y.Z); result.Z = (vector.X * matrix.Z.X) + (vector.Y * matrix.Z.Y) + (vector.Z * matrix.Z.Z); }
public static void FromMatrix3(ref Matrix3 matrix, out Quaternion result) { float w = (float)Math.Sqrt(1 + matrix.X.X + matrix.Y.Y + matrix.Z.Z) * .5f; float delta = 1 / (w * 4); result.X = (matrix.Z.Y - matrix.Y.Z) * delta; result.Y = (matrix.X.Z - matrix.Z.X) * delta; result.Z = (matrix.Y.X - matrix.X.Y) * delta; result.W = w; }
public Vector3 Transform(Matrix3 matrix) { return((matrix.X * X) + (matrix.Y * Y) + (matrix.Z * Z)); }
public static void Transform(ref Vector3 vector, ref Matrix3 matrix, out Vector3 result) { result = (matrix.X * vector.X) + (matrix.Y * vector.Y) + (matrix.Z * vector.Z); }
public Matrix3 MultiplyTransposed(Matrix3 matrix) { return new Matrix3 ( new Vector3 ( X.X * matrix.X.X + Y.X * matrix.Y.X + Z.X * matrix.Z.X, X.X * matrix.X.Y + Y.X * matrix.Y.Y + Z.X * matrix.Z.Y, X.X * matrix.X.Z + Y.X * matrix.Y.Z + Z.X * matrix.Z.Z ), new Vector3 ( X.Y * matrix.X.X + Y.Y * matrix.Y.X + Z.Y * matrix.Z.X, X.Y * matrix.X.Y + Y.Y * matrix.Y.Y + Z.Y * matrix.Z.Y, X.Y * matrix.X.Z + Y.Y * matrix.Y.Z + Z.Y * matrix.Z.Z ), new Vector3 ( X.Z * matrix.X.X + Y.Z * matrix.Y.X + Z.Z * matrix.Z.X, X.Z * matrix.X.Y + Y.Z * matrix.Y.Y + Z.Z * matrix.Z.Y, X.Z * matrix.X.Z + Y.Z * matrix.Y.Z + Z.Z * matrix.Z.Z ) ); }
public Matrix3 Multiply(Matrix3 matrix) { return new Matrix3 ( new Vector3((matrix.X.X*X.X) + (matrix.X.Y*Y.X) + (matrix.X.Z*Z.X), (matrix.X.X*X.Y) + (matrix.X.Y*Y.Y) + (matrix.X.Z*Z.Y), (matrix.X.X*X.Z) + (matrix.X.Y*Y.Z) + (matrix.X.Z*Z.Z)), new Vector3((matrix.Y.X*X.X) + (matrix.Y.Y*Y.X) + (matrix.Y.Z*Z.X), (matrix.Y.X*X.Y) + (matrix.Y.Y*Y.Y) + (matrix.Y.Z*Z.Y), (matrix.Y.X*X.Z) + (matrix.Y.Y*Y.Z) + (matrix.Y.Z*Z.Z)), new Vector3((matrix.Z.X*X.X) + (matrix.Z.Y*Y.X) + (matrix.Z.Z*Z.X), (matrix.Z.X*X.Y) + (matrix.Z.Y*Y.Y) + (matrix.Z.Z*Z.Y), (matrix.Z.X*X.Z) + (matrix.Z.Y*Y.Z) + (matrix.Z.Z*Z.Z)) ); }
public static void Transpose(Matrix3 matrix, out Matrix3 result) { result.X.X = matrix.X.X; result.X.Y = matrix.Y.X; result.X.Z = matrix.Z.X; result.Y.X = matrix.X.Y; result.Y.Y = matrix.Y.Y; result.Y.Z = matrix.Z.Y; result.Z.X = matrix.X.Z; result.Z.Y = matrix.Y.Z; result.Z.Z = matrix.Z.Z; }
public Matrix4 Multiply(Matrix3 matrix) { return new Matrix4 ( new Vector4((matrix.X.X*X.X) + (matrix.X.Y*Y.X) + (matrix.X.Z*Z.X), (matrix.X.X*X.Y) + (matrix.X.Y*Y.Y) + (matrix.X.Z*Z.Y), (matrix.X.X*X.Z) + (matrix.X.Y*Y.Z) + (matrix.X.Z*Z.Z), X.W), new Vector4((matrix.Y.X*X.X) + (matrix.Y.Y*Y.X) + (matrix.Y.Z*Z.X), (matrix.Y.X*X.Y) + (matrix.Y.Y*Y.Y) + (matrix.Y.Z*Z.Y), (matrix.Y.X*X.Z) + (matrix.Y.Y*Y.Z) + (matrix.Y.Z*Z.Z), Y.W), new Vector4((matrix.Z.X*X.X) + (matrix.Z.Y*Y.X) + (matrix.Z.Z*Z.X), (matrix.Z.X*X.Y) + (matrix.Z.Y*Y.Y) + (matrix.Z.Z*Z.Y), (matrix.Z.X*X.Z) + (matrix.Z.Y*Y.Z) + (matrix.Z.Z*Z.Z), Z.W), W ); }
public static void WriteMatrix(this BinaryWriter writer, Matrix3 value) { writer.WriteVector(value.X); writer.WriteVector(value.Y); writer.WriteVector(value.Z); }
public static Quaternion FromMatrix3(Matrix3 matrix) { float w = (float)Math.Sqrt(1 + matrix.X.X + matrix.Y.Y + matrix.Z.Z) * .5f; float delta = 1 / (w * 4); return new Quaternion ( (matrix.Z.Y - matrix.Y.Z) * delta, (matrix.X.Z - matrix.Z.X) * delta, (matrix.Y.X - matrix.X.Y) * delta, w ); }
public void ApplyBillBoard() { BillBoardMatrix = Matrix3.LookAt((Position - LookAtPosition), (UpPosition - Position)); BillBoardMatrixTranspose = BillBoardMatrix.Transpose(); }
public static void MultiplyTransposed(ref Matrix3 transpose, ref Matrix3 matrix, out Matrix3 result) { result.X.X = transpose.X.X * matrix.X.X + transpose.Y.X * matrix.Y.X + transpose.Z.X * matrix.Z.X; result.X.Y = transpose.X.X * matrix.X.Y + transpose.Y.X * matrix.Y.Y + transpose.Z.X * matrix.Z.Y; result.X.Z = transpose.X.X * matrix.X.Z + transpose.Y.X * matrix.Y.Z + transpose.Z.X * matrix.Z.Z; result.Y.X = transpose.X.Y * matrix.X.X + transpose.Y.Y * matrix.Y.X + transpose.Z.Y * matrix.Z.X; result.Y.Y = transpose.X.Y * matrix.X.Y + transpose.Y.Y * matrix.Y.Y + transpose.Z.Y * matrix.Z.Y; result.Y.Z = transpose.X.Y * matrix.X.Z + transpose.Y.Y * matrix.Y.Z + transpose.Z.Y * matrix.Z.Z; result.Z.X = transpose.X.Z * matrix.X.X + transpose.Y.Z * matrix.Y.X + transpose.Z.Z * matrix.Z.X; result.Z.Y = transpose.X.Z * matrix.X.Y + transpose.Y.Z * matrix.Y.Y + transpose.Z.Z * matrix.Z.Y; result.Z.Z = transpose.X.Z * matrix.X.Z + transpose.Y.Z * matrix.Y.Z + transpose.Z.Z * matrix.Z.Z; }
public void Set(Matrix3[] values) { throw new NotImplementedException(); }
public static void Transform(ref Vector3 vector, ref Matrix3 matrix, out Vector3 result) { result = (matrix.X*vector.X) + (matrix.Y*vector.Y) + (matrix.Z*vector.Z); }
public static void Transform(ref Line3 line, ref Matrix3 matrix, out Line3 result) { Vector3.Transform(ref line.Point1, ref matrix, out result.Point1); Vector3.Transform(ref line.Point2, ref matrix, out result.Point2); }
public Vector3 Transform(Matrix3 matrix) { return (matrix.X*X) + (matrix.Y*Y) + (matrix.Z*Z); }
public static void RotateAround(ref Matrix3 matrix, ref Vector3 axis, float angle, out Matrix3 result) { // rotate into world space var quaternion = Reign.Core.Quaternion.FromRotationAxis(axis, 0); Reign.Core.Quaternion.Conjugate(ref quaternion, out quaternion); Matrix3.FromQuaternion(ref quaternion, out result); Matrix3.Multiply(ref matrix, ref result, out result); // rotate back to matrix space Reign.Core.Quaternion.FromRotationAxis(ref axis, angle, out quaternion); var qMat = Matrix3.FromQuaternion(quaternion); Matrix3.Multiply(ref result, ref qMat, out result); }
public void Set(Matrix3 value) { valueObject.Matrix3 = value; Apply = setMatrix3; }
public static void RotateAroundAxisY(ref Matrix3 matrix, float angle, out Matrix3 result) { float tCos = (float)Math.Cos(angle), tSin = (float)Math.Sin(angle); result.X.X = (matrix.Z.X*tSin) + (matrix.X.X*tCos); result.X.Y = (matrix.Z.Y*tSin) + (matrix.X.Y*tCos); result.X.Z = (matrix.Z.Z*tSin) + (matrix.X.Z*tCos); result.Y = matrix.Y; result.Z.X = (matrix.Z.X*tCos) - (matrix.X.X*tSin); result.Z.Y = (matrix.Z.Y*tCos) - (matrix.X.Y*tSin); result.Z.Z = (matrix.Z.Z*tCos) - (matrix.X.Z*tSin); }
public void Set(Matrix3[] values, int offset, int count) { throw new NotImplementedException(); }
public static Matrix4 FromAffineTransform(Matrix3 transform, Vector3 scale, Vector3 position) { return new Matrix4 ( new Vector4(transform.X * scale.X, position.X), new Vector4(transform.Y * scale.Y, position.Y), new Vector4(transform.Z * scale.Z, position.Z), new Vector4(0, 0, 0, 1) ); }
public Line3 Transform(Matrix3 matrix) { return new Line3(Point1.Transform(matrix), Point2.Transform(matrix)); }
public static void FromAffineTransform(ref Matrix3 transform, ref Vector3 scale, ref Vector3 position, out Matrix4 result) { result.X.X = transform.X.X * scale.X; result.X.Y = transform.X.Y * scale.X; result.X.Z = transform.X.Z * scale.X; result.X.W = position.X; result.Y.X = transform.Y.X * scale.Y; result.Y.Y = transform.Y.Y * scale.Y; result.Y.Z = transform.Y.Z * scale.Y; result.Y.W = position.Y; result.Z.X = transform.Z.X * scale.Z; result.Z.Y = transform.Z.Y * scale.Z; result.Z.Z = transform.Z.Z * scale.Z; result.Z.W = position.Z; result.W.X = 0; result.W.Y = 0; result.W.Z = 0; result.W.W = 1; }