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>
16 #include <turtle_brains/core/tb_string.hpp>
97 enum ColumnMajorMatrix
103 template<
typename Type>
class TypedVector3;
104 template<
typename Type>
class TypedVector4;
105 template<
typename Type>
class TypedMatrix3;
106 template<
typename Type>
class TypedMatrix4;
107 template<
typename Type>
class TypedQuaternion;
109 typedef TypedMatrix3<float> Matrix3;
110 typedef TypedMatrix4<float> Matrix4;
115 const TypedVector3<Type>* inputVector,
const TypedMatrix3<Type>* inputMatrix);
118 const TypedMatrix3<Type>* inputMatrix,
const TypedVector3<Type>* inputVector);
120 template<
typename Type> TypedMatrix3<Type>*
MatrixMultiply(TypedMatrix3<Type>* result,
const TypedMatrix3<Type>* input,
const Type& scalar);
121 template<
typename Type> TypedMatrix4<Type>*
MatrixMultiply(TypedMatrix4<Type>* result,
const TypedMatrix4<Type>* input,
const Type& scalar);
122 template<
typename Type> TypedMatrix3<Type>*
MatrixMultiply(TypedMatrix3<Type>* result,
const TypedMatrix3<Type>* leftSide,
const TypedMatrix3<Type>* rightSide);
123 template<
typename Type> TypedMatrix4<Type>*
MatrixMultiply(TypedMatrix4<Type>* result,
const TypedMatrix4<Type>* leftSide,
const TypedMatrix4<Type>* rightSide);
125 template<
typename Type> TypedVector4<Type>*
MatrixVector4Multiply(TypedVector4<Type>* result,
const TypedMatrix4<Type>* inputMatrix,
const TypedVector4<Type>* inputVector);
126 template<
typename Type> TypedVector4<Type>*
Vector4MatrixMultiply(TypedVector4<Type>* result,
const TypedVector4<Type>* inputVector,
const TypedMatrix4<Type>* inputMatrix);
127 template<
typename Type> TypedVector3<Type>*
Vector3TransformCoordinate(TypedVector3<Type>* result,
const TypedVector3<Type>* inputVector,
const TypedMatrix4<Type>* inputMatrix);
128 template<
typename Type> TypedVector3<Type>*
Vector3TransformNormal(TypedVector3<Type>* result,
const TypedVector3<Type>* inputVector,
const TypedMatrix4<Type>* inputMatrix);
129 template<
typename Type> TypedMatrix3<Type>*
MatrixComputeInverse(TypedMatrix3<Type>* result,
const TypedMatrix3<Type>* input);
130 template<
typename Type> TypedMatrix4<Type>*
MatrixComputeInverse(TypedMatrix4<Type>* result,
const TypedMatrix4<Type>* input);
131 template<
typename Type> TypedMatrix3<Type>*
MatrixFastInverse(TypedMatrix3<Type>* result,
const TypedMatrix3<Type>* input);
132 template<
typename Type> TypedMatrix4<Type>*
MatrixFastInverse(TypedMatrix4<Type>* result,
const TypedMatrix4<Type>* input);
134 template<
typename Type> TypedMatrix4<Type>*
MatrixCreateTranslation(TypedMatrix4<Type>* result,
const TypedVector3<Type>* translation);
135 template<
typename Type> TypedMatrix4<Type>*
MatrixCreateTranslation(TypedMatrix4<Type>* result,
const Type translationX,
const Type translationY,
const Type translationZ);
136 template<
typename Type> TypedMatrix3<Type>*
MatrixCreateScale(TypedMatrix3<Type>* result,
const TypedVector3<Type>* scale);
137 template<
typename Type> TypedMatrix4<Type>*
MatrixCreateScale(TypedMatrix4<Type>* result,
const TypedVector3<Type>* scale);
138 template<
typename Type> TypedMatrix3<Type>*
MatrixCreateScale(TypedMatrix3<Type>* result,
const Type scaleX,
const Type scaleY,
const Type scaleZ);
139 template<
typename Type> TypedMatrix4<Type>*
MatrixCreateScale(TypedMatrix4<Type>* result,
const Type scaleX,
const Type scaleY,
const Type scaleZ);
140 template<
typename Type> TypedMatrix3<Type>*
MatrixCreateRotationX(TypedMatrix3<Type>* result,
const TypedAngle<Type> rotation);
141 template<
typename Type> TypedMatrix4<Type>*
MatrixCreateRotationX(TypedMatrix4<Type>* result,
const TypedAngle<Type> rotation);
142 template<
typename Type> TypedMatrix3<Type>*
MatrixCreateRotationY(TypedMatrix3<Type>* result,
const TypedAngle<Type> rotation);
143 template<
typename Type> TypedMatrix4<Type>*
MatrixCreateRotationY(TypedMatrix4<Type>* result,
const TypedAngle<Type> rotation);
144 template<
typename Type> TypedMatrix3<Type>*
MatrixCreateRotationZ(TypedMatrix3<Type>* result,
const TypedAngle<Type> rotation);
145 template<
typename Type> TypedMatrix4<Type>*
MatrixCreateRotationZ(TypedMatrix4<Type>* result,
const TypedAngle<Type> rotation);
146 template<
typename Type> TypedMatrix3<Type>*
MatrixCreateRotationA(TypedMatrix3<Type>* result,
const TypedVector3<Type>* rotationAxis,
const TypedAngle<Type> rotation);
147 template<
typename Type> TypedMatrix4<Type>*
MatrixCreateRotationA(TypedMatrix4<Type>* result,
const TypedVector3<Type>* rotationAxis,
const TypedAngle<Type> rotation);
164 Type(0), Type(0), Type(0),
165 Type(0), Type(0), Type(0),
166 Type(0), Type(0), Type(0));
176 Type(1), Type(0), Type(0),
177 Type(0), Type(1), Type(0),
178 Type(0), Type(0), Type(1));
188 static TypedMatrix3 Scale(
const float scaleX,
const float scaleY,
const float scaleZ)
191 tbMath::MatrixCreateScale(&matrix, scaleX, scaleY, scaleZ);
195 static TypedMatrix3 RotationX(
const TypedAngle<Type>& rotation)
198 tbMath::MatrixCreateRotationX(&matrix, rotation);
202 static TypedMatrix3 RotationY(
const TypedAngle<Type>& rotation)
209 static TypedMatrix3 RotationZ(
const TypedAngle<Type>& rotation)
219 MatrixCreateRotationA<Type>(&matrix, &rotationAxis, rotation);
224 static TypedMatrix3 FromQuaternion(
const TypedQuaternion<Type>& quaternion);
230 #if defined(tb_visual_cpp)
231 #pragma warning(push)
232 #pragma warning(disable: 4201)
234 Type m_f11; Type m_f21; Type m_f31;
235 Type m_f12; Type m_f22; Type m_f32;
236 Type m_f13; Type m_f23; Type m_f33;
241 Type m_f11; Type m_f21; Type m_f31;
242 Type m_f12; Type m_f22; Type m_f32;
243 Type m_f13; Type m_f23; Type m_f33;
253 Type(1), Type(0), Type(0),
254 Type(0), Type(1), Type(0),
255 Type(0), Type(0), Type(1) }
263 Type f12, Type f22, Type f32,
264 Type f13, Type f23, Type f33) :
279 componentArray[0], componentArray[1], componentArray[2],
280 componentArray[3], componentArray[4], componentArray[5],
281 componentArray[6], componentArray[7], componentArray[8] }
291 #if defined(tb_visual_cpp)
292 #pragma warning(push)
293 #pragma warning(disable: 26495)
313 static_cast<Type>(other.mComponents[0]), static_cast<Type>(other.mComponents[1]), static_cast<Type>(other.mComponents[2]),
314 static_cast<Type>(other.mComponents[3]), static_cast<Type>(other.mComponents[4]), static_cast<Type>(other.mComponents[5]),
315 static_cast<Type>(other.mComponents[6]), static_cast<Type>(other.mComponents[7]), static_cast<Type>(other.mComponents[8])
339 for (
size_t index(0); index < 9; ++index)
341 if (
false ==
IsEqual(mComponents[index], other[index]))
357 for (
size_t index(0); index < 9; ++index)
359 if (
false ==
IsEqual(mComponents[index], other[index]))
372 inline const Type&
operator[](
const int& index)
const {
return mComponents[index]; }
373 inline const Type&
operator[](
const std::size_t& index)
const {
return mComponents[index]; }
380 inline Type&
operator[](
const int& index) {
return mComponents[index]; }
381 inline Type&
operator[](
const std::size_t& index) {
return mComponents[index]; }
387 inline const Type&
operator()(
const size_t& column,
const size_t& row)
const {
return mComponents[column + (row * 3)]; }
394 inline Type&
operator()(
const size_t& column,
const size_t& row) {
return mComponents[column + (row * 3)]; }
400 inline const Type&
operator()(
int column,
int row)
const {
return mComponents[column + (row * 3)]; }
407 inline Type&
operator()(
int column,
int row) {
return mComponents[column + (row * 3)]; }
416 inline explicit operator Type* (void) {
return mComponents; }
421 inline explicit operator const Type* (void)
const {
return mComponents; }
429 static_cast<ToType
>(m_f11),
static_cast<ToType
>(m_f21),
static_cast<ToType
>(m_f31),
430 static_cast<ToType
>(m_f12),
static_cast<ToType
>(m_f22),
static_cast<ToType
>(m_f32),
431 static_cast<ToType
>(m_f13),
static_cast<ToType
>(m_f23),
static_cast<ToType
>(m_f33));
459 inline void SetBasis(
const size_t& basisIndex, Type basisX, Type basisY, Type basisZ)
461 mComponents[(basisIndex * 3) + 0] = basisX;
462 mComponents[(basisIndex * 3) + 1] = basisY;
463 mComponents[(basisIndex * 3) + 2] = basisZ;
473 #if defined(tb_with_math_operators)
481 leftSide(0, 0) + rightSide(0, 0), leftSide(1, 0) + rightSide(1, 0), leftSide(2, 0) + rightSide(2, 0),
482 leftSide(0, 1) + rightSide(0, 1), leftSide(1, 1) + rightSide(1, 1), leftSide(2, 1) + rightSide(2, 1),
483 leftSide(0, 2) + rightSide(0, 2), leftSide(1, 2) + rightSide(1, 2), leftSide(2, 2) + rightSide(2, 2));
492 for (
size_t index = 0; index < 9; ++index)
494 (*this)[index] += rightSide[index];
506 leftSide(0, 0) - rightSide(0, 0), leftSide(1, 0) - rightSide(1, 0), leftSide(2, 0) - rightSide(2, 0),
507 leftSide(0, 1) - rightSide(0, 1), leftSide(1, 1) - rightSide(1, 1), leftSide(2, 1) - rightSide(2, 1),
508 leftSide(0, 2) - rightSide(0, 2), leftSide(1, 2) - rightSide(1, 2), leftSide(2, 2) - rightSide(2, 2));
516 for (
size_t index = 0; index < 9; ++index)
518 (*this)[index] -= rightSide[index];
551 self(0, 0),
self(0, 1),
self(0, 2),
552 self(1, 0),
self(1, 1),
self(1, 2),
553 self(2, 0),
self(2, 1),
self(2, 2));
604 Type(0), Type(0), Type(0), Type(0),
605 Type(0), Type(0), Type(0), Type(0),
606 Type(0), Type(0), Type(0), Type(0),
607 Type(0), Type(0), Type(0), Type(0));
617 Type(1), Type(0), Type(0), Type(0),
618 Type(0), Type(1), Type(0), Type(0),
619 Type(0), Type(0), Type(1), Type(0),
620 Type(0), Type(0), Type(0), Type(1));
631 static TypedMatrix4 Translation(
const Type translationX,
const Type translationY,
const Type translationZ)
638 static TypedMatrix4 Scale(
const TypedVector3<Type>& scale)
645 static TypedMatrix4 Scale(
const Type scaleX,
const Type scaleY,
const Type scaleZ)
676 MatrixCreateRotationA<Type>(&matrix, &rotationAxis, rotation);
680 static TypedMatrix4 FromTransform(
const TypedVector3<Type>& position,
const TypedMatrix3<Type>& orientation,
const TypedVector3<Type>& scale)
683 matrix.Compose(position, orientation, scale);
694 Type mComponents[16];
696 #if defined(tb_visual_cpp)
697 #pragma warning(push)
698 #pragma warning(disable: 4201)
701 Type xx; Type xy; Type xz; Type hx;
702 Type yx; Type yy; Type yz; Type hy;
703 Type zx; Type zy; Type zz; Type hz;
704 Type tx; Type ty; Type tz; Type ht;
706 #if defined(tb_visual_cpp)
716 Type(1), Type(0), Type(0), Type(0),
717 Type(0), Type(1), Type(0), Type(0),
718 Type(0), Type(0), Type(1), Type(0),
719 Type(0), Type(0), Type(0), Type(1) }
727 Type f11, Type f21, Type f31, Type f41,
728 Type f12, Type f22, Type f32, Type f42,
729 Type f13, Type f23, Type f33, Type f43,
730 Type f14, Type f24, Type f34, Type f44) :
746 Type f11, Type f21, Type f31, Type f41,
747 Type f12, Type f22, Type f32, Type f42,
748 Type f13, Type f23, Type f33, Type f43,
749 Type f14, Type f24, Type f34, Type f44,
const ColumnMajorMatrix& columnMajor) :
766 componentArray[0], componentArray[1], componentArray[2], componentArray[3],
767 componentArray[4], componentArray[5], componentArray[6], componentArray[7],
768 componentArray[8], componentArray[9], componentArray[10], componentArray[11],
769 componentArray[12], componentArray[13], componentArray[14], componentArray[15] }
780 inline explicit TypedMatrix4(
const Type*
const componentArray,
const ColumnMajorMatrix& columnMajor) :
782 componentArray[0], componentArray[4], componentArray[8], componentArray[12],
783 componentArray[1], componentArray[5], componentArray[9], componentArray[13],
784 componentArray[2], componentArray[6], componentArray[10], componentArray[14],
785 componentArray[3], componentArray[7], componentArray[11], componentArray[15] }
796 #if defined(tb_visual_cpp)
797 #pragma warning(push)
798 #pragma warning(disable: 26495)
818 static_cast<Type>(other.mComponents[0]), static_cast<Type>(other.mComponents[1]), static_cast<Type>(other.mComponents[2]), static_cast<Type>(other.mComponents[3]),
819 static_cast<Type>(other.mComponents[4]), static_cast<Type>(other.mComponents[5]), static_cast<Type>(other.mComponents[6]), static_cast<Type>(other.mComponents[7]),
820 static_cast<Type>(other.mComponents[8]), static_cast<Type>(other.mComponents[9]), static_cast<Type>(other.mComponents[10]), static_cast<Type>(other.mComponents[11]),
821 static_cast<Type>(other.mComponents[12]), static_cast<Type>(other.mComponents[13]), static_cast<Type>(other.mComponents[14]), static_cast<Type>(other.mComponents[15])
845 for (
size_t index(0); index < 16; ++index)
847 if (
false ==
IsEqual(mComponents[index], other[index]))
863 for (
size_t index(0); index < 16; ++index)
865 if (
false ==
IsEqual(mComponents[index], other[index]))
878 inline const Type&
operator[](
const int index)
const {
return mComponents[index]; }
879 inline const Type&
operator[](
const size_t& index)
const {
return mComponents[index]; }
886 inline Type&
operator[](
const int index) {
return mComponents[index]; }
887 inline Type&
operator[](
const size_t& index) {
return mComponents[index]; }
893 inline const Type&
operator()(
const size_t& column,
const size_t& row)
const {
return mComponents[column + (row << 2)]; }
900 inline Type&
operator()(
const size_t& column,
const size_t& row) {
return mComponents[column + (row << 2)]; }
906 inline const Type&
operator()(
int column,
int row)
const {
return mComponents[column + (row << 2)]; }
913 inline Type&
operator()(
int column,
int row) {
return mComponents[column + (row << 2)]; }
922 inline explicit operator Type* (void) {
return mComponents; }
927 inline explicit operator const Type* (void)
const {
return mComponents; }
935 static_cast<ToType
>(mComponents[0]),
static_cast<ToType
>(mComponents[1]),
static_cast<ToType
>(mComponents[2]),
static_cast<ToType
>(mComponents[3]),
936 static_cast<ToType
>(mComponents[4]),
static_cast<ToType
>(mComponents[5]),
static_cast<ToType
>(mComponents[6]),
static_cast<ToType
>(mComponents[7]),
937 static_cast<ToType
>(mComponents[8]),
static_cast<ToType
>(mComponents[9]),
static_cast<ToType
>(mComponents[10]),
static_cast<ToType
>(mComponents[11]),
938 static_cast<ToType
>(mComponents[12]),
static_cast<ToType
>(mComponents[13]),
static_cast<ToType
>(mComponents[14]),
static_cast<ToType
>(mComponents[15]));
966 inline void SetBasis(
const size_t& basisIndex, Type basisX, Type basisY, Type basisZ)
968 mComponents[(basisIndex << 2) + 0] = basisX;
969 mComponents[(basisIndex << 2) + 1] = basisY;
970 mComponents[(basisIndex << 2) + 2] = basisZ;
989 (*this)(0, 3) = position.x;
990 (*
this)(1, 3) = position.y;
991 (*
this)(2, 3) = position.z;
1035 inline void SetScale(
const TypedVector3<Type>& scale)
1044 void Compose(
const TypedVector3<Type>& position,
const TypedMatrix3<Type>& orientation,
const TypedVector3<Type>& scale)
1048 SetBasis(0, orientation.GetBasis(0) * scale.x);
1049 SetBasis(1, orientation.GetBasis(1) * scale.y);
1050 SetBasis(2, orientation.GetBasis(2) * scale.z);
1053 void Decompose(TypedVector3<Type>& position, TypedMatrix3<Type>& orientation, TypedVector3<Type>& scale)
const
1057 orientation.SetBasis(0,
GetBasis(0).GetNormalized(scale.x));
1058 orientation.SetBasis(1,
GetBasis(1).GetNormalized(scale.y));
1059 orientation.SetBasis(2,
GetBasis(2).GetNormalized(scale.z));
1062 #if defined(tb_with_math_operators)
1066 inline TypedMatrix4<Type> operator+(
const TypedMatrix4<Type>& rightSide)
const
1070 leftSide(0, 0) + rightSide(0, 0), leftSide(1, 0) + rightSide(1, 0), leftSide(2, 0) + rightSide(2, 0), leftSide(3, 0) + rightSide(3, 0),
1071 leftSide(0, 1) + rightSide(0, 1), leftSide(1, 1) + rightSide(1, 1), leftSide(2, 1) + rightSide(2, 1), leftSide(3, 1) + rightSide(3, 1),
1072 leftSide(0, 2) + rightSide(0, 2), leftSide(1, 2) + rightSide(1, 2), leftSide(2, 2) + rightSide(2, 2), leftSide(3, 2) + rightSide(3, 2),
1073 leftSide(0, 3) + rightSide(0, 3), leftSide(1, 3) + rightSide(1, 3), leftSide(2, 3) + rightSide(2, 3), leftSide(3, 3) + rightSide(3, 3));
1080 inline TypedMatrix4<Type>& operator+=(
const TypedMatrix4<Type>& rightSide)
1082 for (
size_t index = 0; index < 16; ++index)
1084 (*this)[index] += rightSide[index];
1092 inline TypedMatrix4<Type> operator-(
const TypedMatrix4<Type>& rightSide)
const
1094 const TypedMatrix4<Type>& leftSide(*
this);
1095 return TypedMatrix4<Type>(
1096 leftSide(0, 0) - rightSide(0, 0), leftSide(1, 0) - rightSide(1, 0), leftSide(2, 0) - rightSide(2, 0), leftSide(3, 0) - rightSide(3, 0),
1097 leftSide(0, 1) - rightSide(0, 1), leftSide(1, 1) - rightSide(1, 1), leftSide(2, 1) - rightSide(2, 1), leftSide(3, 1) - rightSide(3, 1),
1098 leftSide(0, 2) - rightSide(0, 2), leftSide(1, 2) - rightSide(1, 2), leftSide(2, 2) - rightSide(2, 2), leftSide(3, 2) - rightSide(3, 2),
1099 leftSide(0, 3) - rightSide(0, 3), leftSide(1, 3) - rightSide(1, 3), leftSide(2, 3) - rightSide(2, 3), leftSide(3, 3) - rightSide(3, 3));
1105 inline TypedMatrix4<Type>& operator-=(
const TypedMatrix4<Type>& rightSide)
1107 for (
size_t index = 0; index < 16; ++index)
1109 (*this)[index] -= rightSide[index];
1120 MatrixMultiply<Type>(&result,
this, &rightSide);
1141 temp(0, 0) =
self(0, 0); temp(0, 1) =
self(1, 0); temp(0, 2) =
self(2, 0); temp(0, 3) =
self(3, 0);
1142 temp(1, 0) =
self(0, 1); temp(1, 1) =
self(1, 1); temp(1, 2) =
self(2, 1); temp(1, 3) =
self(3, 1);
1143 temp(2, 0) =
self(0, 2); temp(2, 1) =
self(1, 2); temp(2, 2) =
self(2, 2); temp(2, 3) =
self(3, 2);
1144 temp(3, 0) =
self(0, 3); temp(3, 1) =
self(1, 3); temp(3, 2) =
self(2, 3); temp(3, 3) =
self(3, 3);
1177 inline TypedVector3<Type> TransformCoordinate(
const TypedVector3<Type>& inputVector)
const
1179 TypedVector3<Type> result;
1188 inline TypedVector3<Type> TransformNormal(
const TypedVector3<Type>& inputVector)
const
1190 TypedVector3<Type> result;
1198 inline TypedVector4<Type> Transform(
const TypedVector4<Type>& inputVector)
const
1200 TypedVector4<Type> result;
1208 #if defined(tb_with_math_operators)
1213 template<
typename Type> TypedMatrix3<Type> operator*(
const Type leftSide,
const TypedMatrix3<Type>& rightSide)
1215 TypedMatrix3<Type> result;
1223 template<
typename Type> TypedMatrix3<Type> operator*(
const TypedMatrix3<Type>& leftSide,
const Type rightSide)
1225 TypedMatrix3<Type> result;
1233 template<
typename Type> TypedMatrix4<Type> operator*(
const Type leftSide,
const TypedMatrix4<Type>& rightSide)
1235 TypedMatrix4<Type> result;
1243 template<
typename Type> TypedMatrix4<Type> operator*(
const TypedMatrix4<Type>& leftSide,
const Type rightSide)
1245 TypedMatrix4<Type> result;
1254 template<
typename Type> TypedVector3<Type> operator*(
const TypedVector3<Type>& leftSide,
const TypedMatrix3<Type>& rightSide)
1256 TypedVector3<Type> result;
1265 template<
typename Type> TypedVector3<Type> operator*(
const TypedMatrix3<Type>& leftSide,
const TypedVector3<Type>& rightSide)
1267 TypedVector3<Type> result;
1276 template<
typename Type> TypedVector4<Type> operator*(
const TypedVector4<Type>& leftSide,
const TypedMatrix4<Type>& rightSide)
1278 TypedVector4<Type> result;
1287 template<
typename Type> TypedVector4<Type> operator*(
const TypedMatrix4<Type>& leftSide,
const TypedVector4<Type>& rightSide)
1289 TypedVector4<Type> result;
1332 tb_error_if(
nullptr == result,
"tbExternalError: Invalid parameter; Expected result to be valid pointer.");
1338 #if defined(tb_debug_build)
1339 tb_error_if(eyePosition == targetPosition,
"tbExternalError: Invalid parameter; This would result in looking directly at eye position.");
1340 tb_error_if(fabsf(
Vector3Magnitude(&unitUp) - 1.0f) > 0.00001f,
"tbExternalError: Invalid unitUp, this is not a unit length vector.");
1352 result->
SetBasis(0, right.x, finalUp.x, forward.x);
1353 result->
SetBasis(1, right.y, finalUp.y, forward.y);
1354 result->
SetBasis(2, right.z, finalUp.z, forward.z);
1356 (*result)(0, 3) = -(eyePosition.x * (*result)(0, 0) + eyePosition.y * (*result)(0, 1) + eyePosition.z * (*result)(0, 2));
1357 (*result)(1, 3) = -(eyePosition.x * (*result)(1, 0) + eyePosition.y * (*result)(1, 1) + eyePosition.z * (*result)(1, 2));
1358 (*result)(2, 3) = -(eyePosition.x * (*result)(2, 0) + eyePosition.y * (*result)(2, 1) + eyePosition.z * (*result)(2, 2));
1372 (*result)(0, 3) = translation->x;
1373 (*result)(1, 3) = translation->y;
1374 (*result)(2, 3) = translation->z;
1388 const Type translationX,
const Type translationY,
const Type translationZ)
1391 (*result)(0, 3) = translationX;
1392 (*result)(1, 3) = translationY;
1393 (*result)(2, 3) = translationZ;
1406 memset(result->mComponents, 0,
sizeof(Type) * 9);
1407 (*result)(0, 0) = scale->x;
1408 (*result)(1, 1) = scale->y;
1409 (*result)(2, 2) = scale->z;
1418 memset(result->mComponents, 0,
sizeof(Type) << 4);
1419 (*result)(0, 0) = scale->x;
1420 (*result)(1, 1) = scale->y;
1421 (*result)(2, 2) = scale->z;
1422 (*result)(3, 3) = 1.0f;
1436 const Type scaleX,
const Type scaleY,
const Type scaleZ)
1438 memset(result->mComponents, 0,
sizeof(Type) * 9);
1439 (*result)(0, 0) = scaleX;
1440 (*result)(1, 1) = scaleY;
1441 (*result)(2, 2) = scaleZ;
1449 const Type scaleX,
const Type scaleY,
const Type scaleZ)
1451 memset(result->mComponents, 0,
sizeof(Type) << 4);
1452 (*result)(0, 0) = scaleX;
1453 (*result)(1, 1) = scaleY;
1454 (*result)(2, 2) = scaleZ;
1455 (*result)(3, 3) = 1.0f;
1469 const Type sinOfRotation = std::sin(rotation.
AsRadians());
1470 const Type cosOfRotation = std::cos(rotation.
AsRadians());
1471 (*result)(1, 1) = cosOfRotation;
1472 (*result)(2, 1) = sinOfRotation;
1473 (*result)(1, 2) = -sinOfRotation;
1474 (*result)(2, 2) = cosOfRotation;
1484 const Type sinOfRotation = std::sin(rotation.
AsRadians());
1485 const Type cosOfRotation = std::cos(rotation.
AsRadians());
1486 (*result)(1, 1) = cosOfRotation;
1487 (*result)(2, 1) = sinOfRotation;
1488 (*result)(1, 2) = -sinOfRotation;
1489 (*result)(2, 2) = cosOfRotation;
1503 const Type sinOfRotation = std::sin(rotation.
AsRadians());
1504 const Type cosOfRotation = std::cos(rotation.
AsRadians());
1505 (*result)(0, 0) = cosOfRotation;
1506 (*result)(2, 0) = -sinOfRotation;
1507 (*result)(0, 2) = sinOfRotation;
1508 (*result)(2, 2) = cosOfRotation;
1518 const Type sinOfRotation = std::sin(rotation.
AsRadians());
1519 const Type cosOfRotation = std::cos(rotation.
AsRadians());
1520 (*result)(0, 0) = cosOfRotation;
1521 (*result)(2, 0) = -sinOfRotation;
1522 (*result)(0, 2) = sinOfRotation;
1523 (*result)(2, 2) = cosOfRotation;
1537 const Type sinOfRotation = std::sin(rotation.
AsRadians());
1538 const Type cosOfRotation = std::cos(rotation.
AsRadians());
1539 (*result)(0, 0) = cosOfRotation;
1540 (*result)(1, 0) = sinOfRotation;
1541 (*result)(0, 1) = -sinOfRotation;
1542 (*result)(1, 1) = cosOfRotation;
1552 const Type sinOfRotation = std::sin(rotation.
AsRadians());
1553 const Type cosOfRotation = std::cos(rotation.
AsRadians());
1554 (*result)(0, 0) = cosOfRotation;
1555 (*result)(1, 0) = sinOfRotation;
1556 (*result)(0, 1) = -sinOfRotation;
1557 (*result)(1, 1) = cosOfRotation;
1572 const Type s = -std::sin(rotation.
AsRadians());
1573 const Type c = std::cos(rotation.
AsRadians());
1574 const Type t = 1.0f - c;
1576 const auto av = rotationAxis->GetNormalized();
1580 (*result)(0, 0) = c + tv.x * av.x;
1581 (*result)(0, 1) = tv.x * av.y + sv.z;
1582 (*result)(0, 2) = tv.x * av.z - sv.y;
1584 (*result)(1, 0) = tv.y * av.x - sv.z;
1585 (*result)(1, 1) = c + tv.y * av.y;
1586 (*result)(1, 2) = tv.y * av.z + sv.x;
1588 (*result)(2, 0) = tv.z * av.x + sv.y;
1589 (*result)(2, 1) = tv.z * av.y - sv.x;
1590 (*result)(2, 2) = c + tv.z * av.z;
1601 const Type s = -std::sin(rotation.
AsRadians());
1602 const Type c = std::cos(rotation.
AsRadians());
1603 const Type t = 1.0f - c;
1605 const auto av = rotationAxis->GetNormalized();
1609 (*result)(0, 0) = c + tv.x * av.x;
1610 (*result)(0, 1) = tv.x * av.y + sv.z;
1611 (*result)(0, 2) = tv.x * av.z - sv.y;
1612 (*result)(0, 3) = 0.0f;
1614 (*result)(1, 0) = tv.y * av.x - sv.z;
1615 (*result)(1, 1) = c + tv.y * av.y;
1616 (*result)(1, 2) = tv.y * av.z + sv.x;
1617 (*result)(1, 3) = 0.0f;
1619 (*result)(2, 0) = tv.z * av.x + sv.y;
1620 (*result)(2, 1) = tv.z * av.y - sv.x;
1621 (*result)(2, 2) = c + tv.z * av.z;
1622 (*result)(2, 3) = 0.0f;
1624 (*result)(3, 0) = 0.0f;
1625 (*result)(3, 1) = 0.0f;
1626 (*result)(3, 2) = 0.0f;
1627 (*result)(3, 3) = 1.0f;
1645 const float nearPlane,
const float farPlane)
1647 memset(result->mComponents, 0,
sizeof(
float) << 4);
1651 const float t = tan(fieldOfView / 2.0f);
1652 (*result)(0, 0) = 1.0f / (aspectRatio * t);
1653 (*result)(1, 1) = 1.0f / t;
1654 (*result)(2, 2) = -(farPlane + nearPlane) / (farPlane - nearPlane);
1655 (*result)(3, 2) = -1.0f;
1656 (*result)(2, 3) = -(2.0f * farPlane * nearPlane) / (farPlane - nearPlane);
1674 const float nearPlane,
const float farPlane)
1676 memset(result->mComponents, 0,
sizeof(
float) << 4);
1680 const float t = tan(fieldOfView / 2.0f);
1681 (*result)(0, 0) = 1.0f / (aspectRatio * t);
1682 (*result)(1, 1) = 1.0f / t;
1683 (*result)(2, 2) = (farPlane + nearPlane) / (farPlane - nearPlane);
1684 (*result)(3, 2) = 1.0f;
1685 (*result)(2, 3) = -(2.0f * farPlane * nearPlane) / (farPlane - nearPlane);
1706 const float top,
const float bottom,
const float nearPlane,
const float farPlane)
1709 memset(result->mComponents, 0,
sizeof(
float) << 4);
1711 output(0, 0) = 2.0f / (right - left);
1712 output(1, 1) = 2.0f / (top - bottom);
1713 output(2, 2) = -2.0f / (farPlane - nearPlane);
1714 output(3, 3) = 1.0f;
1715 output(0, 3) = -(right + left) / (right - left);
1716 output(1, 3) = -(top + bottom) / (top - bottom);
1717 output(2, 3) = -((farPlane + nearPlane) / (farPlane - nearPlane));
1738 const float top,
const float bottom,
const float nearPlane,
const float farPlane)
1741 memset(result->mComponents, 0,
sizeof(
float) << 4);
1743 output(0, 0) = 2.0f / (right - left);
1744 output(1, 1) = 2.0f / (top - bottom);
1745 output(2, 2) = 2.0f / (farPlane - nearPlane);
1746 output(3, 3) = 1.0f;
1747 output(0, 3) = -(right + left) / (right - left);
1748 output(1, 3) = -(top + bottom) / (top - bottom);
1749 output(2, 3) = -(farPlane + nearPlane) / (farPlane - nearPlane);
1763 float *r = result->mComponents;
1764 const float *m1 = leftSide->mComponents;
1765 const float *m2 = rightSide->mComponents;
1767 r[0] = m1[0] + m2[0]; r[1] = m1[1] + m2[1]; r[2] = m1[2] + m2[2];
1768 r[3] = m1[3] + m2[3]; r[4] = m1[4] + m2[4]; r[5] = m1[5] + m2[5];
1769 r[6] = m1[6] + m2[6]; r[7] = m1[7] + m2[7]; r[8] = m1[8] + m2[8];
1778 float *r = result->mComponents;
1779 const float *m1 = leftSide->mComponents;
1780 const float *m2 = rightSide->mComponents;
1782 r[0] = m1[0] + m2[0]; r[1] = m1[1] + m2[1]; r[2] = m1[2] + m2[2]; r[3] = m1[3] + m2[3];
1783 r[4] = m1[4] + m2[4]; r[5] = m1[5] + m2[5]; r[6] = m1[6] + m2[6]; r[7] = m1[7] + m2[7];
1784 r[8] = m1[8] + m2[8]; r[9] = m1[9] + m2[9]; r[10] = m1[10] + m2[10]; r[11] = m1[11] + m2[11];
1785 r[12] = m1[12] + m2[12]; r[13] = m1[13] + m2[13]; r[14] = m1[14] + m2[14]; r[15] = m1[15] + m2[15];
1799 float *r = result->mComponents;
1800 const float *m1 = leftSide->mComponents;
1801 const float *m2 = rightSide->mComponents;
1803 r[0] = m1[0] - m2[0]; r[1] = m1[1] - m2[1]; r[2] = m1[2] - m2[2];
1804 r[3] = m1[3] - m2[3]; r[4] = m1[4] - m2[4]; r[5] = m1[5] - m2[5];
1805 r[6] = m1[6] - m2[6]; r[7] = m1[7] - m2[7]; r[8] = m1[8] - m2[8];
1814 float *r = result->mComponents;
1815 const float *m1 = leftSide->mComponents;
1816 const float *m2 = rightSide->mComponents;
1818 r[0] = m1[0] - m2[0]; r[1] = m1[1] - m2[1]; r[2] = m1[2] - m2[2]; r[3] = m1[3] - m2[3];
1819 r[4] = m1[4] - m2[4]; r[5] = m1[5] - m2[5]; r[6] = m1[6] - m2[6]; r[7] = m1[7] - m2[7];
1820 r[8] = m1[8] - m2[8]; r[9] = m1[9] - m2[9]; r[10] = m1[10] - m2[10]; r[11] = m1[11] - m2[11];
1821 r[12] = m1[12] - m2[12]; r[13] = m1[13] - m2[13]; r[14] = m1[14] - m2[14]; r[15] = m1[15] - m2[15];
1833 tb_error_if(result == input,
"tbExternalError: Invalid parameter; expected result to be different than input");
1837 a(0, 0) = b(0, 0); a(0, 1) = b(1, 0); a(0, 2) = b(2, 0);
1838 a(1, 0) = b(0, 1); a(1, 1) = b(1, 1); a(1, 2) = b(2, 1);
1839 a(2, 0) = b(0, 2); a(2, 1) = b(1, 2); a(2, 2) = b(2, 2);
1851 tb_error_if(result == input,
"tbExternalError: Invalid parameter; expected result to be different than input");
1855 a(0, 0) = b(0, 0); a(0, 1) = b(1, 0); a(0, 2) = b(2, 0); a(0, 3) = b(3, 0);
1856 a(1, 0) = b(0, 1); a(1, 1) = b(1, 1); a(1, 2) = b(2, 1); a(1, 3) = b(3, 1);
1857 a(2, 0) = b(0, 2); a(2, 1) = b(1, 2); a(2, 2) = b(2, 2); a(2, 3) = b(3, 2);
1858 a(3, 0) = b(0, 3); a(3, 1) = b(1, 3); a(3, 2) = b(2, 3); a(3, 3) = b(3, 3);
1875 tb_error_if(result == leftSide || result == rightSide,
"tbExternalError: Invalid parameter; expected result to be different than leftSide and rightSide");
1880 (*result)(0, 0) = a(0, 0) * b(0, 0) + a(1, 0) * b(0, 1) + a(2, 0) * b(0, 2);
1881 (*result)(1, 0) = a(0, 0) * b(1, 0) + a(1, 0) * b(1, 1) + a(2, 0) * b(1, 2);
1882 (*result)(2, 0) = a(0, 0) * b(2, 0) + a(1, 0) * b(2, 1) + a(2, 0) * b(2, 2);
1883 (*result)(0, 1) = a(0, 1) * b(0, 0) + a(1, 1) * b(0, 1) + a(2, 1) * b(0, 2);
1884 (*result)(1, 1) = a(0, 1) * b(1, 0) + a(1, 1) * b(1, 1) + a(2, 1) * b(1, 2);
1885 (*result)(2, 1) = a(0, 1) * b(2, 0) + a(1, 1) * b(2, 1) + a(2, 1) * b(2, 2);
1886 (*result)(0, 2) = a(0, 2) * b(0, 0) + a(1, 2) * b(0, 1) + a(2, 2) * b(0, 2);
1887 (*result)(1, 2) = a(0, 2) * b(1, 0) + a(1, 2) * b(1, 1) + a(2, 2) * b(1, 2);
1888 (*result)(2, 2) = a(0, 2) * b(2, 0) + a(1, 2) * b(2, 1) + a(2, 2) * b(2, 2);
1899 tb_error_if(result == leftSide || result == rightSide,
"tbExternalError: Invalid parameter; expected result to be different than leftSide and rightSide");
1904 (*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);
1905 (*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);
1906 (*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);
1907 (*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);
1908 (*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);
1909 (*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);
1910 (*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);
1911 (*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);
1912 (*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);
1913 (*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);
1914 (*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);
1915 (*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);
1916 (*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);
1917 (*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);
1918 (*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);
1919 (*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);
1935 Type* resultComponents = result->mComponents;
1936 const Type* inputComponents = input->mComponents;
1937 for (
size_t index = 0; index < 9; ++index)
1939 resultComponents[index] = inputComponents[index] * scalar;
1955 Type* resultComponents = result->mComponents;
1956 const Type* inputComponents = input->mComponents;
1957 for (
size_t index = 0; index < 16; ++index)
1959 resultComponents[index] = inputComponents[index] * scalar;
1978 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector.");
1979 result->x = (inputVector->x * (*inputMatrix)(0, 0)) + (inputVector->y * (*inputMatrix)(1, 0)) + (inputVector->z * (*inputMatrix)(2, 0));
1980 result->y = (inputVector->x * (*inputMatrix)(0, 1)) + (inputVector->y * (*inputMatrix)(1, 1)) + (inputVector->z * (*inputMatrix)(2, 1));
1981 result->z = (inputVector->x * (*inputMatrix)(0, 2)) + (inputVector->y * (*inputMatrix)(1, 2)) + (inputVector->z * (*inputMatrix)(2, 2));
1999 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector.");
2000 result->x = (inputVector->x * (*inputMatrix)(0, 0)) + (inputVector->y * (*inputMatrix)(0, 1)) + (inputVector->z * (*inputMatrix)(0, 2));
2001 result->y = (inputVector->x * (*inputMatrix)(1, 0)) + (inputVector->y * (*inputMatrix)(1, 1)) + (inputVector->z * (*inputMatrix)(1, 2));
2002 result->z = (inputVector->x * (*inputMatrix)(2, 0)) + (inputVector->y * (*inputMatrix)(2, 1)) + (inputVector->z * (*inputMatrix)(2, 2));
2020 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector.");
2021 result->x = (inputVector->x * (*inputMatrix)(0, 0)) + (inputVector->y * (*inputMatrix)(1, 0)) + (inputVector->z * (*inputMatrix)(2, 0)) + (inputVector->w * (*inputMatrix)(3, 0));
2022 result->y = (inputVector->x * (*inputMatrix)(0, 1)) + (inputVector->y * (*inputMatrix)(1, 1)) + (inputVector->z * (*inputMatrix)(2, 1)) + (inputVector->w * (*inputMatrix)(3, 1));
2023 result->z = (inputVector->x * (*inputMatrix)(0, 2)) + (inputVector->y * (*inputMatrix)(1, 2)) + (inputVector->z * (*inputMatrix)(2, 2)) + (inputVector->w * (*inputMatrix)(3, 2));
2024 result->w = (inputVector->x * (*inputMatrix)(0, 3)) + (inputVector->y * (*inputMatrix)(1, 3)) + (inputVector->z * (*inputMatrix)(2, 3)) + (inputVector->w * (*inputMatrix)(3, 3));
2042 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector.");
2043 result->x = (inputVector->x * (*inputMatrix)(0, 0)) + (inputVector->y * (*inputMatrix)(0, 1)) + (inputVector->z * (*inputMatrix)(0, 2)) + (inputVector->w * (*inputMatrix)(0, 3));
2044 result->y = (inputVector->x * (*inputMatrix)(1, 0)) + (inputVector->y * (*inputMatrix)(1, 1)) + (inputVector->z * (*inputMatrix)(1, 2)) + (inputVector->w * (*inputMatrix)(1, 3));
2045 result->z = (inputVector->x * (*inputMatrix)(2, 0)) + (inputVector->y * (*inputMatrix)(2, 1)) + (inputVector->z * (*inputMatrix)(2, 2)) + (inputVector->w * (*inputMatrix)(2, 3));
2046 result->w = (inputVector->x * (*inputMatrix)(3, 0)) + (inputVector->y * (*inputMatrix)(3, 1)) + (inputVector->z * (*inputMatrix)(3, 2)) + (inputVector->w * (*inputMatrix)(3, 3));
2067 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector");
2070 result->x = (inputVector->x * matrix(0, 0)) + (inputVector->y * matrix(0, 1)) + (inputVector->z * matrix(0, 2)) + matrix(0, 3);
2071 result->y = (inputVector->x * matrix(1, 0)) + (inputVector->y * matrix(1, 1)) + (inputVector->z * matrix(1, 2)) + matrix(1, 3);
2072 result->z = (inputVector->x * matrix(2, 0)) + (inputVector->y * matrix(2, 1)) + (inputVector->z * matrix(2, 2)) + matrix(2, 3);
2090 tb_error_if(result == inputVector,
"tbExternalError: Invalid parameter; expected result to be different than inputVector");
2093 result->x = (inputVector->x * matrix(0, 0)) + (inputVector->y * matrix(0, 1)) + (inputVector->z * matrix(0, 2));
2094 result->y = (inputVector->x * matrix(1, 0)) + (inputVector->y * matrix(1, 1)) + (inputVector->z * matrix(1, 2));
2095 result->z = (inputVector->x * matrix(2, 0)) + (inputVector->y * matrix(2, 1)) + (inputVector->z * matrix(2, 2));
2099 template<
typename Type> Type Matrix2x2Determinant(
const Type f11,
const Type f12,
const Type f21,
const Type f22)
2101 return f11 * f22 - f12 * f21;
2109 const Type f21,
const Type f22,
const Type f23,
const Type f31,
const Type f32,
const Type f33)
2111 return f11 * (f22 * f33 - f32 * f23) - f12 * (f21 * f33 - f31 * f23) + f13 * (f21 * f32 - f31 * f22);
2121 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));
2131 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))) -
2132 (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))) +
2133 (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))) -
2134 (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)));
2144 tb_error_if(result == input,
"tbExternalError: Invalid parameter, expected result to be different than input.");
2152 const Type inverseDeterminant = 1.0f / determinant;
2155 (*result)(0, 0) = Matrix2x2Determinant(m(1, 1), m(1, 2), m(2, 1), m(2, 2)) * inverseDeterminant;
2156 (*result)(1, 0) = -Matrix2x2Determinant(m(1, 0), m(1, 2), m(2, 0), m(2, 2)) * inverseDeterminant;
2157 (*result)(2, 0) = Matrix2x2Determinant(m(1, 0), m(1, 1), m(2, 0), m(2, 1)) * inverseDeterminant;
2158 (*result)(0, 1) = -Matrix2x2Determinant(m(0, 1), m(0, 2), m(2, 1), m(2, 2)) * inverseDeterminant;
2159 (*result)(1, 1) = Matrix2x2Determinant(m(0, 0), m(0, 2), m(2, 0), m(2, 2)) * inverseDeterminant;
2160 (*result)(2, 1) = -Matrix2x2Determinant(m(0, 0), m(0, 1), m(2, 0), m(2, 1)) * inverseDeterminant;
2161 (*result)(0, 2) = Matrix2x2Determinant(m(0, 1), m(0, 2), m(1, 1), m(1, 2)) * inverseDeterminant;
2162 (*result)(1, 2) = -Matrix2x2Determinant(m(0, 0), m(0, 2), m(1, 0), m(1, 2)) * inverseDeterminant;
2163 (*result)(2, 2) = Matrix2x2Determinant(m(0, 0), m(0, 1), m(1, 0), m(1, 1)) * inverseDeterminant;
2180 tb_error_if(result == input,
"tbExternalError: Invalid parameter, expected result to be different than input.");
2188 const Type inverseDeterminant = 1.0f / determinant;
2190 (*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;
2191 (*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;
2192 (*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;
2193 (*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;
2194 (*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;
2195 (*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;
2196 (*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;
2197 (*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;
2198 (*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;
2199 (*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;
2200 (*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;
2201 (*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;
2202 (*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;
2203 (*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;
2204 (*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;
2205 (*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;
2219 tb_error_if(result == input,
"tbExternalError: Invalid parameter, expected result to be different than input.");
2221 (*result)(0, 0) = (*input)(0, 0);
2222 (*result)(1, 1) = (*input)(1, 1);
2223 (*result)(2, 2) = (*input)(2, 2);
2225 (*result)(1, 0) = (*input)(0, 1);
2226 (*result)(2, 0) = (*input)(0, 2);
2227 (*result)(0, 1) = (*input)(1, 0);
2228 (*result)(2, 1) = (*input)(1, 2);
2229 (*result)(0, 2) = (*input)(2, 0);
2230 (*result)(1, 2) = (*input)(2, 1);
2252 tb_error_if(result == input,
"tbExternalError: Invalid parameter, expected result to be different than input.");
2254 (*result)(0, 0) = (*input)(0, 0);
2255 (*result)(1, 1) = (*input)(1, 1);
2256 (*result)(2, 2) = (*input)(2, 2);
2257 (*result)(3, 3) = (*input)(3, 3);
2259 (*result)(1, 0) = (*input)(0, 1);
2260 (*result)(2, 0) = (*input)(0, 2);
2261 (*result)(0, 1) = (*input)(1, 0);
2262 (*result)(2, 1) = (*input)(1, 2);
2263 (*result)(0, 2) = (*input)(2, 0);
2264 (*result)(1, 2) = (*input)(2, 1);
2285 (*result)(0, 3) = (-(*input)(0, 3) * inversed(0, 0) + -(*input)(1, 3) * inversed(0, 1) + -(*input)(2, 3) * inversed(0, 2));
2286 (*result)(1, 3) = (-(*input)(0, 3) * inversed(1, 0) + -(*input)(1, 3) * inversed(1, 1) + -(*input)(2, 3) * inversed(1, 2));
2287 (*result)(2, 3) = (-(*input)(0, 3) * inversed(2, 0) + -(*input)(1, 3) * inversed(2, 1) + -(*input)(2, 3) * inversed(2, 2));
2290 (*result)(3, 0) = 0.0f;
2291 (*result)(3, 1) = 0.0f;
2292 (*result)(3, 2) = 0.0f;
2299 inline Matrix4 Translate(
const Matrix4& originalMatrix,
const Vector3& translation)
2301 Matrix4 outputMatrix(kSkipInitialization);
2302 Matrix4 translationMatrix(kSkipInitialization);
2305 MatrixMultiply(&outputMatrix, &translationMatrix, &originalMatrix);
2307 return outputMatrix;
2310 inline Matrix4 Translate(
const Matrix4& originalMatrix,
float x,
float y,
float z)
2318 inline Matrix4 TranslateLocal(
const Matrix4& originalMatrix,
const Vector3& translation)
2320 Matrix4 outputMatrix(kSkipInitialization);
2321 Matrix4 translationMatrix(kSkipInitialization);
2324 MatrixMultiply(&outputMatrix, &originalMatrix, &translationMatrix);
2326 return outputMatrix;
2329 inline Matrix4 TranslateLocal(
const Matrix4& originalMatrix,
float x,
float y,
float z)
2337 inline Matrix3 Rotate(
const Matrix3& originalMatrix,
const Vector3& aroundAxis,
const tbMath::Angle angle)
2339 Matrix3 outputMatrix(kSkipInitialization);
2340 Matrix3 rotationMatrix(kSkipInitialization);
2347 return outputMatrix;
2350 inline Matrix3 Rotate(
const size_t& axisIndex,
const Matrix3& originalMatrix,
const tbMath::Angle angle)
2352 return Rotate(originalMatrix, originalMatrix.GetBasis(axisIndex), angle);
2358 inline Matrix4 Rotate(
const Matrix4& originalMatrix,
const Vector3& aroundAxis,
const tbMath::Angle angle)
2360 Matrix4 outputMatrix(kSkipInitialization);
2361 Matrix4 rotationMatrix(kSkipInitialization);
2368 return outputMatrix;
2371 inline Matrix4 Rotate(
const size_t& axisIndex,
const Matrix4& originalMatrix,
const tbMath::Angle angle)
2373 return Rotate(originalMatrix, originalMatrix.GetBasis(axisIndex), angle);
2378 inline Matrix4 RotateWorldSpace(
const size_t& axisIndex,
const Matrix4& originalMatrix,
const tbMath::Angle angle)
2380 Matrix4 outputMatrix(kSkipInitialization);
2381 Matrix4 rotationMatrix(kSkipInitialization);
2388 const Matrix4 rotationTransposed(rotationMatrix.GetTransposed());
2389 MatrixMultiply(&outputMatrix, &originalMatrix, &rotationTransposed);
2391 return outputMatrix;
2394 inline Matrix3 Scale(
const Matrix3& originalMatrix,
const Vector3& scale)
2396 Matrix3 outputMatrix(kSkipInitialization);
2397 Matrix3 scalingMatrix(kSkipInitialization);
2402 return outputMatrix;
2405 inline Matrix3 Scale(
const Matrix3 originalMatrix,
float x,
float y,
float z)
2407 return Scale(originalMatrix, Vector3(x, y, z));
2410 inline Matrix4 Scale(
const Matrix4& originalMatrix,
const Vector3& scale)
2412 Matrix4 outputMatrix(kSkipInitialization);
2413 Matrix4 scalingMatrix(kSkipInitialization);
2418 return outputMatrix;
2421 inline Matrix4 Scale(
const Matrix4& originalMatrix,
float x,
float y,
float z)
2423 return Scale(originalMatrix, Vector3(x, y, z));
2432 for (
int r = 0; r < 3; ++r)
2435 for (
int c = 0; c < 3; ++c)
2437 output << data(c, r) << ((c < 2) ?
", " :
"");
2453 for (
int r = 0; r < 3; ++r)
2456 for (
int c = 0; c < 3; ++c)
2459 data(c, r) = tbCore::FromString<Type>(token);
2474 for (
int r = 0; r < 4; ++r)
2477 for (
int c = 0; c < 4; ++c)
2479 output << data(c, r) << ((c < 3) ?
", " :
"");
2495 for (
int r = 0; r < 4; ++r)
2498 for (
int c = 0; c < 4; ++c)
2501 data(c, r) = tbCore::FromString<Type>(token);
Definition: tb_angle.hpp:38
Type AsRadians(void) const
Definition: tb_angle.hpp:87
Definition: tb_matrix.hpp:156
TypedMatrix3 & operator=(const TypedMatrix3 &other)=default
void SetBasis(const size_t &basisIndex, const TypedVector3< Type > &basis)
Definition: tb_matrix.hpp:449
TypedMatrix3(const SkipInitialization &fastAndStupid)
Definition: tb_matrix.hpp:300
TypedMatrix3(const TypedMatrix3 &other)=default
TypedMatrix3(void)
Definition: tb_matrix.hpp:251
Type & operator()(int column, int row)
Definition: tb_matrix.hpp:407
static TypedMatrix3 Zero(void)
Definition: tb_matrix.hpp:161
static TypedMatrix3 Identity(void)
Definition: tb_matrix.hpp:173
TypedMatrix3(Type f11, Type f21, Type f31, Type f12, Type f22, Type f32, Type f13, Type f23, Type f33)
Definition: tb_matrix.hpp:262
bool operator!=(const TypedMatrix3 &other) const
Definition: tb_matrix.hpp:355
const Type & operator[](const int &index) const
Definition: tb_matrix.hpp:372
const Type & operator()(const size_t &column, const size_t &row) const
Definition: tb_matrix.hpp:387
void SetBasis(const size_t &basisIndex, Type basisX, Type basisY, Type basisZ)
Definition: tb_matrix.hpp:459
TypedMatrix3(const Type *const componentArray)
Definition: tb_matrix.hpp:277
Type & operator()(const size_t &column, const size_t &row)
Definition: tb_matrix.hpp:394
const TypedVector3< Type > GetBasis(const size_t &basisIndex) const
Definition: tb_matrix.hpp:441
const Type & operator()(int column, int row) const
Definition: tb_matrix.hpp:400
Type & operator[](const int &index)
Definition: tb_matrix.hpp:380
bool operator==(const TypedMatrix3 &other) const
Definition: tb_matrix.hpp:337
Definition: tb_matrix.hpp:596
const Type & operator[](const int index) const
Definition: tb_matrix.hpp:878
void SetPosition(const Type x, const Type y, const Type z)
Definition: tb_matrix.hpp:998
TypedMatrix4(Type f11, Type f21, Type f31, Type f41, Type f12, Type f22, Type f32, Type f42, Type f13, Type f23, Type f33, Type f43, Type f14, Type f24, Type f34, Type f44)
Definition: tb_matrix.hpp:726
TypedMatrix4(const Type *const componentArray)
Definition: tb_matrix.hpp:764
Type & operator()(int column, int row)
Definition: tb_matrix.hpp:913
void SetBasis(const size_t &basisIndex, Type basisX, Type basisY, Type basisZ)
Definition: tb_matrix.hpp:966
Type & operator[](const int index)
Definition: tb_matrix.hpp:886
TypedMatrix4 & operator=(const TypedMatrix4 &other)=default
TypedMatrix4(const TypedMatrix4 &other)=default
TypedVector3< Type > GetBasis(const size_t &basisIndex) const
Definition: tb_matrix.hpp:948
static TypedMatrix4 Zero(void)
Definition: tb_matrix.hpp:601
bool operator==(const TypedMatrix4 &other) const
Definition: tb_matrix.hpp:843
TypedMatrix3< Type > GetOrientation(void) const
Definition: tb_matrix.hpp:1009
TypedMatrix4(const Type *const componentArray, const ColumnMajorMatrix &columnMajor)
Definition: tb_matrix.hpp:780
TypedVector3< Type > GetPosition(void) const
Definition: tb_matrix.hpp:978
void SetBasis(const size_t &basisIndex, const TypedVector3< Type > &basis)
Definition: tb_matrix.hpp:956
TypedMatrix4(const SkipInitialization &fastAndStupid)
Definition: tb_matrix.hpp:805
const Type & operator()(const size_t &column, const size_t &row) const
Definition: tb_matrix.hpp:893
void SetOrientation(const TypedMatrix3< Type > &orientation)
Definition: tb_matrix.hpp:1022
Type & operator()(const size_t &column, const size_t &row)
Definition: tb_matrix.hpp:900
TypedMatrix4(void)
Definition: tb_matrix.hpp:714
const Type & operator()(int column, int row) const
Definition: tb_matrix.hpp:906
static TypedMatrix4 Identity(void)
Definition: tb_matrix.hpp:614
void SetPosition(const TypedVector3< Type > &position)
Definition: tb_matrix.hpp:987
bool operator!=(const TypedMatrix4 &other) const
Definition: tb_matrix.hpp:861
TypedMatrix4(Type f11, Type f21, Type f31, Type f41, Type f12, Type f22, Type f32, Type f42, Type f13, Type f23, Type f33, Type f43, Type f14, Type f24, Type f34, Type f44, const ColumnMajorMatrix &columnMajor)
Definition: tb_matrix.hpp:745
Definition: tb_quaternion.hpp:41
Definition: tb_vector.hpp:472
Definition: tb_vector.hpp:927
#define tb_unused(parameter)
Definition: tb_defines.hpp:25
#define tb_error_if(errorTest, message,...)
Definition: tb_error.hpp:42
std::string String
Definition: tb_string.hpp:302
Contains objects and functions for dealing with Vector and Matrix math.
TypedMatrix3< Type > * MatrixComputeInverse(TypedMatrix3< Type > *result, const TypedMatrix3< Type > *input)
Definition: tb_matrix.hpp:2140
Matrix3 * MatrixSubtract(Matrix3 *result, const Matrix3 *leftSide, const Matrix3 *rightSide)
Definition: tb_matrix.hpp:1797
Type Vector3DotProduct(const TypedVector3< Type > *leftSide, const TypedVector3< Type > *rightSide)
Definition: tb_vector.hpp:1618
TypedVector4< Type > * Vector4MatrixMultiply(TypedVector4< Type > *result, const TypedVector4< Type > *inputVector, const TypedMatrix4< Type > *inputMatrix)
Definition: tb_matrix.hpp:2039
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:1705
TypedMatrix3< Type > * MatrixCreateRotationZ(TypedMatrix3< Type > *result, const TypedAngle< Type > rotation)
Definition: tb_matrix.hpp:1534
TypedMatrix3< Type > * MatrixCreateRotationA(TypedMatrix3< Type > *result, const TypedVector3< Type > *rotationAxis, const TypedAngle< Type > rotation)
Definition: tb_matrix.hpp:1569
TypedMatrix3< Type > * MatrixCreateRotationY(TypedMatrix3< Type > *result, const TypedAngle< Type > rotation)
Definition: tb_matrix.hpp:1500
std::ostream & operator<<(std::ostream &output, const tbMath::TypedAngle< Type > &angle)
Definition: tb_angle.hpp:203
Matrix4 * MatrixCreatePerspectiveLH(Matrix4 *result, const float fieldOfView, const float aspectRatio, const float nearPlane, const float farPlane)
Definition: tb_matrix.hpp:1673
bool IsZero(const Type &value, const Type tolerance=tbMath::kTolerance)
Definition: tb_math.hpp:74
bool IsEqual(const Type &leftValue, const Type &rightValue, const Type tolerance=tbMath::kTolerance)
Definition: tb_math.hpp:56
Matrix4 * MatrixCreatePerspectiveRH(Matrix4 *result, const float fieldOfView, const float aspectRatio, const float nearPlane, const float farPlane)
Definition: tb_matrix.hpp:1644
Type Vector3Magnitude(const TypedVector3< Type > *input)
Definition: tb_vector.hpp:1687
TypedVector3< Type > * MatrixVector3Multiply(TypedVector3< Type > *result, const TypedMatrix3< Type > *inputMatrix, const TypedVector3< Type > *inputVector)
Definition: tb_matrix.hpp:1975
TypedMatrix4< Type > * MatrixCreateLookAt(TypedMatrix4< Type > *result, const TypedVector3< Type > &eyePosition, const TypedVector3< Type > &targetPosition, const TypedVector3< Type > &unitUp)
Definition: tb_matrix.hpp:1329
Type MatrixDeterminant(const TypedMatrix3< Type > *input)
Definition: tb_matrix.hpp:2118
TypedVector4< Type > * MatrixVector4Multiply(TypedVector4< Type > *result, const TypedMatrix4< Type > *inputMatrix, const TypedVector4< Type > *inputVector)
Definition: tb_matrix.hpp:2017
Type Matrix3x3Determinant(const Type f11, const Type f12, const Type f13, const Type f21, const Type f22, const Type f23, const Type f31, const Type f32, const Type f33)
Definition: tb_matrix.hpp:2108
TypedVector3< Type > * Vector3MatrixMultiply(TypedVector3< Type > *result, const TypedVector3< Type > *inputVector, const TypedMatrix3< Type > *inputMatrix)
Definition: tb_matrix.hpp:1996
SkipInitialization
Definition: tb_vector.hpp:80
TypedMatrix3< Type > * MatrixCreateIdentity(TypedMatrix3< Type > *result)
Definition: tb_matrix.hpp:1305
TypedMatrix3< Type > * MatrixMultiply(TypedMatrix3< Type > *result, const TypedMatrix3< Type > *input, const Type &scalar)
Definition: tb_matrix.hpp:1933
TypedMatrix4< Type > * MatrixCreateTranslation(TypedMatrix4< Type > *result, const TypedVector3< Type > *translation)
Definition: tb_matrix.hpp:1369
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:1737
TypedMatrix3< Type > * MatrixCreateRotationX(TypedMatrix3< Type > *result, const TypedAngle< Type > rotation)
Definition: tb_matrix.hpp:1466
Vector3 * Vector3Subtract(Vector3 *result, const Vector3 *leftSide, const Vector3 *rightSide)
Definition: tb_vector.hpp:1430
Matrix3 * MatrixTranspose(Matrix3 *result, const Matrix3 *input)
Definition: tb_matrix.hpp:1831
TypedVector3< Type > * Vector3TransformNormal(TypedVector3< Type > *result, const TypedVector3< Type > *inputVector, const TypedMatrix4< Type > *inputMatrix)
Definition: tb_matrix.hpp:2087
TypedVector3< Type > * Vector3CrossProduct(TypedVector3< Type > *result, const TypedVector3< Type > *leftSide, const TypedVector3< Type > *rightSide)
Definition: tb_vector.hpp:1648
TypedVector3< Type > * Vector3TransformCoordinate(TypedVector3< Type > *result, const TypedVector3< Type > *inputVector, const TypedMatrix4< Type > *inputMatrix)
Definition: tb_matrix.hpp:2064
TypedMatrix3< Type > * MatrixCreateScale(TypedMatrix3< Type > *result, const TypedVector3< Type > *scale)
Definition: tb_matrix.hpp:1404
Matrix3 * MatrixAdd(Matrix3 *result, const Matrix3 *leftSide, const Matrix3 *rightSide)
Definition: tb_matrix.hpp:1761
TypedVector3< Type > * Vector3Normalize(TypedVector3< Type > *result, const TypedVector3< Type > *value)
Definition: tb_vector.hpp:1764
TypedMatrix3< Type > * MatrixFastInverse(TypedMatrix3< Type > *result, const TypedMatrix3< Type > *input)
Definition: tb_matrix.hpp:2217
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:22