9 #ifndef _TurtleBrains_Matrix_h_
10 #define _TurtleBrains_Matrix_h_
12 #include "tb_vector.h"
13 #include "../core/tb_error.h"
14 #include "../core/tb_defines.h"
31 Vector3*
Vector3TransformCoord(Vector3* result,
const Vector3* inputVector,
const Matrix4* inputMatrix);
70 #if defined(tb_visual_cpp)
72 #pragma warning(disable: 4201)
74 float m_f11;
float m_f21;
float m_f31;
75 float m_f12;
float m_f22;
float m_f32;
76 float m_f13;
float m_f23;
float m_f33;
81 float m_f11;
float m_f21;
float m_f31;
82 float m_f12;
float m_f22;
float m_f32;
83 float m_f13;
float m_f23;
float m_f33;
91 inline explicit Matrix3(
float f11 = 0.0f,
float f21 = 0.0f,
float f31 = 0.0f,
92 float f12 = 0.0f,
float f22 = 0.0f,
float f32 = 0.0f,
93 float f13 = 0.0f,
float f23 = 0.0f,
float f33 = 0.0f)
99 mComponents[0] = f11; mComponents[1] = f21; mComponents[2] = f31;
100 mComponents[3] = f12; mComponents[4] = f22; mComponents[5] = f32;
101 mComponents[6] = f13; mComponents[7] = f23; mComponents[8] = f33;
109 inline explicit Matrix3(
const float *
const componentArray)
111 memcpy(mComponents, componentArray,
sizeof(
float) * 9);
130 memcpy(mComponents, other.mComponents,
sizeof(
float) * 9);
140 memcpy(mComponents, other.mComponents,
sizeof(
float) * 9);
157 for (
size_t index(0); index < 9; ++index)
159 if (
false ==
IsEqual(mComponents[index], other[index]))
175 for (
size_t index(0); index < 9; ++index)
177 if (
false ==
IsEqual(mComponents[index], other[index]))
190 inline const float&
operator[](
const size_t& index)
const {
return mComponents[index]; }
197 inline float&
operator[](
const size_t& index) {
return mComponents[index]; }
203 inline const float&
operator()(
const size_t& column,
const size_t& row)
const {
return mComponents[column + (row * 3)]; }
210 inline float&
operator()(
const size_t& column,
const size_t& row) {
return mComponents[column + (row * 3)]; }
216 inline const float&
operator()(
int column,
int row)
const {
return mComponents[column + (row * 3)]; }
223 inline float&
operator()(
int column,
int row) {
return mComponents[column + (row * 3)]; }
232 inline operator float*(void) {
return mComponents; }
237 inline operator const float*(void)
const {
return mComponents; }
263 inline void SetBasis(
const size_t& basisIndex,
const Vector3 &basis) { *((
Vector3*)&mComponents[basisIndex * 3]) = basis; }
273 inline void SetBasis(
const size_t& basisIndex,
float basisX,
float basisY,
float basisZ)
275 mComponents[(basisIndex * 3) + 0] = basisX;
276 mComponents[(basisIndex * 3) + 1] = basisY;
277 mComponents[(basisIndex * 3) + 2] = basisZ;
281 #if defined(tb_with_math_operators)
282 inline Matrix3 operator*(
float scalar)
const
285 (*
this)(0, 0) * scalar, (*
this)(1, 0) * scalar, (*
this)(2, 0) * scalar,
286 (*
this)(0, 1) * scalar, (*
this)(1, 1) * scalar, (*
this)(2, 1) * scalar,
287 (*
this)(0, 2) * scalar, (*
this)(1, 2) * scalar, (*
this)(2, 2) * scalar);
314 0.0f, 0.0f, 0.0f, 0.0f,
315 0.0f, 0.0f, 0.0f, 0.0f,
316 0.0f, 0.0f, 0.0f, 0.0f,
317 0.0f, 0.0f, 0.0f, 0.0f);
327 1.0f, 0.0f, 0.0f, 0.0f,
328 0.0f, 1.0f, 0.0f, 0.0f,
329 0.0f, 0.0f, 1.0f, 0.0f,
330 0.0f, 0.0f, 0.0f, 1.0f);
335 float mComponents[16];
337 #if defined(tb_visual_cpp)
338 #pragma warning(push)
339 #pragma warning(disable: 4201)
341 float m_f11;
float m_f21;
float m_f31;
float m_f41;
342 float m_f12;
float m_f22;
float m_f32;
float m_f42;
343 float m_f13;
float m_f23;
float m_f33;
float m_f43;
344 float m_f14;
float m_f24;
float m_f34;
float m_f44;
349 float m_f11;
float m_f21;
float m_f31;
float m_f41;
350 float m_f12;
float m_f22;
float m_f32;
float m_f42;
351 float m_f13;
float m_f23;
float m_f33;
float m_f43;
352 float m_f14;
float m_f24;
float m_f34;
float m_f44;
360 inline explicit Matrix4(
float f11 = 0.0f,
float f21 = 0.0f,
float f31 = 0.0f,
float f41 = 0.0f,
361 float f12 = 0.0f,
float f22 = 0.0f,
float f32 = 0.0f,
float f42 = 0.0f,
362 float f13 = 0.0f,
float f23 = 0.0f,
float f33 = 0.0f,
float f43 = 0.0f,
363 float f14 = 0.0f,
float f24 = 0.0f,
float f34 = 0.0f,
float f44 = 0.0f)
370 mComponents[0] = f11; mComponents[1] = f21; mComponents[2] = f31; mComponents[3] = f41;
371 mComponents[4] = f12; mComponents[5] = f22; mComponents[6] = f32; mComponents[7] = f42;
372 mComponents[8] = f13; mComponents[9] = f23; mComponents[10]= f33; mComponents[11]= f43;
373 mComponents[12]= f14; mComponents[13]= f24; mComponents[14]= f34; mComponents[15]= f44;
381 inline explicit Matrix4(
const float *
const componentArray)
383 memcpy(mComponents, componentArray,
sizeof(
float) << 4);
402 memcpy(mComponents, other.mComponents,
sizeof(
float) << 4);
412 memcpy(mComponents, other.mComponents,
sizeof(
float) << 4);
429 for (
size_t index(0); index < 16; ++index)
431 if (
false ==
IsEqual(mComponents[index], other[index]))
447 for (
size_t index(0); index < 16; ++index)
449 if (
false ==
IsEqual(mComponents[index], other[index]))
462 inline const float&
operator[](
const size_t& index)
const {
return mComponents[index]; }
469 inline float&
operator[](
const size_t& index) {
return mComponents[index]; }
475 inline const float&
operator()(
const size_t& column,
const size_t& row)
const {
return mComponents[column + (row << 2)]; }
482 inline float&
operator()(
const size_t& column,
const size_t& row) {
return mComponents[column + (row << 2)]; }
488 inline const float&
operator()(
int column,
int row)
const {
return mComponents[column + (row << 2)]; }
495 inline float&
operator()(
int column,
int row) {
return mComponents[column + (row << 2)]; }
505 inline operator float*(void) {
return mComponents; }
510 inline operator const float*(void)
const {
return mComponents; }
537 inline void SetBasis(
const size_t& basisIndex,
const Vector3 &basis) { *((
Vector3*)&mComponents[basisIndex<<2]) = basis; }
547 inline void SetBasis(
const size_t& basisIndex,
float basisX,
float basisY,
float basisZ)
549 mComponents[(basisIndex<<2) + 0] = basisX;
550 mComponents[(basisIndex<<2) + 1] = basisY;
551 mComponents[(basisIndex<<2) + 2] = basisZ;
554 #if defined(tb_with_math_operators)
562 return Vector3((*
this)(0, 3), (*
this)(1, 3), (*
this)(2, 3));
571 (*this)(0, 3) = position.x;
572 (*
this)(1, 3) = position.y;
573 (*
this)(2, 3) = position.z;
599 temp(0, 0) =
self(0, 0); temp(0, 1) =
self(1, 0); temp(0, 2) =
self(2, 0); temp(0, 3) =
self(3, 0);
600 temp(1, 0) =
self(0, 1); temp(1, 1) =
self(1, 1); temp(1, 2) =
self(2, 1); temp(1, 3) =
self(3, 1);
601 temp(2, 0) =
self(0, 2); temp(2, 1) =
self(1, 2); temp(2, 2) =
self(2, 2); temp(2, 3) =
self(3, 2);
602 temp(3, 0) =
self(0, 3); temp(3, 1) =
self(1, 3); temp(3, 2) =
self(2, 3); temp(3, 3) =
self(3, 3);
669 tb_error(
"Not yet implemented / tested.");
672 Vector3 realUp((
nullptr == up) ?
Vector3(0.0f, 1.0f, 0.0f) : *up);
689 result->m_f14 = translation->x;
690 result->m_f24 = translation->y;
691 result->m_f34 = translation->z;
707 result->m_f14 = translationX;
708 result->m_f24 = translationY;
709 result->m_f34 = translationZ;
722 memset(result->mComponents, 0,
sizeof(
float) << 4);
723 result->m_f11 = scale->x;
724 result->m_f22 = scale->y;
725 result->m_f33 = scale->z;
726 result->m_f44 = 1.0f;
741 memset(result->mComponents, 0,
sizeof(
float) << 4);
742 result->m_f11 = scaleX;
743 result->m_f22 = scaleY;
744 result->m_f33 = scaleZ;
745 result->m_f44 = 1.0f;
758 const float rotationInRadians(tbMath::Convert::DegreesToRadians(rotationInDegrees));
761 result->m_f22 = cos(rotationInRadians);
762 result->m_f32 = -sin(rotationInRadians);
763 result->m_f23 = sin(rotationInRadians);
764 result->m_f33 = cos(rotationInRadians);
777 const float rotationInRadians(tbMath::Convert::DegreesToRadians(rotationInDegrees));
780 result->m_f11 = cos(rotationInRadians);
781 result->m_f31 = sin(rotationInRadians);
782 result->m_f13 = -sin(rotationInRadians);
783 result->m_f33 = cos(rotationInRadians);
796 const float rotationInRadians(tbMath::Convert::DegreesToRadians(rotationInDegrees));
799 result->m_f11 = cos(rotationInRadians);
800 result->m_f21 = -sin(rotationInRadians);
801 result->m_f12 = sin(rotationInRadians);
802 result->m_f22 = cos(rotationInRadians);
816 const float rotationInRadians(tbMath::Convert::DegreesToRadians(rotationInDegrees));
819 const float s = sinf(rotationInRadians);
820 const float c = cosf(rotationInRadians);
821 const float t = 1.0f - c;
823 float x = rotationAxis->x;
824 float y = rotationAxis->y;
825 float z = rotationAxis->z;
827 const float tx = t * rotationAxis->x;
828 const float ty = t * rotationAxis->y;
829 const float tz = t * rotationAxis->z;
830 const float sx = s * rotationAxis->x;
831 const float sy = s * rotationAxis->y;
832 const float sz = s * rotationAxis->z;
834 result->mComponents[0] = tx * x + c;
835 result->mComponents[1] = tx * y + sz;
836 result->mComponents[2] = tx * z - sy;
837 result->mComponents[3] = 0.0f;
839 result->mComponents[4] = tx * y - sz;
840 result->mComponents[5] = ty * y + c;
841 result->mComponents[6] = ty * z + sx;
842 result->mComponents[7] = 0.0f;
844 result->mComponents[8] = tx * z + sy;
845 result->mComponents[9] = ty * z - sx;
846 result->mComponents[10] = tz * z + c;
847 result->mComponents[11] = 0.0f;
849 result->mComponents[12] = 0.0f;
850 result->mComponents[13] = 0.0f;
851 result->mComponents[14] = 0.0f;
852 result->mComponents[15] = 1.0f;
867 const float nearPlane,
const float farPlane)
869 memset(result->mComponents, 0,
sizeof(
float) << 4);
871 const float f = 1.0f / tanf(fieldOfView / 2.0f);
872 result->m_f11 = f / aspectRatio;
874 result->m_f33 = (farPlane) / (nearPlane - farPlane);
875 result->m_f43 = -1.0f;
876 result->m_f34 = (nearPlane * farPlane) / (nearPlane - farPlane);
891 const float nearPlane,
const float farPlane)
893 memset(result->mComponents, 0,
sizeof(
float) << 4);
895 const float f = 1.0f / tanf(fieldOfView / 2.0f);
896 result->m_f11 = f / aspectRatio;
898 result->m_f33 = (farPlane) / (farPlane - nearPlane);
899 result->m_f43 = 1.0f;
900 result->m_f34 = -(nearPlane * farPlane) / (farPlane - nearPlane);
921 const float nearPlane,
const float farPlane)
923 memset(result->mComponents, 0,
sizeof(
float) << 4);
925 result->m_f11 = 2.0f / width;
926 result->m_f22 = 2.0f / height;
927 result->m_f33 = 1.0f / (nearPlane - farPlane);
928 result->m_f34 = nearPlane / (nearPlane - farPlane);
929 result->m_f44 = 1.0f;
950 const float nearPlane,
const float farPlane)
952 memset(result->mComponents, 0,
sizeof(
float) << 4);
960 result->m_f11 = 2.0f / width;
961 result->m_f22 = 2.0f / height;
962 result->m_f33 = 1.0f / (farPlane - nearPlane);
963 result->m_f34 = nearPlane / (nearPlane - farPlane);
964 result->m_f44 = 1.0f;
978 float *r = result->mComponents;
979 const float *m1 = leftSide->mComponents;
980 const float *m2 = rightSide->mComponents;
982 r[0] = m1[0] + m2[0]; r[1] = m1[1] + m2[1]; r[2] = m1[2] + m2[2]; r[3] = m1[3] + m2[3];
983 r[4] = m1[4] + m2[4]; r[5] = m1[5] + m2[5]; r[6] = m1[6] + m2[6]; r[7] = m1[7] + m2[7];
984 r[8] = m1[8] + m2[8]; r[9] = m1[9] + m2[9]; r[10] = m1[10] + m2[10]; r[11] = m1[11] + m2[11];
985 r[12] = m1[12] + m2[12]; r[13] = m1[13] + m2[13]; r[14] = m1[14] + m2[14]; r[15] = m1[15] + m2[15];
998 float *r = result->mComponents;
999 const float *m1 = leftSide->mComponents;
1000 const float *m2 = rightSide->mComponents;
1002 r[0] = m1[0] - m2[0]; r[1] = m1[1] - m2[1]; r[2] = m1[2] - m2[2]; r[3] = m1[3] - m2[3];
1003 r[4] = m1[4] - m2[4]; r[5] = m1[5] - m2[5]; r[6] = m1[6] - m2[6]; r[7] = m1[7] - m2[7];
1004 r[8] = m1[8] - m2[8]; r[9] = m1[9] - m2[9]; r[10] = m1[10] - m2[10]; r[11] = m1[11] - m2[11];
1005 r[12] = m1[12] - m2[12]; r[13] = m1[13] - m2[13]; r[14] = m1[14] - m2[14]; r[15] = m1[15] - m2[15];
1017 tb_error_if(result == input,
"tbExternalError: Invalid parameter; expected result to be different than input");
1018 result->m_f11 = input->m_f11; result->m_f12 = input->m_f21; result->m_f13 = input->m_f31; result->m_f14 = input->m_f41;
1019 result->m_f21 = input->m_f12; result->m_f22 = input->m_f22; result->m_f23 = input->m_f32; result->m_f24 = input->m_f42;
1020 result->m_f31 = input->m_f13; result->m_f32 = input->m_f23; result->m_f33 = input->m_f33; result->m_f34 = input->m_f43;
1021 result->m_f41 = input->m_f14; result->m_f42 = input->m_f24; result->m_f43 = input->m_f34; result->m_f44 = input->m_f44;
1037 tb_error_if(result == leftSide || result == rightSide,
"tbExternalError: Invalid parameter; expected result to be different than leftSide and rightSide");
1038 result->m_f11 = (leftSide->m_f11 * rightSide->m_f11) + (leftSide->m_f21 * rightSide->m_f12) + (leftSide->m_f31 * rightSide->m_f13) + (leftSide->m_f41 * rightSide->m_f14);
1039 result->m_f21 = (leftSide->m_f11 * rightSide->m_f21) + (leftSide->m_f21 * rightSide->m_f22) + (leftSide->m_f31 * rightSide->m_f23) + (leftSide->m_f41 * rightSide->m_f24);
1040 result->m_f31 = (leftSide->m_f11 * rightSide->m_f31) + (leftSide->m_f21 * rightSide->m_f32) + (leftSide->m_f31 * rightSide->m_f33) + (leftSide->m_f41 * rightSide->m_f34);
1041 result->m_f41 = (leftSide->m_f11 * rightSide->m_f41) + (leftSide->m_f21 * rightSide->m_f42) + (leftSide->m_f31 * rightSide->m_f43) + (leftSide->m_f41 * rightSide->m_f44);
1042 result->m_f12 = (leftSide->m_f12 * rightSide->m_f11) + (leftSide->m_f22 * rightSide->m_f12) + (leftSide->m_f32 * rightSide->m_f13) + (leftSide->m_f42 * rightSide->m_f14);
1043 result->m_f22 = (leftSide->m_f12 * rightSide->m_f21) + (leftSide->m_f22 * rightSide->m_f22) + (leftSide->m_f32 * rightSide->m_f23) + (leftSide->m_f42 * rightSide->m_f24);
1044 result->m_f32 = (leftSide->m_f12 * rightSide->m_f31) + (leftSide->m_f22 * rightSide->m_f32) + (leftSide->m_f32 * rightSide->m_f33) + (leftSide->m_f42 * rightSide->m_f34);
1045 result->m_f42 = (leftSide->m_f12 * rightSide->m_f41) + (leftSide->m_f22 * rightSide->m_f42) + (leftSide->m_f32 * rightSide->m_f43) + (leftSide->m_f42 * rightSide->m_f44);
1046 result->m_f13 = (leftSide->m_f13 * rightSide->m_f11) + (leftSide->m_f23 * rightSide->m_f12) + (leftSide->m_f33 * rightSide->m_f13) + (leftSide->m_f43 * rightSide->m_f14);
1047 result->m_f23 = (leftSide->m_f13 * rightSide->m_f21) + (leftSide->m_f23 * rightSide->m_f22) + (leftSide->m_f33 * rightSide->m_f23) + (leftSide->m_f43 * rightSide->m_f24);
1048 result->m_f33 = (leftSide->m_f13 * rightSide->m_f31) + (leftSide->m_f23 * rightSide->m_f32) + (leftSide->m_f33 * rightSide->m_f33) + (leftSide->m_f43 * rightSide->m_f34);
1049 result->m_f43 = (leftSide->m_f13 * rightSide->m_f41) + (leftSide->m_f23 * rightSide->m_f42) + (leftSide->m_f33 * rightSide->m_f43) + (leftSide->m_f43 * rightSide->m_f44);
1050 result->m_f14 = (leftSide->m_f14 * rightSide->m_f11) + (leftSide->m_f24 * rightSide->m_f12) + (leftSide->m_f34 * rightSide->m_f13) + (leftSide->m_f44 * rightSide->m_f14);
1051 result->m_f24 = (leftSide->m_f14 * rightSide->m_f21) + (leftSide->m_f24 * rightSide->m_f22) + (leftSide->m_f34 * rightSide->m_f23) + (leftSide->m_f44 * rightSide->m_f24);
1052 result->m_f34 = (leftSide->m_f14 * rightSide->m_f31) + (leftSide->m_f24 * rightSide->m_f32) + (leftSide->m_f34 * rightSide->m_f33) + (leftSide->m_f44 * rightSide->m_f34);
1053 result->m_f44 = (leftSide->m_f14 * rightSide->m_f41) + (leftSide->m_f24 * rightSide->m_f42) + (leftSide->m_f34 * rightSide->m_f43) + (leftSide->m_f44 * rightSide->m_f44);
1068 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector.");
1069 result->x = (inputVector->x * inputMatrix->m_f11) + (inputVector->y * inputMatrix->m_f12) + (inputVector->z * inputMatrix->m_f13);
1070 result->y = (inputVector->x * inputMatrix->m_f21) + (inputVector->y * inputMatrix->m_f22) + (inputVector->z * inputMatrix->m_f23);
1071 result->z = (inputVector->x * inputMatrix->m_f31) + (inputVector->y * inputMatrix->m_f32) + (inputVector->z * inputMatrix->m_f33);
1086 tb_error_if(result == inputVector ,
"tbExternalError: Invalid parameter; expected result to be different than inputVector.");
1087 result->x = (inputVector->x * inputMatrix->m_f11) + (inputVector->y * inputMatrix->m_f12) + (inputVector->z * inputMatrix->m_f13) + (inputVector->w * inputMatrix->m_f14);
1088 result->y = (inputVector->x * inputMatrix->m_f21) + (inputVector->y * inputMatrix->m_f22) + (inputVector->z * inputMatrix->m_f23) + (inputVector->w * inputMatrix->m_f24);
1089 result->z = (inputVector->x * inputMatrix->m_f31) + (inputVector->y * inputMatrix->m_f32) + (inputVector->z * inputMatrix->m_f33) + (inputVector->w * inputMatrix->m_f34);
1090 result->w = (inputVector->x * inputMatrix->m_f41) + (inputVector->y * inputMatrix->m_f42) + (inputVector->z * inputMatrix->m_f43) + (inputVector->w * inputMatrix->m_f44);
1106 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector");
1107 result->x = (inputVector->x * inputMatrix->m_f11) + (inputVector->y * inputMatrix->m_f12) + (inputVector->z * inputMatrix->m_f13) + inputMatrix->m_f14;
1108 result->y = (inputVector->x * inputMatrix->m_f21) + (inputVector->y * inputMatrix->m_f22) + (inputVector->z * inputMatrix->m_f23) + inputMatrix->m_f24;
1109 result->z = (inputVector->x * inputMatrix->m_f31) + (inputVector->y * inputMatrix->m_f32) + (inputVector->z * inputMatrix->m_f33) + inputMatrix->m_f34;
1125 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector");
1126 result->x = (inputVector->x * inputMatrix->m_f11) + (inputVector->y * inputMatrix->m_f12) + (inputVector->z * inputMatrix->m_f13);
1127 result->y = (inputVector->x * inputMatrix->m_f21) + (inputVector->y * inputMatrix->m_f22) + (inputVector->z * inputMatrix->m_f23);
1128 result->z = (inputVector->x * inputMatrix->m_f31) + (inputVector->y * inputMatrix->m_f32) + (inputVector->z * inputMatrix->m_f33);
1136 inline float Matrix3x3Determinant(
const float f11,
const float f12,
const float f13,
const float f21,
const float f22,
const float f23,
const float f31,
const float f32,
const float f33)
1138 return f11 * (f22 * f33 - f32 * f23) - f12 * (f21 * f33 - f31 * f23) + f13 * (f21 * f32 - f31 * f22);
1147 return input->m_f11 *
Matrix3x3Determinant(input->m_f22, input->m_f32, input->m_f42, input->m_f23, input->m_f33, input->m_f43, input->m_f24, input->m_f34, input->m_f44) -
1148 input->m_f21 *
Matrix3x3Determinant(input->m_f12, input->m_f32, input->m_f42, input->m_f13, input->m_f33, input->m_f43, input->m_f14, input->m_f34, input->m_f44) +
1149 input->m_f31 *
Matrix3x3Determinant(input->m_f12, input->m_f22, input->m_f42, input->m_f13, input->m_f23, input->m_f43, input->m_f14, input->m_f24, input->m_f44) -
1150 input->m_f41 *
Matrix3x3Determinant(input->m_f12, input->m_f22, input->m_f32, input->m_f13, input->m_f23, input->m_f33, input->m_f14, input->m_f24, input->m_f34);
1166 tb_error_if(result == input,
"tbExternalError: Invalid parameter, expected result to be different than input.");
1168 if (
true ==
IsZero(determinant))
1174 const float inverseDeterminant = 1.0f / determinant;
1176 result->m_f11 = (
Matrix3x3Determinant (input->m_f22, input->m_f32, input->m_f42, input->m_f23, input->m_f33, input->m_f43, input->m_f24, input->m_f34, input->m_f44)) * inverseDeterminant;
1177 result->m_f21 = (-
Matrix3x3Determinant(input->m_f21, input->m_f31, input->m_f41, input->m_f23, input->m_f33, input->m_f43, input->m_f24, input->m_f34, input->m_f44)) * inverseDeterminant;
1178 result->m_f31 = (
Matrix3x3Determinant (input->m_f21, input->m_f31, input->m_f41, input->m_f22, input->m_f32, input->m_f42, input->m_f24, input->m_f34, input->m_f44)) * inverseDeterminant;
1179 result->m_f41 = (-
Matrix3x3Determinant(input->m_f21, input->m_f31, input->m_f41, input->m_f22, input->m_f32, input->m_f42, input->m_f23, input->m_f33, input->m_f43)) * inverseDeterminant;
1180 result->m_f12 = (-
Matrix3x3Determinant(input->m_f12, input->m_f32, input->m_f42, input->m_f13, input->m_f33, input->m_f43, input->m_f14, input->m_f34, input->m_f44)) * inverseDeterminant;
1181 result->m_f22 = (
Matrix3x3Determinant (input->m_f11, input->m_f31, input->m_f41, input->m_f13, input->m_f33, input->m_f43, input->m_f14, input->m_f34, input->m_f44)) * inverseDeterminant;
1182 result->m_f32 = (-
Matrix3x3Determinant(input->m_f11, input->m_f31, input->m_f41, input->m_f12, input->m_f32, input->m_f42, input->m_f14, input->m_f34, input->m_f44)) * inverseDeterminant;
1183 result->m_f42 = (
Matrix3x3Determinant (input->m_f11, input->m_f31, input->m_f41, input->m_f12, input->m_f32, input->m_f42, input->m_f13, input->m_f33, input->m_f43)) * inverseDeterminant;
1184 result->m_f13 = (
Matrix3x3Determinant (input->m_f12, input->m_f22, input->m_f42, input->m_f13, input->m_f23, input->m_f43, input->m_f14, input->m_f24, input->m_f44)) * inverseDeterminant;
1185 result->m_f23 = (-
Matrix3x3Determinant(input->m_f11, input->m_f21, input->m_f41, input->m_f13, input->m_f23, input->m_f43, input->m_f14, input->m_f24, input->m_f44)) * inverseDeterminant;
1186 result->m_f33 = (
Matrix3x3Determinant (input->m_f11, input->m_f21, input->m_f41, input->m_f12, input->m_f22, input->m_f42, input->m_f14, input->m_f24, input->m_f44)) * inverseDeterminant;
1187 result->m_f43 = (-
Matrix3x3Determinant(input->m_f11, input->m_f21, input->m_f41, input->m_f12, input->m_f22, input->m_f42, input->m_f13, input->m_f23, input->m_f43)) * inverseDeterminant;
1188 result->m_f14 = (-
Matrix3x3Determinant(input->m_f12, input->m_f22, input->m_f32, input->m_f13, input->m_f23, input->m_f33, input->m_f14, input->m_f24, input->m_f34)) * inverseDeterminant;
1189 result->m_f24 = (
Matrix3x3Determinant (input->m_f11, input->m_f21, input->m_f31, input->m_f13, input->m_f23, input->m_f33, input->m_f14, input->m_f24, input->m_f34)) * inverseDeterminant;
1190 result->m_f34 = (-
Matrix3x3Determinant(input->m_f11, input->m_f21, input->m_f31, input->m_f12, input->m_f22, input->m_f32, input->m_f14, input->m_f24, input->m_f34)) * inverseDeterminant;
1191 result->m_f44 = (
Matrix3x3Determinant (input->m_f11, input->m_f21, input->m_f31, input->m_f12, input->m_f22, input->m_f32, input->m_f13, input->m_f24, input->m_f33)) * inverseDeterminant;
1199 namespace Unstable {
1200 inline Matrix4* FastInverse(Matrix4* result,
const Matrix4* input)
1202 (*result)(0, 0) = (*input)(0, 0);
1203 (*result)(1, 1) = (*input)(1, 1);
1204 (*result)(2, 2) = (*input)(2, 2);
1205 (*result)(3, 3) = (*input)(3, 3);
1207 (*result)(1, 0) = (*input)(0, 1);
1208 (*result)(2, 0) = (*input)(0, 2);
1209 (*result)(0, 1) = (*input)(1, 0);
1210 (*result)(2, 1) = (*input)(1, 2);
1211 (*result)(0, 2) = (*input)(2, 0);
1212 (*result)(1, 2) = (*input)(2, 1);
1214 (*result)(3, 0) = -(*input)(3, 0);
1215 (*result)(3, 1) = -(*input)(3, 1);
1216 (*result)(3, 2) = -(*input)(3, 2);
1218 (*result)(0, 3) = 0.0f;
1219 (*result)(1, 3) = 0.0f;
1220 (*result)(2, 3) = 0.0f;
1228 inline Matrix4 Translate(
const Matrix4& originalMatrix,
const Vector3& translation)
1230 Matrix4 outputMatrix(kSkipInitialization);
1231 Matrix4 translationMatrix(kSkipInitialization);
1234 const Matrix4 translationTransposed(translationMatrix.GetTransposed());
1235 MatrixMultiply(&outputMatrix, &originalMatrix, &translationTransposed);
1237 return outputMatrix;
1240 inline Matrix4 Translate(
const Matrix4& originalMatrix,
float x,
float y,
float z)
1248 inline Matrix4 TranslateLocal(
const Matrix4& originalMatrix,
const Vector3& translation)
1250 Matrix4 outputMatrix(kSkipInitialization);
1251 Matrix4 translationMatrix(kSkipInitialization);
1254 MatrixMultiply(&outputMatrix, &originalMatrix, &translationMatrix);
1256 return outputMatrix;
1259 inline Matrix4 TranslateLocal(
const Matrix4& originalMatrix,
float x,
float y,
float z)
1268 inline Matrix4 Rotate(
const Matrix4& originalMatrix,
const Vector3& aroundAxis,
const float rotationInDegrees)
1270 Matrix4 outputMatrix(kSkipInitialization);
1271 Matrix4 rotationMatrix(kSkipInitialization);
1279 return outputMatrix;
1282 inline Matrix4 Rotate(
const size_t& axisIndex,
const Matrix4& originalMatrix,
const float rotationInDegrees)
1284 return Rotate(originalMatrix, *originalMatrix.GetBasis(axisIndex), rotationInDegrees);
1287 inline Matrix4 RotateWorldSpace(
const size_t& axisIndex,
const Matrix4& originalMatrix,
const float rotationInDegrees)
1289 Matrix4 outputMatrix(kSkipInitialization);
1290 Matrix4 rotationMatrix(kSkipInitialization);
1294 const Matrix4 rotationTransposed(rotationMatrix.GetTransposed());
1295 MatrixMultiply(&outputMatrix, &originalMatrix, &rotationTransposed);
1297 return outputMatrix;
1300 inline Matrix4 Scale(
const Matrix4& originalMatrix,
const Vector3& scale)
1302 Matrix4 outputMatrix(kSkipInitialization);
1303 Matrix4 scalingMatrix(kSkipInitialization);
1308 return outputMatrix;
1311 inline Matrix4 Scale(
const Matrix4& originalMatrix,
float x,
float y,
float z)
1313 return Scale(originalMatrix, Vector3(x, y, z));
Matrix4 * MatrixCreateOrthoLH(Matrix4 *result, const float width, const float height, const float nearPlane, const float farPlane)
Definition: tb_matrix.h:949
static Matrix4 Identity(void)
Definition: tb_matrix.h:324
Matrix4 * MatrixCreateOrthoRH(Matrix4 *result, const float width, const float height, const float nearPlane, const float farPlane)
Definition: tb_matrix.h:920
static Matrix3 Identity(void)
Definition: tb_matrix.h:58
Vector3 * Vector3MatrixMultiply(Vector3 *result, const Vector3 *inputVector, const Matrix3 *inputMatrix)
Definition: tb_matrix.h:1066
const float & operator()(int column, int row) const
Definition: tb_matrix.h:216
Contains objects and functions for dealing with Vector and Matrix math.
float MatrixDeterminant(const Matrix4 *input)
Definition: tb_matrix.h:1145
static Matrix4 Zero(void)
Definition: tb_matrix.h:311
#define tb_error(message,...)
Definition: tb_error.h:23
const float & operator()(const size_t &column, const size_t &row) const
Definition: tb_matrix.h:475
bool operator!=(const Matrix3 &other) const
Definition: tb_matrix.h:173
Definition: tb_vector.h:303
Matrix3(float f11=0.0f, float f21=0.0f, float f31=0.0f, float f12=0.0f, float f22=0.0f, float f32=0.0f, float f13=0.0f, float f23=0.0f, float f33=0.0f)
Definition: tb_matrix.h:91
Definition: tb_matrix.h:40
Matrix4 * MatrixCreateRotationY(Matrix4 *result, const float rotationInDegrees)
Definition: tb_matrix.h:775
float & operator()(int column, int row)
Definition: tb_matrix.h:495
Matrix4 ComputeInverse(void) const
Definition: tb_matrix.h:611
float Matrix3x3Determinant(const float f11, const float f12, const float f13, const float f21, const float f22, const float f23, const float f31, const float f32, const float f33)
Definition: tb_matrix.h:1136
Vector3 * Vector3TransformCoord(Vector3 *result, const Vector3 *inputVector, const Matrix4 *inputMatrix)
Definition: tb_matrix.h:1104
float & operator[](const size_t &index)
Definition: tb_matrix.h:197
Matrix4 * MatrixMultiply(Matrix4 *result, const Matrix4 *leftSide, const Matrix4 *rightSide)
Definition: tb_matrix.h:1035
Vector3 TransformNormal(const Vector3 &inputVector) const
Definition: tb_matrix.h:633
bool operator!=(const Matrix4 &other) const
Definition: tb_matrix.h:445
Here is some information about the primary namespace.
Definition: tb_application_dialog.h:21
Matrix4 * MatrixCreateTranslation(Matrix4 *result, const Vector3 *translation)
Definition: tb_matrix.h:686
Matrix4 * MatrixCreateRotationA(Matrix4 *result, const Vector3 *rotationAxis, const float rotationInDegrees)
Definition: tb_matrix.h:814
#define tb_unused(parameter)
Definition: tb_defines.h:19
Matrix4 * MatrixCreateScale(Matrix4 *result, const Vector3 *scale)
Definition: tb_matrix.h:720
const Vector3 * GetBasis(const size_t &basisIndex) const
Definition: tb_matrix.h:529
Definition: tb_matrix.h:304
SkipInitialization
Definition: tb_vector.h:29
float & operator[](const size_t &index)
Definition: tb_matrix.h:469
Matrix3(const Matrix3 &other)
Definition: tb_matrix.h:128
float & operator()(const size_t &column, const size_t &row)
Definition: tb_matrix.h:482
Matrix4 * MatrixCreateFromForward(Matrix4 *result, const Vector3 *forward, const Vector3 *up=nullptr)
Definition: tb_matrix.h:667
Vector3 GetPosition(void) const
Definition: tb_matrix.h:560
Matrix4 * MatrixCreatePerspectiveLH(Matrix4 *result, const float fieldOfView, const float aspectRatio, const float nearPlane, const float farPlane)
Definition: tb_matrix.h:890
Matrix4 * MatrixTranspose(Matrix4 *result, const Matrix4 *input)
Definition: tb_matrix.h:1015
Vector4 * Vector4MatrixMultiply(Vector4 *result, const Vector4 *inputVector, const Matrix4 *inputMatrix)
Definition: tb_matrix.h:1084
Matrix4(float f11=0.0f, float f21=0.0f, float f31=0.0f, float f41=0.0f, float f12=0.0f, float f22=0.0f, float f32=0.0f, float f42=0.0f, float f13=0.0f, float f23=0.0f, float f33=0.0f, float f43=0.0f, float f14=0.0f, float f24=0.0f, float f34=0.0f, float f44=0.0f)
Definition: tb_matrix.h:360
Matrix4 * MatrixCreatePerspectiveRH(Matrix4 *result, const float fieldOfView, const float aspectRatio, const float nearPlane, const float farPlane)
Definition: tb_matrix.h:866
bool operator==(const Matrix3 &other) const
Definition: tb_matrix.h:155
Matrix4(const float *const componentArray)
Definition: tb_matrix.h:381
Vector3 * GetBasis(const size_t &basisIndex)
Definition: tb_matrix.h:520
void SetBasis(const size_t &basisIndex, float basisX, float basisY, float basisZ)
Definition: tb_matrix.h:273
bool operator==(const Matrix4 &other) const
Definition: tb_matrix.h:427
Matrix4 & operator=(const Matrix4 &other)
Definition: tb_matrix.h:408
Matrix4 * MatrixSubtract(Matrix4 *result, const Matrix4 *leftSide, const Matrix4 *rightSide)
Definition: tb_matrix.h:996
Matrix4 * MatrixCreateRotationX(Matrix4 *result, const float rotationInDegrees)
Definition: tb_matrix.h:756
const float & operator[](const size_t &index) const
Definition: tb_matrix.h:190
Matrix4 * MatrixComputeInverse(Matrix4 *result, const Matrix4 *input)
Definition: tb_matrix.h:1164
void SetBasis(const size_t &basisIndex, const Vector3 &basis)
Definition: tb_matrix.h:263
const float & operator()(int column, int row) const
Definition: tb_matrix.h:488
bool IsZero(const float value, const float tolerance=tbMath::kTolerance)
Definition: tb_math.h:49
bool IsEqual(const float leftValue, const float rightValue, const float tolerance=tbMath::kTolerance)
Definition: tb_math.h:30
static Matrix3 Zero(void)
Definition: tb_matrix.h:46
Matrix3(const SkipInitialization &fastAndStupid)
Definition: tb_matrix.h:120
Vector3 * Vector3CrossProduct(Vector3 *result, const Vector3 *leftSide, const Vector3 *rightSide)
Definition: tb_vector.h:1193
const Vector3 * GetBasis(const size_t &basisIndex) const
Definition: tb_matrix.h:255
void SetPosition(float x, float y, float z)
Definition: tb_matrix.h:580
Matrix3 & operator=(const Matrix3 &other)
Definition: tb_matrix.h:136
Vector3 * GetBasis(const size_t &basisIndex)
Definition: tb_matrix.h:246
float & operator()(const size_t &column, const size_t &row)
Definition: tb_matrix.h:210
Matrix4 GetTransposed(void) const
Definition: tb_matrix.h:590
Vector3 TransformCoordinate(const Vector3 &inputVector) const
Definition: tb_matrix.h:622
Vector3 * Vector3TransformNormal(Vector3 *result, const Vector3 *inputVector, const Matrix4 *inputMatrix)
Definition: tb_matrix.h:1123
const float & operator()(const size_t &column, const size_t &row) const
Definition: tb_matrix.h:203
void SetBasis(const size_t &basisIndex, const Vector3 &basis)
Definition: tb_matrix.h:537
void SetBasis(const size_t &basisIndex, float basisX, float basisY, float basisZ)
Definition: tb_matrix.h:547
#define tb_error_if(errorTest, message,...)
Definition: tb_error.h:37
Matrix4(const Matrix4 &other)
Definition: tb_matrix.h:400
Matrix4 * MatrixAdd(Matrix4 *result, const Matrix4 *leftSide, const Matrix4 *rightSide)
Definition: tb_matrix.h:976
Matrix4 * MatrixCreateIdentity(Matrix4 *result)
Definition: tb_matrix.h:652
float & operator()(int column, int row)
Definition: tb_matrix.h:223
const float & operator[](const size_t &index) const
Definition: tb_matrix.h:462
Matrix4 * MatrixCreateRotationZ(Matrix4 *result, const float rotationInDegrees)
Definition: tb_matrix.h:794
void SetPosition(const Vector3 &position)
Definition: tb_matrix.h:569
Matrix3(const float *const componentArray)
Definition: tb_matrix.h:109
Definition: tb_vector.h:599
Matrix4(const SkipInitialization &fastAndStupid)
Definition: tb_matrix.h:392