65 internal static TSMatrix InternalIdentity;
71 public static readonly
TSMatrix Zero;
78 Identity.M11 = FP.One;
79 Identity.M22 = FP.One;
80 Identity.M33 = FP.One;
97 public static TSMatrix CreateFromYawPitchRoll(FP yaw, FP pitch, FP roll)
101 TSQuaternion.CreateFromYawPitchRoll(yaw, pitch, roll, out quaternion);
102 CreateFromQuaternion(ref quaternion, out matrix);
106 public static TSMatrix CreateRotationX(FP radians)
109 FP num2 = FP.Cos(radians);
110 FP num = FP.Sin(radians);
112 matrix.
M12 = FP.Zero;
113 matrix.
M13 = FP.Zero;
114 matrix.
M21 = FP.Zero;
117 matrix.
M31 = FP.Zero;
123 public static void CreateRotationX(FP radians, out
TSMatrix result)
125 FP num2 = FP.Cos(radians);
126 FP num = FP.Sin(radians);
128 result.M12 = FP.Zero;
129 result.M13 = FP.Zero;
130 result.M21 = FP.Zero;
133 result.M31 = FP.Zero;
138 public static TSMatrix CreateRotationY(FP radians)
141 FP num2 = FP.Cos(radians);
142 FP num = FP.Sin(radians);
144 matrix.
M12 = FP.Zero;
146 matrix.
M21 = FP.Zero;
148 matrix.
M23 = FP.Zero;
150 matrix.
M32 = FP.Zero;
155 public static void CreateRotationY(FP radians, out
TSMatrix result)
157 FP num2 = FP.Cos(radians);
158 FP num = FP.Sin(radians);
160 result.M12 = FP.Zero;
162 result.M21 = FP.Zero;
164 result.M23 = FP.Zero;
166 result.M32 = FP.Zero;
170 public static TSMatrix CreateRotationZ(FP radians)
173 FP num2 = FP.Cos(radians);
174 FP num = FP.Sin(radians);
177 matrix.
M13 = FP.Zero;
180 matrix.
M23 = FP.Zero;
181 matrix.
M31 = FP.Zero;
182 matrix.
M32 = FP.Zero;
188 public static void CreateRotationZ(FP radians, out
TSMatrix result)
190 FP num2 = FP.Cos(radians);
191 FP num = FP.Sin(radians);
194 result.M13 = FP.Zero;
197 result.M23 = FP.Zero;
198 result.M31 = FP.Zero;
199 result.M32 = FP.Zero;
215 #region public JMatrix(FP m11, FP m12, FP m13, FP m21, FP m22, FP m23,FP m31, FP m32, FP m33) 216 public TSMatrix(FP m11, FP m12, FP m13, FP m21, FP m22, FP m23,FP m31, FP m32, FP m33)
234 #region public FP Determinant() 247 #region public static JMatrix Multiply(JMatrix matrix1, JMatrix matrix2) 263 FP num0 = ((matrix1.M11 * matrix2.M11) + (matrix1.M12 * matrix2.M21)) + (matrix1.M13 * matrix2.M31);
264 FP num1 = ((matrix1.M11 * matrix2.M12) + (matrix1.M12 * matrix2.M22)) + (matrix1.M13 * matrix2.M32);
265 FP num2 = ((matrix1.M11 * matrix2.M13) + (matrix1.M12 * matrix2.M23)) + (matrix1.M13 * matrix2.M33);
266 FP num3 = ((matrix1.M21 * matrix2.M11) + (matrix1.M22 * matrix2.M21)) + (matrix1.M23 * matrix2.M31);
267 FP num4 = ((matrix1.M21 * matrix2.M12) + (matrix1.M22 * matrix2.M22)) + (matrix1.M23 * matrix2.M32);
268 FP num5 = ((matrix1.M21 * matrix2.M13) + (matrix1.M22 * matrix2.M23)) + (matrix1.M23 * matrix2.M33);
269 FP num6 = ((matrix1.M31 * matrix2.M11) + (matrix1.M32 * matrix2.M21)) + (matrix1.M33 * matrix2.M31);
270 FP num7 = ((matrix1.M31 * matrix2.M12) + (matrix1.M32 * matrix2.M22)) + (matrix1.M33 * matrix2.M32);
271 FP num8 = ((matrix1.M31 * matrix2.M13) + (matrix1.M32 * matrix2.M23)) + (matrix1.M33 * matrix2.M33);
291 #region public static JMatrix Add(JMatrix matrix1, JMatrix matrix2) 295 TSMatrix.
Add(ref matrix1, ref matrix2, out result);
307 result.M11 = matrix1.M11 + matrix2.M11;
308 result.M12 = matrix1.M12 + matrix2.M12;
309 result.M13 = matrix1.M13 + matrix2.M13;
310 result.M21 = matrix1.M21 + matrix2.M21;
311 result.M22 = matrix1.M22 + matrix2.M22;
312 result.M23 = matrix1.M23 + matrix2.M23;
313 result.M31 = matrix1.M31 + matrix2.M31;
314 result.M32 = matrix1.M32 + matrix2.M32;
315 result.M33 = matrix1.M33 + matrix2.M33;
324 #region public static JMatrix Inverse(JMatrix matrix) 332 public FP Determinant()
334 return M11 * M22 * M33 + M12 * M23 * M31 + M13 * M21 * M32 -
335 M31 * M22 * M13 - M32 * M23 * M11 - M33 * M21 *
M12;
340 FP determinantInverse = 1 / matrix.Determinant();
341 FP m11 = (matrix.M22 * matrix.M33 - matrix.M23 * matrix.M32) * determinantInverse;
342 FP m12 = (matrix.M13 * matrix.M32 - matrix.M33 * matrix.M12) * determinantInverse;
343 FP m13 = (matrix.M12 * matrix.M23 - matrix.M22 * matrix.M13) * determinantInverse;
345 FP m21 = (matrix.M23 * matrix.M31 - matrix.M21 * matrix.M33) * determinantInverse;
346 FP m22 = (matrix.M11 * matrix.M33 - matrix.M13 * matrix.M31) * determinantInverse;
347 FP m23 = (matrix.M13 * matrix.M21 - matrix.M11 * matrix.M23) * determinantInverse;
349 FP m31 = (matrix.M21 * matrix.M32 - matrix.M22 * matrix.M31) * determinantInverse;
350 FP m32 = (matrix.M12 * matrix.M31 - matrix.M11 * matrix.M32) * determinantInverse;
351 FP m33 = (matrix.M11 * matrix.M22 - matrix.M12 * matrix.M21) * determinantInverse;
373 FP det = 1024 * matrix.M11 * matrix.M22 * matrix.M33 -
374 1024 * matrix.M11 * matrix.M23 * matrix.M32 -
375 1024 * matrix.M12 * matrix.M21 * matrix.M33 +
376 1024 * matrix.M12 * matrix.M23 * matrix.M31 +
377 1024 * matrix.M13 * matrix.M21 * matrix.M32 -
378 1024 * matrix.M13 * matrix.M22 * matrix.M31;
380 FP num11 =1024* matrix.M22 * matrix.M33 - 1024*matrix.M23 * matrix.M32;
381 FP num12 =1024* matrix.M13 * matrix.M32 -1024* matrix.M12 * matrix.M33;
382 FP num13 =1024* matrix.M12 * matrix.M23 -1024* matrix.M22 * matrix.M13;
384 FP num21 =1024* matrix.M23 * matrix.M31 -1024* matrix.M33 * matrix.M21;
385 FP num22 =1024* matrix.M11 * matrix.M33 -1024* matrix.M31 * matrix.M13;
386 FP num23 =1024* matrix.M13 * matrix.M21 -1024* matrix.M23 * matrix.M11;
388 FP num31 =1024* matrix.M21 * matrix.M32 - 1024* matrix.M31 * matrix.M22;
389 FP num32 =1024* matrix.M12 * matrix.M31 - 1024* matrix.M32 * matrix.M11;
390 FP num33 =1024* matrix.M11 * matrix.M22 - 1024*matrix.M21 * matrix.M12;
393 result.M11 = FP.PositiveInfinity;
394 result.M12 = FP.PositiveInfinity;
395 result.M13 = FP.PositiveInfinity;
396 result.M21 = FP.PositiveInfinity;
397 result.M22 = FP.PositiveInfinity;
398 result.M23 = FP.PositiveInfinity;
399 result.M31 = FP.PositiveInfinity;
400 result.M32 = FP.PositiveInfinity;
401 result.M33 = FP.PositiveInfinity;
403 result.M11 = num11 / det;
404 result.M12 = num12 / det;
405 result.M13 = num13 / det;
406 result.M21 = num21 / det;
407 result.M22 = num22 / det;
408 result.M23 = num23 / det;
409 result.M31 = num31 / det;
410 result.M32 = num32 / det;
411 result.M33 = num33 / det;
423 #region public static JMatrix Multiply(JMatrix matrix1, FP scaleFactor) 439 FP num = scaleFactor;
440 result.M11 = matrix1.M11 * num;
441 result.M12 = matrix1.M12 * num;
442 result.M13 = matrix1.M13 * num;
443 result.M21 = matrix1.M21 * num;
444 result.M22 = matrix1.M22 * num;
445 result.M23 = matrix1.M23 * num;
446 result.M31 = matrix1.M31 * num;
447 result.M32 = matrix1.M32 * num;
448 result.M33 = matrix1.M33 * num;
457 #region public static JMatrix CreateFromQuaternion(JQuaternion quaternion) 461 LookAt (out result, position, target);
469 result.M11 = xaxis.
x;
470 result.M21 = yaxis.
x;
471 result.M31 = zaxis.
x;
472 result.M12 = xaxis.
y;
473 result.M22 = yaxis.
y;
474 result.M32 = zaxis.
y;
475 result.M13 = xaxis.
z;
476 result.M23 = yaxis.
z;
477 result.M33 = zaxis.
z;
484 TSMatrix.CreateFromQuaternion(ref quaternion,out result);
495 FP num9 = quaternion.x * quaternion.x;
496 FP num8 = quaternion.y * quaternion.y;
497 FP num7 = quaternion.z * quaternion.z;
498 FP num6 = quaternion.x * quaternion.y;
499 FP num5 = quaternion.z * quaternion.w;
500 FP num4 = quaternion.z * quaternion.x;
501 FP num3 = quaternion.y * quaternion.w;
502 FP num2 = quaternion.y * quaternion.z;
503 FP num = quaternion.x * quaternion.w;
504 result.M11 = FP.One - (2 * (num8 + num7));
505 result.M12 = 2 * (num6 + num5);
506 result.M13 = 2 * (num4 - num3);
507 result.M21 = 2 * (num6 - num5);
508 result.M22 = FP.One - (2 * (num7 + num9));
509 result.M23 = 2 * (num2 + num);
510 result.M31 = 2 * (num4 + num3);
511 result.M32 = 2 * (num2 - num);
512 result.M33 = FP.One - (2 * (num8 + num9));
521 #region public static JMatrix Transpose(JMatrix matrix) 536 result.M11 = matrix.M11;
537 result.M12 = matrix.M21;
538 result.M13 = matrix.M31;
539 result.M21 = matrix.M12;
540 result.M22 = matrix.M22;
541 result.M23 = matrix.M32;
542 result.M31 = matrix.M13;
543 result.M32 = matrix.M23;
544 result.M33 = matrix.M33;
554 #region public static JMatrix operator *(JMatrix value1,JMatrix value2) 565 return this.M11 + this.M22 + this.
M33;
574 #region public static JMatrix operator +(JMatrix value1, JMatrix value2) 588 #region public static JMatrix operator -(JMatrix value1, JMatrix value2) 604 #region public static void CreateFromAxisAngle(ref JVector axis, FP angle, out JMatrix result) 610 FP num2 = FP.Sin(angle);
611 FP num = FP.Cos(angle);
618 result.M11 = num11 + (num * (FP.One - num11));
619 result.M12 = (num8 - (num * num8)) + (num2 * z);
620 result.M13 = (num7 - (num * num7)) - (num2 * y);
621 result.M21 = (num8 - (num * num8)) - (num2 * z);
622 result.M22 = num10 + (num * (FP.One - num10));
623 result.M23 = (num6 - (num * num6)) + (num2 * x);
624 result.M31 = (num7 - (num * num7)) + (num2 * y);
625 result.M32 = (num6 - (num * num6)) - (num2 * x);
626 result.M33 = num9 + (num * (FP.One - num9));
643 public override string ToString() {
644 return string.Format(
"{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}", M11.RawValue, M12.RawValue, M13.RawValue, M21.RawValue, M22.RawValue, M23.RawValue, M31.RawValue, M32.RawValue, M33.RawValue);
649 TSMatrix.LookAt (out
this, position, target);
FP y
The Y component of the vector.
static TSMatrix AngleAxis(FP angle, TSVector axis)
Creates a matrix which rotates around the given axis by the given angle.
static void CreateFromQuaternion(ref TSQuaternion quaternion, out TSMatrix result)
Creates a JMatrix representing an orientation from a quaternion.
static TSMatrix Multiply(TSMatrix matrix1, FP scaleFactor)
Multiply a matrix by a scalefactor.
static void Add(ref TSMatrix matrix1, ref TSMatrix matrix2, out TSMatrix result)
Matrices are added.
static TSMatrix operator-(TSMatrix value1, TSMatrix value2)
Subtracts two matrices.
static TSMatrix operator*(TSMatrix value1, TSMatrix value2)
Multiplies two matrices.
static readonly TSVector up
A vector with components (0,1,0);
static FP Atan2(FP y, FP x)
Returns the arc tan of coordinates x-y.
static TSMatrix CreateFromLookAt(TSVector position, TSVector target)
Creates a JMatrix representing an orientation from a quaternion.
static TSMatrix Add(TSMatrix matrix1, TSMatrix matrix2)
Matrices are added.
static void Transpose(ref TSMatrix matrix, out TSMatrix result)
Creates the transposed matrix.
static TSMatrix Inverse(TSMatrix matrix)
Calculates the inverse of a give matrix.
static void CreateFromAxisAngle(ref TSVector axis, FP angle, out TSMatrix result)
Creates a matrix which rotates around the given axis by the given angle.
Contains common math operations.
FP z
The Z component of the vector.
static void Multiply(ref TSMatrix matrix1, FP scaleFactor, out TSMatrix result)
Multiply a matrix by a scalefactor.
TSMatrix(FP m11, FP m12, FP m13, FP m21, FP m22, FP m23, FP m31, FP m32, FP m33)
Initializes a new instance of the matrix structure.
static void Multiply(ref TSMatrix matrix1, ref TSMatrix matrix2, out TSMatrix result)
Multiply two matrices. Notice: matrix multiplication is not commutative.
static readonly TSMatrix Identity
Identity matrix.
static TSVector Cross(TSVector vector1, TSVector vector2)
The cross product of two vectors.
static FP Sqrt(FP number)
Gets the square root.
static TSVector Normalize(TSVector value)
Normalizes the given vector.
static void Inverse(ref TSMatrix matrix, out TSMatrix result)
Calculates the inverse of a give matrix.
FP x
The X component of the vector.
static TSMatrix Multiply(TSMatrix matrix1, TSMatrix matrix2)
Gets the determinant of the matrix.
A Quaternion representing an orientation.
static TSMatrix Transpose(TSMatrix matrix)
Creates the transposed matrix.
static TSMatrix operator+(TSMatrix value1, TSMatrix value2)
Adds two matrices.