9 #ifndef TurtleBrains_Matrix_hpp
10 #define TurtleBrains_Matrix_hpp
12 #include <turtle_brains/math/tb_vector.hpp>
13 #include <turtle_brains/math/tb_angle.hpp>
14 #include <turtle_brains/core/tb_error.hpp>
15 #include <turtle_brains/core/tb_defines.hpp>
66 enum ColumnMajorMatrix
74 Vector3*
Vector3MatrixMultiply(Vector3* result,
const Vector3* inputVector,
const Matrix3* inputMatrix);
75 Vector3*
MatrixVector3Multiply(Vector3* result,
const Matrix3* inputMatrix,
const Vector3* inputVector);
76 Matrix3*
MatrixMultiply(Matrix3* result,
const Matrix3* left,
const Matrix3* right);
77 Matrix4*
MatrixMultiply(Matrix4* result,
const Matrix4* left,
const Matrix4* right);
78 Matrix3*
MatrixMultiply(Matrix3* result,
const Matrix3* input,
const float scalar);
79 Matrix4*
MatrixMultiply(Matrix4* result,
const Matrix4* input,
const float scalar);
87 Vector4*
Vector4MatrixMultiply(Vector4* result,
const Vector4* inputVector,
const Matrix4* inputMatrix);
88 Vector4*
MatrixVector4Multiply(Vector4* result,
const Matrix4* inputMatrix,
const Vector4* inputVector);
91 Matrix4*
MatrixCreateTranslation(Matrix4* result,
const float translationX,
const float translationY,
const float translationZ);
94 Matrix3*
MatrixCreateScale(Matrix3* result,
const float scaleX,
const float scaleY,
const float scaleZ);
95 Matrix4*
MatrixCreateScale(Matrix4* result,
const float scaleX,
const float scaleY,
const float scaleZ);
139 Matrix3 matrix(tbMath::kSkipInitialization);
144 static Matrix3 Scale(
const float scaleX,
const float scaleY,
const float scaleZ)
146 Matrix3 matrix(tbMath::kSkipInitialization);
147 tbMath::MatrixCreateScale(&matrix, scaleX, scaleY, scaleZ);
153 Matrix3 matrix(tbMath::kSkipInitialization);
154 tbMath::MatrixCreateRotationX(&matrix, rotation);
160 Matrix3 matrix(tbMath::kSkipInitialization);
167 Matrix3 matrix(tbMath::kSkipInitialization);
174 Matrix3 matrix(tbMath::kSkipInitialization);
180 static Matrix3 FromQuaternion(
const tbMath::Unstable::Quaternion& quaternion);
184 float mComponents[9];
186 #if defined(tb_visual_cpp)
187 #pragma warning(push)
188 #pragma warning(disable: 4201)
190 float m_f11;
float m_f21;
float m_f31;
191 float m_f12;
float m_f22;
float m_f32;
192 float m_f13;
float m_f23;
float m_f33;
197 float m_f11;
float m_f21;
float m_f31;
198 float m_f12;
float m_f22;
float m_f32;
199 float m_f13;
float m_f23;
float m_f33;
218 inline explicit Matrix3(
float f11,
float f21,
float f31,
219 float f12,
float f22,
float f32,
220 float f13,
float f23,
float f33) :
233 inline explicit Matrix3(
const float *
const componentArray) :
235 componentArray[0], componentArray[1], componentArray[2],
236 componentArray[3], componentArray[4], componentArray[5],
237 componentArray[6], componentArray[7], componentArray[8] }
257 other.mComponents[0], other.mComponents[1], other.mComponents[2],
258 other.mComponents[3], other.mComponents[4], other.mComponents[5],
259 other.mComponents[6], other.mComponents[7], other.mComponents[8]}
268 memcpy(mComponents, other.mComponents,
sizeof(
float) * 9);
284 for (
size_t index(0); index < 9; ++index)
286 if (
false ==
IsEqual(mComponents[index], other[index]))
302 for (
size_t index(0); index < 9; ++index)
304 if (
false ==
IsEqual(mComponents[index], other[index]))
317 inline const float&
operator[](
const int& index)
const {
return mComponents[index]; }
324 inline float&
operator[](
const int& index) {
return mComponents[index]; }
330 inline const float&
operator()(
const size_t& column,
const size_t& row)
const {
return mComponents[column + (row * 3)]; }
337 inline float&
operator()(
const size_t& column,
const size_t& row) {
return mComponents[column + (row * 3)]; }
343 inline const float&
operator()(
int column,
int row)
const {
return mComponents[column + (row * 3)]; }
350 inline float&
operator()(
int column,
int row) {
return mComponents[column + (row * 3)]; }
359 inline explicit operator float*(void) {
return mComponents; }
364 inline explicit operator const float*(void)
const {
return mComponents; }
381 inline void SetBasis(
const size_t& basisIndex,
const Vector3 &basis) { *((
Vector3*)&mComponents[basisIndex * 3]) = basis; }
391 inline void SetBasis(
const size_t& basisIndex,
float basisX,
float basisY,
float basisZ)
393 mComponents[(basisIndex * 3) + 0] = basisX;
394 mComponents[(basisIndex * 3) + 1] = basisY;
395 mComponents[(basisIndex * 3) + 2] = basisZ;
405 #if defined(tb_with_math_operators)
411 const Matrix3& leftSide(*
this);
413 leftSide(0, 0) + rightSide(0, 0), leftSide(1, 0) + rightSide(1, 0), leftSide(2, 0) + rightSide(2, 0),
414 leftSide(0, 1) + rightSide(0, 1), leftSide(1, 1) + rightSide(1, 1), leftSide(2, 1) + rightSide(2, 1),
415 leftSide(0, 2) + rightSide(0, 2), leftSide(1, 2) + rightSide(1, 2), leftSide(2, 2) + rightSide(2, 2));
424 for (
size_t index = 0; index < 9; ++index)
426 (*this)[index] += rightSide[index];
436 const Matrix3& leftSide(*
this);
438 leftSide(0, 0) - rightSide(0, 0), leftSide(1, 0) - rightSide(1, 0), leftSide(2, 0) - rightSide(2, 0),
439 leftSide(0, 1) - rightSide(0, 1), leftSide(1, 1) - rightSide(1, 1), leftSide(2, 1) - rightSide(2, 1),
440 leftSide(0, 2) - rightSide(0, 2), leftSide(1, 2) - rightSide(1, 2), leftSide(2, 2) - rightSide(2, 2));
448 for (
size_t index = 0; index < 9; ++index)
450 (*this)[index] -= rightSide[index];
479 inline Matrix3 GetTransposed(
void)
const
483 self(0, 0),
self(0, 1),
self(0, 2),
484 self(1, 0),
self(1, 1),
self(1, 2),
485 self(2, 0),
self(2, 1),
self(2, 2));
493 inline Matrix3 ComputeInverse(
void)
const
504 inline Matrix3 FastInverse(
void)
const
536 0.0f, 0.0f, 0.0f, 0.0f,
537 0.0f, 0.0f, 0.0f, 0.0f,
538 0.0f, 0.0f, 0.0f, 0.0f,
539 0.0f, 0.0f, 0.0f, 0.0f);
549 1.0f, 0.0f, 0.0f, 0.0f,
550 0.0f, 1.0f, 0.0f, 0.0f,
551 0.0f, 0.0f, 1.0f, 0.0f,
552 0.0f, 0.0f, 0.0f, 1.0f);
558 Matrix4 matrix(tbMath::kSkipInitialization);
563 static Matrix4 Translation(
const float translationX,
const float translationY,
const float translationZ)
565 Matrix4 matrix(tbMath::kSkipInitialization);
566 tbMath::MatrixCreateTranslation(&matrix, translationX, translationY, translationZ);
572 Matrix4 matrix(tbMath::kSkipInitialization);
573 tbMath::MatrixCreateScale(&matrix, &scale);
577 static Matrix4 Scale(
const float scaleX,
const float scaleY,
const float scaleZ)
579 Matrix4 matrix(tbMath::kSkipInitialization);
586 Matrix4 matrix(tbMath::kSkipInitialization);
593 Matrix4 matrix(tbMath::kSkipInitialization);
600 Matrix4 matrix(tbMath::kSkipInitialization);
607 Matrix4 matrix(tbMath::kSkipInitialization);
613 static Matrix4 FromQuaternion(
const tbMath::Unstable::Quaternion& quaternion,
const tbMath::Vector3& translation);
618 float mComponents[16];
620 #if defined(tb_visual_cpp)
621 #pragma warning(push)
622 #pragma warning(disable: 4201)
625 float xx;
float xy;
float xz;
float hx;
626 float yx;
float yy;
float yz;
float hy;
627 float zx;
float zy;
float zz;
float hz;
628 float tx;
float ty;
float tz;
float ht;
630 #if defined(tb_visual_cpp)
640 1.0f, 0.0f, 0.0f, 0.0f,
641 0.0f, 1.0f, 0.0f, 0.0f,
642 0.0f, 0.0f, 1.0f, 0.0f,
643 0.0f, 0.0f, 0.0f, 1.0f}
651 float f11,
float f21,
float f31,
float f41,
652 float f12,
float f22,
float f32,
float f42,
653 float f13,
float f23,
float f33,
float f43,
654 float f14,
float f24,
float f34,
float f44) :
670 float f11,
float f21,
float f31,
float f41,
671 float f12,
float f22,
float f32,
float f42,
672 float f13,
float f23,
float f33,
float f43,
673 float f14,
float f24,
float f34,
float f44,
const ColumnMajorMatrix& columnMajor) :
688 inline explicit Matrix4(
const float*
const componentArray) :
690 componentArray[0], componentArray[1], componentArray[2], componentArray[3],
691 componentArray[4], componentArray[5], componentArray[6], componentArray[7],
692 componentArray[8], componentArray[9], componentArray[10], componentArray[11],
693 componentArray[12], componentArray[13], componentArray[14], componentArray[15] }
704 inline explicit Matrix4(
const float*
const componentArray,
const ColumnMajorMatrix& columnMajor) :
706 componentArray[0], componentArray[4], componentArray[8], componentArray[12],
707 componentArray[1], componentArray[5], componentArray[9], componentArray[13],
708 componentArray[2], componentArray[6], componentArray[10], componentArray[14],
709 componentArray[3], componentArray[7], componentArray[11], componentArray[15] }
730 other.mComponents[0], other.mComponents[1], other.mComponents[2], other.mComponents[3],
731 other.mComponents[4], other.mComponents[5], other.mComponents[6], other.mComponents[7],
732 other.mComponents[8], other.mComponents[9], other.mComponents[10], other.mComponents[11],
733 other.mComponents[12], other.mComponents[13], other.mComponents[14], other.mComponents[15]
743 memcpy(mComponents, other.mComponents,
sizeof(
float) << 4);
759 for (
size_t index(0); index < 16; ++index)
761 if (
false ==
IsEqual(mComponents[index], other[index]))
777 for (
size_t index(0); index < 16; ++index)
779 if (
false ==
IsEqual(mComponents[index], other[index]))
792 inline const float&
operator[](
const size_t& index)
const {
return mComponents[index]; }
799 inline float&
operator[](
const size_t& index) {
return mComponents[index]; }
805 inline const float&
operator()(
const size_t& column,
const size_t& row)
const {
return mComponents[column + (row << 2)]; }
812 inline float&
operator()(
const size_t& column,
const size_t& row) {
return mComponents[column + (row << 2)]; }
818 inline const float&
operator()(
int column,
int row)
const {
return mComponents[column + (row << 2)]; }
825 inline float&
operator()(
int column,
int row) {
return mComponents[column + (row << 2)]; }
835 inline explicit operator float*(void) {
return mComponents; }
840 inline explicit operator const float*(void)
const {
return mComponents; }
857 inline void SetBasis(
const size_t& basisIndex,
const Vector3 &basis) { *((
Vector3*)&mComponents[basisIndex<<2]) = basis; }
867 inline void SetBasis(
const size_t& basisIndex,
float basisX,
float basisY,
float basisZ)
869 mComponents[(basisIndex<<2) + 0] = basisX;
870 mComponents[(basisIndex<<2) + 1] = basisY;
871 mComponents[(basisIndex<<2) + 2] = basisZ;
881 return Vector3(&mComponents[12]);
890 (*this)(0, 3) = position.x;
891 (*
this)(1, 3) = position.y;
892 (*
this)(2, 3) = position.z;
899 inline void SetPosition(
const float x,
const float y,
const float z)
906 #if defined(tb_with_math_operators)
912 const Matrix4& leftSide(*
this);
914 leftSide(0, 0) + rightSide(0, 0), leftSide(1, 0) + rightSide(1, 0), leftSide(2, 0) + rightSide(2, 0), leftSide(3, 0) + rightSide(3, 0),
915 leftSide(0, 1) + rightSide(0, 1), leftSide(1, 1) + rightSide(1, 1), leftSide(2, 1) + rightSide(2, 1), leftSide(3, 1) + rightSide(3, 1),
916 leftSide(0, 2) + rightSide(0, 2), leftSide(1, 2) + rightSide(1, 2), leftSide(2, 2) + rightSide(2, 2), leftSide(3, 2) + rightSide(3, 2),
917 leftSide(0, 3) + rightSide(0, 3), leftSide(1, 3) + rightSide(1, 3), leftSide(2, 3) + rightSide(2, 3), leftSide(3, 3) + rightSide(3, 3));
926 for (
size_t index = 0; index < 16; ++index)
928 (*this)[index] += rightSide[index];
938 const Matrix4& leftSide(*
this);
940 leftSide(0, 0) - rightSide(0, 0), leftSide(1, 0) - rightSide(1, 0), leftSide(2, 0) - rightSide(2, 0), leftSide(3, 0) - rightSide(3, 0),
941 leftSide(0, 1) - rightSide(0, 1), leftSide(1, 1) - rightSide(1, 1), leftSide(2, 1) - rightSide(2, 1), leftSide(3, 1) - rightSide(3, 1),
942 leftSide(0, 2) - rightSide(0, 2), leftSide(1, 2) - rightSide(1, 2), leftSide(2, 2) - rightSide(2, 2), leftSide(3, 2) - rightSide(3, 2),
943 leftSide(0, 3) - rightSide(0, 3), leftSide(1, 3) - rightSide(1, 3), leftSide(2, 3) - rightSide(2, 3), leftSide(3, 3) - rightSide(3, 3));
951 for (
size_t index = 0; index < 16; ++index)
953 (*this)[index] -= rightSide[index];
981 inline Matrix4 GetTransposed(
void)
const
985 temp(0, 0) =
self(0, 0); temp(0, 1) =
self(1, 0); temp(0, 2) =
self(2, 0); temp(0, 3) =
self(3, 0);
986 temp(1, 0) =
self(0, 1); temp(1, 1) =
self(1, 1); temp(1, 2) =
self(2, 1); temp(1, 3) =
self(3, 1);
987 temp(2, 0) =
self(0, 2); temp(2, 1) =
self(1, 2); temp(2, 2) =
self(2, 2); temp(2, 3) =
self(3, 2);
988 temp(3, 0) =
self(0, 3); temp(3, 1) =
self(1, 3); temp(3, 2) =
self(2, 3); temp(3, 3) =
self(3, 3);
997 inline Matrix4 ComputeInverse(
void)
const
1010 inline Matrix4 FastInverse(
void)
const
1021 inline Vector3 TransformCoordinate(
const Vector3& inputVector)
const
1032 inline Vector3 TransformNormal(
const Vector3& inputVector)
const
1042 inline Vector4 Transform(
const Vector4& inputVector)
const
1052 #if defined(tb_with_math_operators)
1057 inline Matrix3 operator*(
const float leftSide,
const Matrix3& rightSide)
1067 inline Matrix3 operator*(
const Matrix3& leftSide,
const float rightSide)
1077 inline Matrix4 operator*(
const float leftSide,
const Matrix4& rightSide)
1087 inline Matrix4 operator*(
const Matrix4& leftSide,
const float rightSide)
1098 inline Vector3 operator*(
const Vector3& leftSide,
const Matrix3& rightSide)
1109 inline Vector3 operator*(
const Matrix3& leftSide,
const Vector3& rightSide)
1120 inline Vector4 operator*(
const Vector4& leftSide,
const Matrix4& rightSide)
1131 inline Vector4 operator*(
const Matrix4& leftSide,
const Vector4& rightSide)
1176 tb_error_if(
nullptr == result,
"tbExternalError: Invalid parameter; Expected result to be valid pointer.");
1178 Vector3 right, finalUp, forward;
1182 #if defined(tb_debug_build) //Going to refer to these as the Math Idiot proofing tests.
1183 tb_error_if(eyePosition == targetPosition,
"tbExternalError: Invalid parameter; This would result in looking directly at eye position.");
1184 tb_error_if(fabsf(
Vector3Magnitude(&unitUp) - 1.0f) > 0.00001f,
"tbExternalError: Invalid unitUp, this is not a unit length vector.");
1196 result->
SetBasis(0, right.x, finalUp.x, forward.x);
1197 result->
SetBasis(1, right.y, finalUp.y, forward.y);
1198 result->
SetBasis(2, right.z, finalUp.z, forward.z);
1200 (*result)(0, 3) = -(eyePosition.x * (*result)(0, 0) + eyePosition.y * (*result)(0, 1) + eyePosition.z * (*result)(0, 2));
1201 (*result)(1, 3) = -(eyePosition.x * (*result)(1, 0) + eyePosition.y * (*result)(1, 1) + eyePosition.z * (*result)(1, 2));
1202 (*result)(2, 3) = -(eyePosition.x * (*result)(2, 0) + eyePosition.y * (*result)(2, 1) + eyePosition.z * (*result)(2, 2));
1216 (*result)(0, 3) = translation->x;
1217 (*result)(1, 3) = translation->y;
1218 (*result)(2, 3) = translation->z;
1234 (*result)(0, 3) = translationX;
1235 (*result)(1, 3) = translationY;
1236 (*result)(2, 3) = translationZ;
1249 memset(result->mComponents, 0,
sizeof(
float) * 9);
1250 (*result)(0, 0) = scale->x;
1251 (*result)(1, 1) = scale->y;
1252 (*result)(2, 2) = scale->z;
1261 memset(result->mComponents, 0,
sizeof(
float) << 4);
1262 (*result)(0, 0) = scale->x;
1263 (*result)(1, 1) = scale->y;
1264 (*result)(2, 2) = scale->z;
1265 (*result)(3, 3) = 1.0f;
1280 memset(result->mComponents, 0,
sizeof(
float) * 9);
1281 (*result)(0, 0) = scaleX;
1282 (*result)(1, 1) = scaleY;
1283 (*result)(2, 2) = scaleZ;
1292 memset(result->mComponents, 0,
sizeof(
float) << 4);
1293 (*result)(0, 0) = scaleX;
1294 (*result)(1, 1) = scaleY;
1295 (*result)(2, 2) = scaleZ;
1296 (*result)(3, 3) = 1.0f;
1310 const float sinOfRotation = sinf(rotation.
AsRadians());
1311 const float cosOfRotation = cosf(rotation.
AsRadians());
1312 (*result)(1, 1) = cosOfRotation;
1313 (*result)(2, 1) = -sinOfRotation;
1314 (*result)(1, 2) = sinOfRotation;
1315 (*result)(2, 2) = cosOfRotation;
1325 const float sinOfRotation = sinf(rotation.
AsRadians());
1326 const float cosOfRotation = cosf(rotation.
AsRadians());
1327 (*result)(1, 1) = cosOfRotation;
1328 (*result)(2, 1) = -sinOfRotation;
1329 (*result)(1, 2) = sinOfRotation;
1330 (*result)(2, 2) = cosOfRotation;
1344 const float sinOfRotation = sinf(rotation.
AsRadians());
1345 const float cosOfRotation = cosf(rotation.
AsRadians());
1346 (*result)(0, 0) = cosOfRotation;
1347 (*result)(2, 0) = sinOfRotation;
1348 (*result)(0, 2) = -sinOfRotation;
1349 (*result)(2, 2) = cosOfRotation;
1359 const float sinOfRotation = sinf(rotation.
AsRadians());
1360 const float cosOfRotation = cosf(rotation.
AsRadians());
1361 (*result)(0, 0) = cosOfRotation;
1362 (*result)(2, 0) = sinOfRotation;
1363 (*result)(0, 2) = -sinOfRotation;
1364 (*result)(2, 2) = cosOfRotation;
1378 const float sinOfRotation = sinf(rotation.
AsRadians());
1379 const float cosOfRotation = cosf(rotation.
AsRadians());
1380 (*result)(0, 0) = cosOfRotation;
1381 (*result)(1, 0) = -sinOfRotation;
1382 (*result)(0, 1) = sinOfRotation;
1383 (*result)(1, 1) = cosOfRotation;
1393 const float sinOfRotation = sinf(rotation.
AsRadians());
1394 const float cosOfRotation = cosf(rotation.
AsRadians());
1395 (*result)(0, 0) = cosOfRotation;
1396 (*result)(1, 0) = -sinOfRotation;
1397 (*result)(0, 1) = sinOfRotation;
1398 (*result)(1, 1) = cosOfRotation;
1412 const float s = sinf(rotation.
AsRadians());
1413 const float c = cosf(rotation.
AsRadians());
1414 const float t = 1.0f - c;
1416 const auto av = rotationAxis->GetNormalized();
1420 (*result)(0, 0) = c + tv.x * av.x;
1421 (*result)(0, 1) = tv.x * av.y + sv.z;
1422 (*result)(0, 2) = tv.x * av.z - sv.y;
1424 (*result)(1, 0) = tv.y * av.x - sv.z;
1425 (*result)(1, 1) = c + tv.y * av.y;
1426 (*result)(1, 2) = tv.y * av.z + sv.x;
1428 (*result)(2, 0) = tv.z * av.x + sv.y;
1429 (*result)(2, 1) = tv.z * av.y - sv.x;
1430 (*result)(2, 2) = c + tv.z * av.z;
1440 const float s = sinf(rotation.
AsRadians());
1441 const float c = cosf(rotation.
AsRadians());
1442 const float t = 1.0f - c;
1444 const auto av = rotationAxis->GetNormalized();
1448 (*result)(0, 0) = c + tv.x * av.x;
1449 (*result)(0, 1) = tv.x * av.y + sv.z;
1450 (*result)(0, 2) = tv.x * av.z - sv.y;
1451 (*result)(0, 3) = 0.0f;
1453 (*result)(1, 0) = tv.y * av.x - sv.z;
1454 (*result)(1, 1) = c + tv.y * av.y;
1455 (*result)(1, 2) = tv.y * av.z + sv.x;
1456 (*result)(1, 3) = 0.0f;
1458 (*result)(2, 0) = tv.z * av.x + sv.y;
1459 (*result)(2, 1) = tv.z * av.y - sv.x;
1460 (*result)(2, 2) = c + tv.z * av.z;
1461 (*result)(2, 3) = 0.0f;
1463 (*result)(3, 0) = 0.0f;
1464 (*result)(3, 1) = 0.0f;
1465 (*result)(3, 2) = 0.0f;
1466 (*result)(3, 3) = 1.0f;
1484 const float nearPlane,
const float farPlane)
1486 memset(result->mComponents, 0,
sizeof(
float) << 4);
1490 const float t = tan(fieldOfView / 2.0f);
1491 (*result)(0, 0) = 1.0f / (aspectRatio * t);
1492 (*result)(1, 1) = 1.0f / t;
1493 (*result)(2, 2) = -(farPlane + nearPlane) / (farPlane - nearPlane);
1494 (*result)(3, 2) = -1.0f;
1495 (*result)(2, 3) = -(2.0f * farPlane * nearPlane) / (farPlane - nearPlane);
1513 const float nearPlane,
const float farPlane)
1515 memset(result->mComponents, 0,
sizeof(
float) << 4);
1519 const float t = tan(fieldOfView / 2.0f);
1520 (*result)(0, 0) = 1.0f / (aspectRatio * t);
1521 (*result)(1, 1) = 1.0f / t;
1522 (*result)(2, 2) = (farPlane + nearPlane) / (farPlane - nearPlane);
1523 (*result)(3, 2) = 1.0f;
1524 (*result)(2, 3) = -(2.0f * farPlane * nearPlane) / (farPlane - nearPlane);
1545 const float top,
const float bottom,
const float nearPlane,
const float farPlane)
1548 memset(result->mComponents, 0,
sizeof(
float) << 4);
1550 output(0, 0) = 2.0f / (right - left);
1551 output(1, 1) = 2.0f / (top - bottom);
1552 output(2, 2) = -2.0f / (farPlane - nearPlane);
1553 output(3, 3) = 1.0f;
1554 output(0, 3) = -(right + left) / (right - left);
1555 output(1, 3) = -(top + bottom) / (top - bottom);
1556 output(2, 3) = -((farPlane + nearPlane) / (farPlane - nearPlane));
1577 const float top,
const float bottom,
const float nearPlane,
const float farPlane)
1580 memset(result->mComponents, 0,
sizeof(
float) << 4);
1582 output(0, 0) = 2.0f / (right - left);
1583 output(1, 1) = 2.0f / (top - bottom);
1584 output(2, 2) = 2.0f / (farPlane - nearPlane);
1585 output(3, 3) = 1.0f;
1586 output(0, 3) = -(right + left) / (right - left);
1587 output(1, 3) = -(top + bottom) / (top - bottom);
1588 output(2, 3) = -(farPlane + nearPlane) / (farPlane - nearPlane);
1602 float *r = result->mComponents;
1603 const float *m1 = leftSide->mComponents;
1604 const float *m2 = rightSide->mComponents;
1606 r[0] = m1[0] + m2[0]; r[1] = m1[1] + m2[1]; r[2] = m1[2] + m2[2];
1607 r[3] = m1[3] + m2[3]; r[4] = m1[4] + m2[4]; r[5] = m1[5] + m2[5];
1608 r[6] = m1[6] + m2[6]; r[7] = m1[7] + m2[7]; r[8] = m1[8] + m2[8];
1617 float *r = result->mComponents;
1618 const float *m1 = leftSide->mComponents;
1619 const float *m2 = rightSide->mComponents;
1621 r[0] = m1[0] + m2[0]; r[1] = m1[1] + m2[1]; r[2] = m1[2] + m2[2]; r[3] = m1[3] + m2[3];
1622 r[4] = m1[4] + m2[4]; r[5] = m1[5] + m2[5]; r[6] = m1[6] + m2[6]; r[7] = m1[7] + m2[7];
1623 r[8] = m1[8] + m2[8]; r[9] = m1[9] + m2[9]; r[10] = m1[10] + m2[10]; r[11] = m1[11] + m2[11];
1624 r[12] = m1[12] + m2[12]; r[13] = m1[13] + m2[13]; r[14] = m1[14] + m2[14]; r[15] = m1[15] + m2[15];
1638 float *r = result->mComponents;
1639 const float *m1 = leftSide->mComponents;
1640 const float *m2 = rightSide->mComponents;
1642 r[0] = m1[0] - m2[0]; r[1] = m1[1] - m2[1]; r[2] = m1[2] - m2[2];
1643 r[3] = m1[3] - m2[3]; r[4] = m1[4] - m2[4]; r[5] = m1[5] - m2[5];
1644 r[6] = m1[6] - m2[6]; r[7] = m1[7] - m2[7]; r[8] = m1[8] - m2[8];
1653 float *r = result->mComponents;
1654 const float *m1 = leftSide->mComponents;
1655 const float *m2 = rightSide->mComponents;
1657 r[0] = m1[0] - m2[0]; r[1] = m1[1] - m2[1]; r[2] = m1[2] - m2[2]; r[3] = m1[3] - m2[3];
1658 r[4] = m1[4] - m2[4]; r[5] = m1[5] - m2[5]; r[6] = m1[6] - m2[6]; r[7] = m1[7] - m2[7];
1659 r[8] = m1[8] - m2[8]; r[9] = m1[9] - m2[9]; r[10] = m1[10] - m2[10]; r[11] = m1[11] - m2[11];
1660 r[12] = m1[12] - m2[12]; r[13] = m1[13] - m2[13]; r[14] = m1[14] - m2[14]; r[15] = m1[15] - m2[15];
1672 tb_error_if(result == input,
"tbExternalError: Invalid parameter; expected result to be different than input");
1676 a(0, 0) = b(0, 0); a(0, 1) = b(1, 0); a(0, 2) = b(2, 0);
1677 a(1, 0) = b(0, 1); a(1, 1) = b(1, 1); a(1, 2) = b(2, 1);
1678 a(2, 0) = b(0, 2); a(2, 1) = b(1, 2); a(2, 2) = b(2, 2);
1690 tb_error_if(result == input,
"tbExternalError: Invalid parameter; expected result to be different than input");
1694 a(0, 0) = b(0, 0); a(0, 1) = b(1, 0); a(0, 2) = b(2, 0); a(0, 3) = b(3, 0);
1695 a(1, 0) = b(0, 1); a(1, 1) = b(1, 1); a(1, 2) = b(2, 1); a(1, 3) = b(3, 1);
1696 a(2, 0) = b(0, 2); a(2, 1) = b(1, 2); a(2, 2) = b(2, 2); a(2, 3) = b(3, 2);
1697 a(3, 0) = b(0, 3); a(3, 1) = b(1, 3); a(3, 2) = b(2, 3); a(3, 3) = b(3, 3);
1713 tb_error_if(result == leftSide || result == rightSide,
"tbExternalError: Invalid parameter; expected result to be different than leftSide and rightSide");
1718 (*result)(0, 0) = a(0, 0) * b(0, 0) + a(1, 0) * b(0, 1) + a(2, 0) * b(0, 2);
1719 (*result)(1, 0) = a(0, 0) * b(1, 0) + a(1, 0) * b(1, 1) + a(2, 0) * b(1, 2);
1720 (*result)(2, 0) = a(0, 0) * b(2, 0) + a(1, 0) * b(2, 1) + a(2, 0) * b(2, 2);
1721 (*result)(0, 1) = a(0, 1) * b(0, 0) + a(1, 1) * b(0, 1) + a(2, 1) * b(0, 2);
1722 (*result)(1, 1) = a(0, 1) * b(1, 0) + a(1, 1) * b(1, 1) + a(2, 1) * b(1, 2);
1723 (*result)(2, 1) = a(0, 1) * b(2, 0) + a(1, 1) * b(2, 1) + a(2, 1) * b(2, 2);
1724 (*result)(0, 2) = a(0, 2) * b(0, 0) + a(1, 2) * b(0, 1) + a(2, 2) * b(0, 2);
1725 (*result)(1, 2) = a(0, 2) * b(1, 0) + a(1, 2) * b(1, 1) + a(2, 2) * b(1, 2);
1726 (*result)(2, 2) = a(0, 2) * b(2, 0) + a(1, 2) * b(2, 1) + a(2, 2) * b(2, 2);
1736 tb_error_if(result == leftSide || result == rightSide,
"tbExternalError: Invalid parameter; expected result to be different than leftSide and rightSide");
1741 (*result)(0, 0) = a(0, 0) * b(0, 0) + a(1, 0) * b(0, 1) + a(2, 0) * b(0, 2) + a(3, 0) * b(0, 3);
1742 (*result)(1, 0) = a(0, 0) * b(1, 0) + a(1, 0) * b(1, 1) + a(2, 0) * b(1, 2) + a(3, 0) * b(1, 3);
1743 (*result)(2, 0) = a(0, 0) * b(2, 0) + a(1, 0) * b(2, 1) + a(2, 0) * b(2, 2) + a(3, 0) * b(2, 3);
1744 (*result)(3, 0) = a(0, 0) * b(3, 0) + a(1, 0) * b(3, 1) + a(2, 0) * b(3, 2) + a(3, 0) * b(3, 3);
1745 (*result)(0, 1) = a(0, 1) * b(0, 0) + a(1, 1) * b(0, 1) + a(2, 1) * b(0, 2) + a(3, 1) * b(0, 3);
1746 (*result)(1, 1) = a(0, 1) * b(1, 0) + a(1, 1) * b(1, 1) + a(2, 1) * b(1, 2) + a(3, 1) * b(1, 3);
1747 (*result)(2, 1) = a(0, 1) * b(2, 0) + a(1, 1) * b(2, 1) + a(2, 1) * b(2, 2) + a(3, 1) * b(2, 3);
1748 (*result)(3, 1) = a(0, 1) * b(3, 0) + a(1, 1) * b(3, 1) + a(2, 1) * b(3, 2) + a(3, 1) * b(3, 3);
1749 (*result)(0, 2) = a(0, 2) * b(0, 0) + a(1, 2) * b(0, 1) + a(2, 2) * b(0, 2) + a(3, 2) * b(0, 3);
1750 (*result)(1, 2) = a(0, 2) * b(1, 0) + a(1, 2) * b(1, 1) + a(2, 2) * b(1, 2) + a(3, 2) * b(1, 3);
1751 (*result)(2, 2) = a(0, 2) * b(2, 0) + a(1, 2) * b(2, 1) + a(2, 2) * b(2, 2) + a(3, 2) * b(2, 3);
1752 (*result)(3, 2) = a(0, 2) * b(3, 0) + a(1, 2) * b(3, 1) + a(2, 2) * b(3, 2) + a(3, 2) * b(3, 3);
1753 (*result)(0, 3) = a(0, 3) * b(0, 0) + a(1, 3) * b(0, 1) + a(2, 3) * b(0, 2) + a(3, 3) * b(0, 3);
1754 (*result)(1, 3) = a(0, 3) * b(1, 0) + a(1, 3) * b(1, 1) + a(2, 3) * b(1, 2) + a(3, 3) * b(1, 3);
1755 (*result)(2, 3) = a(0, 3) * b(2, 0) + a(1, 3) * b(2, 1) + a(2, 3) * b(2, 2) + a(3, 3) * b(2, 3);
1756 (*result)(3, 3) = a(0, 3) * b(3, 0) + a(1, 3) * b(3, 1) + a(2, 3) * b(3, 2) + a(3, 3) * b(3, 3);
1772 float* resultComponents = result->mComponents;
1773 const float* inputComponents = input->mComponents;
1774 for (
size_t index = 0; index < 9; ++index)
1776 resultComponents[index] = inputComponents[index] * scalar;
1792 float* resultComponents = result->mComponents;
1793 const float* inputComponents = input->mComponents;
1794 for (
size_t index = 0; index < 16; ++index)
1796 resultComponents[index] = inputComponents[index] * scalar;
1835 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector.");
1836 result->x = (inputVector->x * (*inputMatrix)(0, 0)) + (inputVector->y * (*inputMatrix)(1, 0)) + (inputVector->z * (*inputMatrix)(2, 0));
1837 result->y = (inputVector->x * (*inputMatrix)(0, 1)) + (inputVector->y * (*inputMatrix)(1, 1)) + (inputVector->z * (*inputMatrix)(2, 1));
1838 result->z = (inputVector->x * (*inputMatrix)(0, 2)) + (inputVector->y * (*inputMatrix)(1, 2)) + (inputVector->z * (*inputMatrix)(2, 2));
1855 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector.");
1856 result->x = (inputVector->x * (*inputMatrix)(0, 0)) + (inputVector->y * (*inputMatrix)(0, 1)) + (inputVector->z * (*inputMatrix)(0, 2));
1857 result->y = (inputVector->x * (*inputMatrix)(1, 0)) + (inputVector->y * (*inputMatrix)(1, 1)) + (inputVector->z * (*inputMatrix)(1, 2));
1858 result->z = (inputVector->x * (*inputMatrix)(2, 0)) + (inputVector->y * (*inputMatrix)(2, 1)) + (inputVector->z * (*inputMatrix)(2, 2));
1875 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector.");
1876 result->x = (inputVector->x * (*inputMatrix)(0, 0)) + (inputVector->y * (*inputMatrix)(1, 0)) + (inputVector->z * (*inputMatrix)(2, 0)) + (inputVector->w * (*inputMatrix)(3, 0));
1877 result->y = (inputVector->x * (*inputMatrix)(0, 1)) + (inputVector->y * (*inputMatrix)(1, 1)) + (inputVector->z * (*inputMatrix)(2, 1)) + (inputVector->w * (*inputMatrix)(3, 1));
1878 result->z = (inputVector->x * (*inputMatrix)(0, 2)) + (inputVector->y * (*inputMatrix)(1, 2)) + (inputVector->z * (*inputMatrix)(2, 2)) + (inputVector->w * (*inputMatrix)(3, 2));
1879 result->w = (inputVector->x * (*inputMatrix)(0, 3)) + (inputVector->y * (*inputMatrix)(1, 3)) + (inputVector->z * (*inputMatrix)(2, 3)) + (inputVector->w * (*inputMatrix)(3, 3));
1896 tb_error_if(result == inputVector ,
"tbExternalError: Invalid parameter; expected result to be different than inputVector.");
1897 result->x = (inputVector->x * (*inputMatrix)(0, 0)) + (inputVector->y * (*inputMatrix)(0, 1)) + (inputVector->z * (*inputMatrix)(0, 2)) + (inputVector->w * (*inputMatrix)(0, 3));
1898 result->y = (inputVector->x * (*inputMatrix)(1, 0)) + (inputVector->y * (*inputMatrix)(1, 1)) + (inputVector->z * (*inputMatrix)(1, 2)) + (inputVector->w * (*inputMatrix)(1, 3));
1899 result->z = (inputVector->x * (*inputMatrix)(2, 0)) + (inputVector->y * (*inputMatrix)(2, 1)) + (inputVector->z * (*inputMatrix)(2, 2)) + (inputVector->w * (*inputMatrix)(2, 3));
1900 result->w = (inputVector->x * (*inputMatrix)(3, 0)) + (inputVector->y * (*inputMatrix)(3, 1)) + (inputVector->z * (*inputMatrix)(3, 2)) + (inputVector->w * (*inputMatrix)(3, 3));
1916 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector");
1918 const Matrix4& matrix(*inputMatrix);
1919 result->x = (inputVector->x * matrix(0, 0)) + (inputVector->y * matrix(0, 1)) + (inputVector->z * matrix(0, 2)) + matrix(0, 3);
1920 result->y = (inputVector->x * matrix(1, 0)) + (inputVector->y * matrix(1, 1)) + (inputVector->z * matrix(1, 2)) + matrix(1, 3);
1921 result->z = (inputVector->x * matrix(2, 0)) + (inputVector->y * matrix(2, 1)) + (inputVector->z * matrix(2, 2)) + matrix(2, 3);
1938 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector");
1940 const Matrix4& matrix(*inputMatrix);
1941 result->x = (inputVector->x * matrix(0, 0)) + (inputVector->y * matrix(0, 1)) + (inputVector->z * matrix(0, 2));
1942 result->y = (inputVector->x * matrix(1, 0)) + (inputVector->y * matrix(1, 1)) + (inputVector->z * matrix(1, 2));
1943 result->z = (inputVector->x * matrix(2, 0)) + (inputVector->y * matrix(2, 1)) + (inputVector->z * matrix(2, 2));
1947 inline float Matrix2x2Determinant(
const float f11,
const float f12,
const float f21,
const float f22)
1949 return f11 * f22 - f12 * f21;
1956 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)
1958 return f11 * (f22 * f33 - f32 * f23) - f12 * (f21 * f33 - f31 * f23) + f13 * (f21 * f32 - f31 * f22);
1968 return m(0, 0) * (m(1, 1) * m(2, 2) - m(2, 1) * m(1, 2)) - m(0, 1) * (m(1, 0) * m(2, 2) - m(2, 0) * m(1, 2)) + m(0, 2) * (m(1, 0) * m(2, 1) - m(2, 0) * m(1, 1));
1978 return (m(0, 0) *
Matrix3x3Determinant(m(1, 1), m(2, 1), m(3, 1), m(1, 2), m(2, 2), m(3, 2), m(1, 3), m(2, 3), m(3, 3))) -
1979 (m(1, 0) *
Matrix3x3Determinant(m(0, 1), m(2, 1), m(3, 1), m(0, 2), m(2, 2), m(3, 2), m(0, 3), m(2, 3), m(3, 3))) +
1980 (m(2, 0) *
Matrix3x3Determinant(m(0, 1), m(1, 1), m(3, 1), m(0, 2), m(1, 2), m(3, 2), m(0, 3), m(1, 3), m(3, 3))) -
1981 (m(3, 0) *
Matrix3x3Determinant(m(0, 1), m(1, 1), m(2, 1), m(0, 2), m(1, 2), m(2, 2), m(0, 3), m(1, 3), m(2, 3)));
1991 tb_error_if(result == input,
"tbExternalError: Invalid parameter, expected result to be different than input.");
1993 if (
true ==
IsZero(determinant))
1999 const float inverseDeterminant = 1.0f / determinant;
2002 (*result)(0, 0) = Matrix2x2Determinant(m(1, 1), m(1, 2), m(2, 1), m(2, 2)) * inverseDeterminant;
2003 (*result)(1, 0) = -Matrix2x2Determinant(m(1, 0), m(1, 2), m(2, 0), m(2, 2)) * inverseDeterminant;
2004 (*result)(2, 0) = Matrix2x2Determinant(m(1, 0), m(1, 1), m(2, 0), m(2, 1)) * inverseDeterminant;
2005 (*result)(0, 1) = -Matrix2x2Determinant(m(0, 1), m(0, 2), m(2, 1), m(2, 2)) * inverseDeterminant;
2006 (*result)(1, 1) = Matrix2x2Determinant(m(0, 0), m(0, 2), m(2, 0), m(2, 2)) * inverseDeterminant;
2007 (*result)(2, 1) = -Matrix2x2Determinant(m(0, 0), m(0, 1), m(2, 0), m(2, 1)) * inverseDeterminant;
2008 (*result)(0, 2) = Matrix2x2Determinant(m(0, 1), m(0, 2), m(1, 1), m(1, 2)) * inverseDeterminant;
2009 (*result)(1, 2) = -Matrix2x2Determinant(m(0, 0), m(0, 2), m(1, 0), m(1, 2)) * inverseDeterminant;
2010 (*result)(2, 2) = Matrix2x2Determinant(m(0, 0), m(0, 1), m(1, 0), m(1, 1)) * inverseDeterminant;
2027 tb_error_if(result == input,
"tbExternalError: Invalid parameter, expected result to be different than input.");
2029 if (
true ==
IsZero(determinant))
2035 const float inverseDeterminant = 1.0f / determinant;
2037 (*result)(0, 0) =
Matrix3x3Determinant (m(1,1), m(2,1), m(3,1), m(1,2), m(2,2), m(3,2), m(1,3), m(2,3), m(3,3)) * inverseDeterminant;
2038 (*result)(1, 0) = -
Matrix3x3Determinant(m(1,0), m(2,0), m(3,0), m(1,2), m(2,2), m(3,2), m(1,3), m(2,3), m(3,3)) * inverseDeterminant;
2039 (*result)(2, 0) =
Matrix3x3Determinant (m(1,0), m(2,0), m(3,0), m(1,1), m(2,1), m(3,1), m(1,3), m(2,3), m(3,3)) * inverseDeterminant;
2040 (*result)(3, 0) = -
Matrix3x3Determinant(m(1,0), m(2,0), m(3,0), m(1,1), m(2,1), m(3,1), m(1,2), m(2,2), m(3,2)) * inverseDeterminant;
2041 (*result)(0, 1) = -
Matrix3x3Determinant(m(0,1), m(2,1), m(3,1), m(0,2), m(2,2), m(3,2), m(0,3), m(2,3), m(3,3)) * inverseDeterminant;
2042 (*result)(1, 1) =
Matrix3x3Determinant (m(0,0), m(2,0), m(3,0), m(0,2), m(2,2), m(3,2), m(0,3), m(2,3), m(3,3)) * inverseDeterminant;
2043 (*result)(2, 1) = -
Matrix3x3Determinant(m(0,0), m(2,0), m(3,0), m(0,1), m(2,1), m(3,1), m(0,3), m(2,3), m(3,3)) * inverseDeterminant;
2044 (*result)(3, 1) =
Matrix3x3Determinant (m(0,0), m(2,0), m(3,0), m(0,1), m(2,1), m(3,1), m(0,2), m(2,2), m(3,2)) * inverseDeterminant;
2045 (*result)(0, 2) =
Matrix3x3Determinant (m(0,1), m(1,1), m(3,1), m(0,2), m(1,2), m(3,2), m(0,3), m(1,3), m(3,3)) * inverseDeterminant;
2046 (*result)(1, 2) = -
Matrix3x3Determinant(m(0,0), m(1,0), m(3,0), m(0,2), m(1,2), m(3,2), m(0,3), m(1,3), m(3,3)) * inverseDeterminant;
2047 (*result)(2, 2) =
Matrix3x3Determinant (m(0,0), m(1,0), m(3,0), m(0,1), m(1,1), m(3,1), m(0,3), m(1,3), m(3,3)) * inverseDeterminant;
2048 (*result)(3, 2) = -
Matrix3x3Determinant(m(0,0), m(1,0), m(3,0), m(0,1), m(1,1), m(3,1), m(0,2), m(1,2), m(3,2)) * inverseDeterminant;
2049 (*result)(0, 3) = -
Matrix3x3Determinant(m(0,1), m(1,1), m(2,1), m(0,2), m(1,2), m(2,2), m(0,3), m(1,3), m(2,3)) * inverseDeterminant;
2050 (*result)(1, 3) =
Matrix3x3Determinant (m(0,0), m(1,0), m(2,0), m(0,2), m(1,2), m(2,2), m(0,3), m(1,3), m(2,3)) * inverseDeterminant;
2051 (*result)(2, 3) = -
Matrix3x3Determinant(m(0,0), m(1,0), m(2,0), m(0,1), m(1,1), m(2,1), m(0,3), m(1,3), m(2,3)) * inverseDeterminant;
2052 (*result)(3, 3) =
Matrix3x3Determinant (m(0,0), m(1,0), m(2,0), m(0,1), m(1,1), m(2,1), m(0,2), m(1,2), m(2,2)) * inverseDeterminant;
2066 tb_error_if(result == input,
"tbExternalError: Invalid parameter, expected result to be different than input.");
2068 (*result)(0, 0) = (*input)(0, 0);
2069 (*result)(1, 1) = (*input)(1, 1);
2070 (*result)(2, 2) = (*input)(2, 2);
2072 (*result)(1, 0) = (*input)(0, 1);
2073 (*result)(2, 0) = (*input)(0, 2);
2074 (*result)(0, 1) = (*input)(1, 0);
2075 (*result)(2, 1) = (*input)(1, 2);
2076 (*result)(0, 2) = (*input)(2, 0);
2077 (*result)(1, 2) = (*input)(2, 1);
2099 tb_error_if(result == input,
"tbExternalError: Invalid parameter, expected result to be different than input.");
2101 (*result)(0, 0) = (*input)(0, 0);
2102 (*result)(1, 1) = (*input)(1, 1);
2103 (*result)(2, 2) = (*input)(2, 2);
2104 (*result)(3, 3) = (*input)(3, 3);
2106 (*result)(1, 0) = (*input)(0, 1);
2107 (*result)(2, 0) = (*input)(0, 2);
2108 (*result)(0, 1) = (*input)(1, 0);
2109 (*result)(2, 1) = (*input)(1, 2);
2110 (*result)(0, 2) = (*input)(2, 0);
2111 (*result)(1, 2) = (*input)(2, 1);
2127 (*result)(0, 3) = -((*input)(0, 3) * inversed(0, 0) + (*input)(1, 3) * inversed(0, 1) + (*input)(2, 3) * inversed(0, 2));
2128 (*result)(1, 3) = -((*input)(0, 3) * inversed(1, 0) + (*input)(1, 3) * inversed(1, 1) + (*input)(2, 3) * inversed(1, 2));
2129 (*result)(2, 3) = -((*input)(0, 3) * inversed(2, 0) + (*input)(1, 3) * inversed(2, 1) + (*input)(2, 3) * inversed(2, 2));
2131 (*result)(3, 0) = 0.0f;
2132 (*result)(3, 1) = 0.0f;
2133 (*result)(3, 2) = 0.0f;
2140 inline Matrix4 Translate(
const Matrix4& originalMatrix,
const Vector3& translation)
2142 Matrix4 outputMatrix(kSkipInitialization);
2143 Matrix4 translationMatrix(kSkipInitialization);
2146 MatrixMultiply(&outputMatrix, &translationMatrix, &originalMatrix);
2148 return outputMatrix;
2151 inline Matrix4 Translate(
const Matrix4& originalMatrix,
float x,
float y,
float z)
2159 inline Matrix4 TranslateLocal(
const Matrix4& originalMatrix,
const Vector3& translation)
2161 Matrix4 outputMatrix(kSkipInitialization);
2162 Matrix4 translationMatrix(kSkipInitialization);
2165 MatrixMultiply(&outputMatrix, &originalMatrix, &translationMatrix);
2167 return outputMatrix;
2170 inline Matrix4 TranslateLocal(
const Matrix4& originalMatrix,
float x,
float y,
float z)
2178 inline Matrix3 Rotate(
const Matrix3& originalMatrix,
const Vector3& aroundAxis,
const tbMath::Angle angle)
2180 Matrix3 outputMatrix(kSkipInitialization);
2181 Matrix3 rotationMatrix(kSkipInitialization);
2188 return outputMatrix;
2191 inline Matrix3 Rotate(
const size_t& axisIndex,
const Matrix3& originalMatrix,
const tbMath::Angle angle)
2193 return Rotate(originalMatrix, originalMatrix.GetBasis(axisIndex), angle);
2199 inline Matrix4 Rotate(
const Matrix4& originalMatrix,
const Vector3& aroundAxis,
const tbMath::Angle angle)
2201 Matrix4 outputMatrix(kSkipInitialization);
2202 Matrix4 rotationMatrix(kSkipInitialization);
2209 return outputMatrix;
2212 inline Matrix4 Rotate(
const size_t& axisIndex,
const Matrix4& originalMatrix,
const tbMath::Angle angle)
2214 return Rotate(originalMatrix, originalMatrix.GetBasis(axisIndex), angle);
2219 inline Matrix4 RotateWorldSpace(
const size_t& axisIndex,
const Matrix4& originalMatrix,
const tbMath::Angle angle)
2221 Matrix4 outputMatrix(kSkipInitialization);
2222 Matrix4 rotationMatrix(kSkipInitialization);
2229 const Matrix4 rotationTransposed(rotationMatrix.GetTransposed());
2230 MatrixMultiply(&outputMatrix, &originalMatrix, &rotationTransposed);
2232 return outputMatrix;
2235 inline Matrix3 Scale(
const Matrix3& originalMatrix,
const Vector3& scale)
2237 Matrix3 outputMatrix(kSkipInitialization);
2238 Matrix3 scalingMatrix(kSkipInitialization);
2243 return outputMatrix;
2246 inline Matrix3 Scale(
const Matrix3 originalMatrix,
float x,
float y,
float z)
2248 return Scale(originalMatrix, Vector3(x, y, z));
2251 inline Matrix4 Scale(
const Matrix4& originalMatrix,
const Vector3& scale)
2253 Matrix4 outputMatrix(kSkipInitialization);
2254 Matrix4 scalingMatrix(kSkipInitialization);
2259 return outputMatrix;
2262 inline Matrix4 Scale(
const Matrix4& originalMatrix,
float x,
float y,
float z)
2264 return Scale(originalMatrix, Vector3(x, y, z));
Matrix4 * MatrixCreateScale(Matrix4 *result, const float scaleX, const float scaleY, const float scaleZ)
Definition: tb_matrix.hpp:1290
Matrix3 * MatrixFastInverse(Matrix3 *result, const Matrix3 *input)
Definition: tb_matrix.hpp:2064
static Matrix4 Identity(void)
Definition: tb_matrix.hpp:546
AngleType< float > Angle
Definition: tb_angle.hpp:154
static Matrix3 Identity(void)
Definition: tb_matrix.hpp:129
const float & operator()(int column, int row) const
Definition: tb_matrix.hpp:343
Type AsRadians(void) const
Definition: tb_angle.hpp:79
Matrix4 * MatrixCreateTranslation(Matrix4 *result, const Vector3 *translation)
Definition: tb_matrix.hpp:1213
Vector3 * MatrixVector3Multiply(Vector3 *result, const Matrix3 *inputMatrix, const Vector3 *inputVector)
Definition: tb_matrix.hpp:1833
Contains objects and functions for dealing with Vector and Matrix math.
static Matrix4 Zero(void)
Definition: tb_matrix.hpp:533
Matrix4(void)
Definition: tb_matrix.hpp:638
Matrix3(float f11, float f21, float f31, float f12, float f22, float f32, float f13, float f23, float f33)
Definition: tb_matrix.hpp:218
float & operator[](const int &index)
Definition: tb_matrix.hpp:324
const float & operator()(const size_t &column, const size_t &row) const
Definition: tb_matrix.hpp:805
bool operator!=(const Matrix3 &other) const
Definition: tb_matrix.hpp:300
Matrix3 * MatrixCreateRotationZ(Matrix3 *result, const Angle rotation)
Definition: tb_matrix.hpp:1375
Definition: tb_vector.hpp:317
Definition: tb_matrix.hpp:111
Matrix3 * MatrixTranspose(Matrix3 *result, const Matrix3 *input)
Definition: tb_matrix.hpp:1670
Matrix4 * MatrixCreateRotationA(Matrix4 *result, const Vector3 *rotationAxis, const Angle rotation)
Definition: tb_matrix.hpp:1438
Matrix3 * MatrixCreateIdentity(Matrix3 *result)
Definition: tb_matrix.hpp:1150
Matrix3 * MatrixMultiply(Matrix3 *result, const Matrix3 *left, const Matrix3 *right)
Definition: tb_matrix.hpp:1711
bool IsZero(const Type &value)
Definition: tb_math.hpp:53
float & operator()(int column, int row)
Definition: tb_matrix.hpp:825
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.hpp:1956
Matrix3 * MatrixComputeInverse(Matrix3 *result, const Matrix3 *input)
Definition: tb_matrix.hpp:1987
bool operator!=(const Matrix4 &other) const
Definition: tb_matrix.hpp:775
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
Matrix3 * MatrixCreateRotationX(Matrix3 *result, const Angle rotation)
Definition: tb_matrix.hpp:1307
Matrix4(float f11, float f21, float f31, float f41, float f12, float f22, float f32, float f42, float f13, float f23, float f33, float f43, float f14, float f24, float f34, float f44, const ColumnMajorMatrix &columnMajor)
Definition: tb_matrix.hpp:669
#define tb_unused(parameter)
Definition: tb_defines.hpp:25
void SetPosition(const float x, const float y, const float z)
Definition: tb_matrix.hpp:899
Matrix4(float f11, float f21, float f31, float f41, float f12, float f22, float f32, float f42, float f13, float f23, float f33, float f43, float f14, float f24, float f34, float f44)
Definition: tb_matrix.hpp:650
Matrix4 * MatrixCreateRotationZ(Matrix4 *result, const Angle rotation)
Definition: tb_matrix.hpp:1390
Vector3 * Vector3Normalize(Vector3 *result, const Vector3 *input)
Definition: tb_vector.hpp:1341
Definition: tb_matrix.hpp:527
SkipInitialization
Definition: tb_vector.hpp:30
bool IsEqual(const Type &leftValue, const Type &rightValue)
Definition: tb_math.hpp:30
Matrix4 * MatrixCreateRotationY(Matrix4 *result, const Angle rotation)
Definition: tb_matrix.hpp:1356
float & operator[](const size_t &index)
Definition: tb_matrix.hpp:799
Matrix3(const Matrix3 &other)
Definition: tb_matrix.hpp:255
float & operator()(const size_t &column, const size_t &row)
Definition: tb_matrix.hpp:812
Vector4 * Vector4MatrixMultiply(Vector4 *result, const Vector4 *inputVector, const Matrix4 *inputMatrix)
Definition: tb_matrix.hpp:1894
Vector3 GetPosition(void) const
Definition: tb_matrix.hpp:879
const float & operator[](const int &index) const
Definition: tb_matrix.hpp:317
Matrix3(void)
Definition: tb_matrix.hpp:207
Matrix4 * MatrixCreateOrthoRH(Matrix4 *result, const float left, const float right, const float top, const float bottom, const float nearPlane, const float farPlane)
Definition: tb_matrix.hpp:1544
Matrix4 * MatrixCreateLookAt(Matrix4 *result, const Vector3 &eyePosition, const Vector3 &targetPosition, const Vector3 &unitUp)
Definition: tb_matrix.hpp:1174
Matrix4 * MatrixCreatePerspectiveLH(Matrix4 *result, const float fieldOfView, const float aspectRatio, const float nearPlane, const float farPlane)
Definition: tb_matrix.hpp:1512
Matrix4 * MatrixCreatePerspectiveRH(Matrix4 *result, const float fieldOfView, const float aspectRatio, const float nearPlane, const float farPlane)
Definition: tb_matrix.hpp:1483
bool operator==(const Matrix3 &other) const
Definition: tb_matrix.hpp:282
Vector3 * Vector3Subtract(Vector3 *result, const Vector3 *leftSide, const Vector3 *rightSide)
Definition: tb_vector.hpp:1015
Matrix4(const float *const componentArray)
Definition: tb_matrix.hpp:688
void SetBasis(const size_t &basisIndex, float basisX, float basisY, float basisZ)
Definition: tb_matrix.hpp:391
Matrix4(const float *const componentArray, const ColumnMajorMatrix &columnMajor)
Definition: tb_matrix.hpp:704
bool operator==(const Matrix4 &other) const
Definition: tb_matrix.hpp:757
Matrix4 * MatrixCreateOrthoLH(Matrix4 *result, const float left, const float right, const float top, const float bottom, const float nearPlane, const float farPlane)
Definition: tb_matrix.hpp:1576
Matrix4 * MatrixCreateRotationX(Matrix4 *result, const Angle rotation)
Definition: tb_matrix.hpp:1322
Matrix3 * MatrixCreateRotationA(Matrix3 *result, const Vector3 *rotationAxis, const Angle rotation)
Definition: tb_matrix.hpp:1410
Matrix4 & operator=(const Matrix4 &other)
Definition: tb_matrix.hpp:741
float Vector3DotProduct(const Vector3 *leftSide, const Vector3 *rightSide)
Definition: tb_vector.hpp:1204
void SetBasis(const size_t &basisIndex, const Vector3 &basis)
Definition: tb_matrix.hpp:381
const float & operator()(int column, int row) const
Definition: tb_matrix.hpp:818
static Matrix3 Zero(void)
Definition: tb_matrix.hpp:117
Matrix3(const SkipInitialization &fastAndStupid)
Definition: tb_matrix.hpp:247
Vector3 * Vector3CrossProduct(Vector3 *result, const Vector3 *leftSide, const Vector3 *rightSide)
Definition: tb_vector.hpp:1234
Matrix3 & operator=(const Matrix3 &other)
Definition: tb_matrix.hpp:266
float MatrixDeterminant(const Matrix3 *input)
Definition: tb_matrix.hpp:1965
float & operator()(const size_t &column, const size_t &row)
Definition: tb_matrix.hpp:337
Definition: tb_angle.hpp:34
Vector4 * MatrixVector4Multiply(Vector4 *result, const Matrix4 *inputMatrix, const Vector4 *inputVector)
Definition: tb_matrix.hpp:1873
Matrix3 * MatrixAdd(Matrix3 *result, const Matrix3 *leftSide, const Matrix3 *rightSide)
Definition: tb_matrix.hpp:1600
Vector3 * Vector3TransformNormal(Vector3 *result, const Vector3 *inputVector, const Matrix4 *inputMatrix)
Definition: tb_matrix.hpp:1936
Matrix3 * MatrixSubtract(Matrix3 *result, const Matrix3 *leftSide, const Matrix3 *rightSide)
Definition: tb_matrix.hpp:1636
const float & operator()(const size_t &column, const size_t &row) const
Definition: tb_matrix.hpp:330
Matrix3 * MatrixCreateScale(Matrix3 *result, const Vector3 *scale)
Definition: tb_matrix.hpp:1247
void SetBasis(const size_t &basisIndex, const Vector3 &basis)
Definition: tb_matrix.hpp:857
void SetBasis(const size_t &basisIndex, float basisX, float basisY, float basisZ)
Definition: tb_matrix.hpp:867
#define tb_error_if(errorTest, message,...)
Definition: tb_error.hpp:42
Matrix4(const Matrix4 &other)
Definition: tb_matrix.hpp:728
Vector3 GetBasis(const size_t &basisIndex) const
Definition: tb_matrix.hpp:849
Matrix4 * MatrixCreateTranslation(Matrix4 *result, const float translationX, const float translationY, const float translationZ)
Definition: tb_matrix.hpp:1231
float & operator()(int column, int row)
Definition: tb_matrix.hpp:350
const float & operator[](const size_t &index) const
Definition: tb_matrix.hpp:792
Vector3 * Vector3TransformCoordinate(Vector3 *result, const Vector3 *inputVector, const Matrix4 *inputMatrix)
Definition: tb_matrix.hpp:1914
void SetPosition(const Vector3 &position)
Definition: tb_matrix.hpp:888
float Vector3Magnitude(const Vector3 *input)
Definition: tb_vector.hpp:1264
Matrix3(const float *const componentArray)
Definition: tb_matrix.hpp:233
Definition: tb_vector.hpp:626
const Vector3 GetBasis(const size_t &basisIndex) const
Definition: tb_matrix.hpp:373
Vector3 * Vector3MatrixMultiply(Vector3 *result, const Vector3 *inputVector, const Matrix3 *inputMatrix)
Definition: tb_matrix.hpp:1853
Matrix4(const SkipInitialization &fastAndStupid)
Definition: tb_matrix.hpp:720
Matrix3 * MatrixCreateRotationY(Matrix3 *result, const Angle rotation)
Definition: tb_matrix.hpp:1341