33 #include "DebugUtilities.h" 35 #define _USE_MATH_DEFINES 38 #include "HashUtils.h" 42 #define PI_F 3.1415927f 45 template <
class T>
struct Matrix4x4;
46 template <
class T>
struct Vector4;
48 template <
class T>
struct Vector2
70 Vector2 operator-(
const Vector2<T> &right)
const 72 return Vector2(x - right.x, y - right.y);
75 Vector2& operator-=(
const Vector2<T> &right)
82 Vector2 operator-()
const 84 return Vector2(-x, -y);
87 Vector2 operator+(
const Vector2<T> &right)
const 89 return Vector2(x + right.x, y + right.y);
92 Vector2& operator+=(
const Vector2<T> &right)
99 Vector2 operator*(T s)
const 101 return Vector2(x * s, y * s);
104 Vector2 operator*(
const Vector2 &right)
const 106 return Vector2(x * right.x, y * right.y);
109 Vector2& operator*=(
const Vector2 &right)
116 Vector2& operator*=( T s)
123 Vector2 operator/(
const Vector2 &right)
const 125 return Vector2(x / right.x, y / right.y);
128 Vector2& operator/=(
const Vector2 &right)
135 Vector2 operator/(T s)
const 137 return Vector2(x / s, y / s);
140 Vector2& operator/=( T s)
147 bool operator == (
const Vector2 &right)
const 149 return x == right.x && y == right.y;
152 bool operator != (
const Vector2 &right)
const 154 return !(*
this == right);
157 Vector2 operator < (
const Vector2 &right )
const 159 return Vector2(x < right.x ? static_cast<T>(1) : static_cast<T>(0),
160 y < right.y ? static_cast<T>(1) : static_cast<T>(0));
163 Vector2 operator > (
const Vector2 &right )
const 165 return Vector2(x > right.x ? static_cast<T>(1) : static_cast<T>(0),
166 y > right.y ? static_cast<T>(1) : static_cast<T>(0));
169 Vector2 operator <= (
const Vector2 &right )
const 171 return Vector2(x <= right.x ? static_cast<T>(1) : static_cast<T>(0),
172 y <= right.y ? static_cast<T>(1) : static_cast<T>(0));
175 Vector2 operator >= (
const Vector2 &right )
const 177 return Vector2(x >= right.x ? static_cast<T>(1) : static_cast<T>(0),
178 y >= right.y ? static_cast<T>(1) : static_cast<T>(0));
181 T& operator[](
size_t index)
183 return reinterpret_cast<T*
>(
this)[index];
186 const T& operator[](
size_t index)
const 188 return reinterpret_cast<const T*
>(
this)[index];
192 Vector2(T _x = 0, T _y = 0) : x(_x), y(_y) { }
196 Vector2<T> operator*(T s,
const Vector2<T> &a)
202 template <
class T>
struct Vector3
227 Vector3 operator-(
const Vector3 &right )
const 229 return Vector3(x - right.x, y - right.y, z - right.z);
232 Vector3 operator-()
const 234 return Vector3(-x, -y, -z);
237 Vector3& operator-=(
const Vector3<T> &right)
245 Vector3 operator+(
const Vector3 &right )
const 247 return Vector3(x + right.x, y + right.y, z + right.z);
250 Vector3& operator+=(
const Vector3<T> &right)
258 Vector3 operator*( T s )
const 260 return Vector3(x * s, y * s, z * s);
263 Vector3& operator*=( T s)
271 Vector3 operator*(
const Vector3 &right )
const 273 return Vector3(x * right.x, y * right.y, z * right.z);
276 Vector3 operator* (
const Matrix4x4<T>& m)
const 278 Vector4<T> out4 = Vector4<T>(x, y, z, 1) * m;
279 return Vector3(out4.x / out4.w, out4.y / out4.w, out4.z / out4.w) ;
282 Vector3& operator*=(
const Vector3 &right)
290 Vector3 operator/ ( T s)
const 292 return Vector3(x / s, y / s, z / s);
295 Vector3& operator/=( T s)
303 Vector3 operator/(
const Vector3 &right )
const 305 return Vector3(x / right.x, y / right.y, z / right.z);
308 Vector3& operator/=(
const Vector3 &right)
316 bool operator == (
const Vector3 &right)
const 318 return x == right.x && y == right.y && z == right.z;
321 bool operator != (
const Vector3 &right)
const 323 return !(*
this == right);
326 Vector3 operator < (
const Vector3 &right )
const 328 return Vector3(x < right.x ? static_cast<T>(1) : static_cast<T>(0),
329 y < right.y ? static_cast<T>(1) : static_cast<T>(0),
330 z < right.z ? static_cast<T>(1) : static_cast<T>(0));
333 Vector3 operator > (
const Vector3 &right )
const 335 return Vector3(x > right.x ? static_cast<T>(1) : static_cast<T>(0),
336 y > right.y ? static_cast<T>(1) : static_cast<T>(0),
337 z > right.z ? static_cast<T>(1) : static_cast<T>(0));
340 Vector3 operator <= (
const Vector3 &right )
const 342 return Vector3(x <= right.x ? static_cast<T>(1) : static_cast<T>(0),
343 y <= right.y ? static_cast<T>(1) : static_cast<T>(0),
344 z <= right.z ? static_cast<T>(1) : static_cast<T>(0));
347 Vector3 operator >= (
const Vector3 &right )
const 349 return Vector3(x >= right.x ? static_cast<T>(1) : static_cast<T>(0),
350 y >= right.y ? static_cast<T>(1) : static_cast<T>(0),
351 z >= right.z ? static_cast<T>(1) : static_cast<T>(0));
354 T& operator[](
size_t index)
356 return reinterpret_cast<T*
>(
this)[index];
359 const T& operator[](
size_t index)
const 361 return reinterpret_cast<const T*
>(
this)[index];
365 Vector3(T _x = 0, T _y = 0, T _z = 0) : x(_x), y(_y), z(_z) { }
367 operator Vector2<T>()
const{
return Vector2<T>(x,y);}
371 Vector3<T> operator*(T s,
const Vector3<T> &a)
377 template <
class T>
struct Vector4
397 Vector4 operator-(
const Vector4 &right)
const 399 return Vector4(x - right.x, y - right.y, z - right.z, w - right.w);
402 Vector4 operator-()
const 404 return Vector4(-x, -y, -z, -w);
407 Vector4& operator-=(
const Vector4<T> &right)
416 Vector4 operator+(
const Vector4 &right)
const 418 return Vector4(x + right.x, y + right.y, z + right.z, w + right.w);
421 Vector4& operator+=(
const Vector4<T> &right)
430 Vector4 operator*( T s)
const 432 return Vector4(x * s, y * s, z * s, w * s);
435 Vector4& operator*=( T s)
444 Vector4 operator*(
const Vector4 &right)
const 446 return Vector4(x * right.x, y * right.y, z * right.z, w * right.w);
449 Vector4& operator*=(
const Vector4 &right)
458 Vector4 operator/( T s)
const 460 return Vector4(x / s, y / s, z / s, w / s);
463 Vector4& operator/=( T s)
472 Vector4 operator/(
const Vector4 &right)
const 474 return Vector4(x / right.x, y / right.y, z / right.z, w / right.w);
477 Vector4& operator/=(
const Vector4 &right)
486 bool operator == (
const Vector4 &right)
const 488 return x == right.x && y == right.y && z == right.z && w == right.w;
491 bool operator != (
const Vector4 &right)
const 493 return !(*
this == right);
496 Vector4 operator*(
const Matrix4x4<T>& m)
const 499 out[0] = x * m[0][0] + y * m[1][0] + z * m[2][0] + w * m[3][0];
500 out[1] = x * m[0][1] + y * m[1][1] + z * m[2][1] + w * m[3][1];
501 out[2] = x * m[0][2] + y * m[1][2] + z * m[2][2] + w * m[3][2];
502 out[3] = x * m[0][3] + y * m[1][3] + z * m[2][3] + w * m[3][3];
506 Vector4& operator = (
const Vector3<T> &v3)
514 Vector4& operator = (
const Vector4 &) =
default;
516 Vector4 operator < (
const Vector4 &right )
const 518 return Vector4(x < right.x ? static_cast<T>(1) : static_cast<T>(0),
519 y < right.y ? static_cast<T>(1) : static_cast<T>(0),
520 z < right.z ? static_cast<T>(1) : static_cast<T>(0),
521 w < right.w ? static_cast<T>(1) : static_cast<T>(0));
524 Vector4 operator > (
const Vector4 &right )
const 526 return Vector4(x > right.x ? static_cast<T>(1) : static_cast<T>(0),
527 y > right.y ? static_cast<T>(1) : static_cast<T>(0),
528 z > right.z ? static_cast<T>(1) : static_cast<T>(0),
529 w > right.w ? static_cast<T>(1) : static_cast<T>(0));
532 Vector4 operator <= (
const Vector4 &right )
const 534 return Vector4(x <= right.x ? static_cast<T>(1) : static_cast<T>(0),
535 y <= right.y ? static_cast<T>(1) : static_cast<T>(0),
536 z <= right.z ? static_cast<T>(1) : static_cast<T>(0),
537 w <= right.w ? static_cast<T>(1) : static_cast<T>(0));
540 Vector4 operator >= (
const Vector4 &right )
const 542 return Vector4(x >= right.x ? static_cast<T>(1) : static_cast<T>(0),
543 y >= right.y ? static_cast<T>(1) : static_cast<T>(0),
544 z >= right.z ? static_cast<T>(1) : static_cast<T>(0),
545 w >= right.w ? static_cast<T>(1) : static_cast<T>(0));
548 T& operator[](
size_t index)
550 return reinterpret_cast<T*
>(
this)[index];
553 const T& operator[](
size_t index)
const 555 return reinterpret_cast<const T*
>(
this)[index];
559 Vector4(T _x = 0, T _y = 0, T _z = 0, T _w = 0) : x(_x), y(_y), z(_z), w(_w) { }
564 Vector4<T> operator*(T s,
const Vector4<T> &a)
569 template <
class T>
struct Matrix3x3
581 T _m00; T _m01; T _m02;
582 T _m10; T _m11; T _m12;
583 T _m20; T _m21; T _m22;
588 Matrix3x3(T value = 0)
590 _11 = _12 = _13 =value;
591 _21 = _22 = _23 =value;
592 _31 = _32 = _33 =value;
599 T i31, T i32, T i33 )
601 _11 = i11; _12 = i12; _13 = i13;
602 _21 = i21; _22 = i22; _23 = i23;
603 _31 = i31; _32 = i32; _33 = i33;
606 bool operator == (
const Matrix3x3 &r)
const 608 for(
int i = 0; i < 3; ++i )
609 for(
int j = 0; i < 3; ++i )
610 if( (*
this)[i][j] != r[i][j] )
616 bool operator != (
const Matrix3x3 &r)
const 618 return !(*
this == r);
621 T* operator[](
size_t index)
623 return &(
reinterpret_cast<T*
>(
this)[index*3]);
626 const T* operator[](
size_t index)
const 628 return &(
reinterpret_cast<const T*
>(
this)[index*3]);
631 Matrix3x3& operator *=(T s)
633 for(
int i = 0; i < 9; ++i )
634 (reinterpret_cast<T*>(
this))[i] *= s;
640 template <
class T>
struct Matrix4x4
646 T _11; T _12; T _13; T _14;
647 T _21; T _22; T _23; T _24;
648 T _31; T _32; T _33; T _34;
649 T _41; T _42; T _43; T _44;
653 T _m00; T _m01; T _m02; T _m03;
654 T _m10; T _m11; T _m12; T _m13;
655 T _m20; T _m21; T _m22; T _m23;
656 T _m30; T _m31; T _m32; T _m33;
661 Matrix4x4(T value = 0)
663 _11 = _12 = _13 = _14 = value;
664 _21 = _22 = _23 = _24 = value;
665 _31 = _32 = _33 = _34 = value;
666 _41 = _42 = _43 = _44 = value;
671 T i11, T i12, T i13, T i14,
672 T i21, T i22, T i23, T i24,
673 T i31, T i32, T i33, T i34,
674 T i41, T i42, T i43, T i44
677 _11 = i11; _12 = i12; _13 = i13; _14 = i14;
678 _21 = i21; _22 = i22; _23 = i23; _24 = i24;
679 _31 = i31; _32 = i32; _33 = i33; _34 = i34;
680 _41 = i41; _42 = i42; _43 = i43; _44 = i44;
683 bool operator == (
const Matrix4x4 &r)
const 685 for(
int i = 0; i < 4; ++i )
686 for(
int j = 0; i < 4; ++i )
687 if( (*
this)[i][j] != r[i][j] )
693 bool operator != (
const Matrix4x4 &r)
const 695 return !(*
this == r);
698 T* operator[](
size_t index)
700 return &(
reinterpret_cast<T*
>(
this)[index*4]);
703 const T* operator[](
size_t index)
const 705 return &(
reinterpret_cast<const T*
>(
this)[index*4]);
708 Matrix4x4& operator *=(T s)
710 for(
int i = 0; i < 16; ++i )
711 (reinterpret_cast<T*>(
this))[i] *= s;
721 T dot(
const Vector2<T> &a,
const Vector2<T> &b)
723 return a.x * b.x + a.y * b.y;
727 T dot(
const Vector3<T> &a,
const Vector3<T> &b)
729 return a.x * b.x + a.y * b.y + a.z * b.z;
733 T dot(
const Vector4<T> &a,
const Vector4<T> &b)
735 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
738 template <
class VectorType>
739 auto length(
const VectorType &a)->decltype(dot(a,a))
741 return sqrt( dot(a,a) );
746 Vector3<T> min(
const Vector3<T> &a,
const Vector3<T> &b)
748 return Vector3<T>( std::min(a.x, b.x), std::min(a.y, b.y), std::min(a.z, b.z) );
752 Vector4<T> min(
const Vector4<T> &a,
const Vector4<T> &b)
754 return Vector4<T>( std::min(a.x, b.x), std::min(a.y, b.y), std::min(a.z, b.z), std::min(a.w, b.w) );
758 Vector3<T> max(
const Vector3<T> &a,
const Vector3<T> &b)
760 return Vector3<T>( std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z) );
764 Vector4<T> max(
const Vector4<T> &a,
const Vector4<T> &b)
766 return Vector4<T>( std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z), std::max(a.w, b.w) );
770 Vector2<T> abs(
const Vector2<T> &a)
773 return Vector2<T>( a.x < 0 ? -a.x : a.x,
774 a.y < 0 ? -a.y : a.y);
778 Vector3<T> abs(
const Vector3<T> &a)
781 return Vector3<T>( a.x < 0 ? -a.x : a.x,
782 a.y < 0 ? -a.y : a.y,
783 a.z < 0 ? -a.z : a.z);
787 Vector4<T> abs(
const Vector4<T> &a)
790 return Vector4<T>( a.x < 0 ? -a.x : a.x,
791 a.y < 0 ? -a.y : a.y,
792 a.z < 0 ? -a.z : a.z,
793 a.w < 0 ? -a.w : a.w);
798 Vector3<T> cross(
const Vector3<T> &a,
const Vector3<T> &b)
803 return Vector3<T>((a.y*b.z)-(a.z*b.y), (a.z*b.x)-(a.x*b.z), (a.x*b.y)-(a.y*b.x));
806 template <
class VectorType>
807 VectorType normalize(
const VectorType &a)
809 auto len = length(a);
817 Matrix4x4<T> transposeMatrix(
const Matrix4x4<T> &m)
820 m._11, m._21, m._31, m._41,
821 m._12, m._22, m._32, m._42,
822 m._13, m._23, m._33, m._43,
823 m._14, m._24, m._34, m._44
828 Matrix4x4<T> mul(
const Matrix4x4<T> &m1,
const Matrix4x4<T> &m2)
832 for (
int i = 0; i < 4; i++)
834 for (
int j = 0; j < 4; j++)
836 for (
int k = 0; k < 4; k++)
838 mOut[i][j] += m1[i][k] * m2[k][j];
847 Matrix4x4<T> operator* (
const Matrix4x4<T> &m1,
const Matrix4x4<T> &m2)
849 return mul( m1, m2 );
855 Matrix3x3<T> transposeMatrix(
const Matrix3x3<T> &m)
865 Matrix3x3<T> mul(
const Matrix3x3<T> &m1,
const Matrix3x3<T> &m2)
869 for (
int i = 0; i < 3; i++)
871 for (
int j = 0; j < 3; j++)
873 for (
int k = 0; k < 3; k++)
875 mOut[i][j] += m1[i][k] * m2[k][j];
884 Matrix3x3<T> operator* (
const Matrix3x3<T> &m1,
const Matrix3x3<T> &m2)
886 return mul( m1, m2 );
891 typedef unsigned int uint;
893 typedef Vector2<float> float2;
894 typedef Vector3<float> float3;
895 typedef Vector4<float> float4;
897 typedef Matrix4x4<float> float4x4;
898 typedef Matrix3x3<float> float3x3;
902 inline float4x4 identityMatrix()
904 return float4x4(1, 0, 0, 0,
910 inline float4x4 translationMatrix(
float x,
float y,
float z)
912 return float4x4 (1, 0, 0, 0,
918 inline float4x4 translationMatrix(
const float3 &v )
920 return translationMatrix( v.x, v.y, v.z );
924 inline float4x4 scaleMatrix(
float x,
float y,
float z)
926 return float4x4(x, 0, 0, 0,
932 inline float4x4 rotationX(
float angleInRadians)
934 float sinAngle = sinf(angleInRadians);
935 float cosAngle = cosf(angleInRadians);
939 mOut._11 = 1.0f; mOut._12 = 0.0f; mOut._13 = 0.0f; mOut._14 = 0.0f;
940 mOut._21 = 0.0f; mOut._22 = cosAngle; mOut._23 = -sinAngle; mOut._24 = 0.0f;
941 mOut._31 = 0.0f; mOut._32 = sinAngle; mOut._33 = cosAngle; mOut._34 = 0.0f;
942 mOut._41 = 0.0f; mOut._42 = 0.0f; mOut._43 = 0.0f; mOut._44 = 1.0f;
947 inline float4x4 rotationY(
float angleInRadians)
949 float sinAngle = sinf(angleInRadians);
950 float cosAngle = cosf(angleInRadians);
954 mOut._11 = cosAngle; mOut._12 = 0.0f; mOut._13 = sinAngle; mOut._14 = 0.0f;
955 mOut._21 = 0.0f; mOut._22 = 1.0f; mOut._23 = 0.0f; mOut._24 = 0.0f;
956 mOut._31 = -sinAngle; mOut._32 = 0.0f; mOut._33 = cosAngle; mOut._34 = 0.0f;
957 mOut._41 = 0.0f; mOut._42 = 0.0f; mOut._43 = 0.0f; mOut._44 = 1.0f;
962 inline float4x4 rotationZ(
float angleInRadians)
964 float sinAngle = sinf(angleInRadians);
965 float cosAngle = cosf(angleInRadians);
969 mOut._11 = cosAngle; mOut._12 = -sinAngle; mOut._13 = 0.0f; mOut._14 = 0.0f;
970 mOut._21 = sinAngle; mOut._22 = cosAngle; mOut._23 = 0.0f; mOut._24 = 0.0f;
971 mOut._31 = 0.0f; mOut._32 = 0.0f; mOut._33 = 1.0f; mOut._34 = 0.0f;
972 mOut._41 = 0.0f; mOut._42 = 0.0f; mOut._43 = 0.0f; mOut._44 = 1.0f;
978 inline float4x4 rotationArbitrary(float3 axis,
float degree)
980 UNSUPPORTED(
"This function is not tested, it might be incorrect");
982 axis = normalize(axis);
984 float angleInRadians = degree * (PI_F / 180.0f);
986 float sinAngle = sinf(angleInRadians);
987 float cosAngle = cosf(angleInRadians);
988 float oneMinusCosAngle = 1 - cosAngle;
992 mOut._11 = 1.0f + oneMinusCosAngle * (axis.x * axis.x - 1.0f);
993 mOut._12 = axis.z * sinAngle + oneMinusCosAngle * axis.x * axis.y;
994 mOut._13 = -axis.y * sinAngle + oneMinusCosAngle * axis.x * axis.z;
997 mOut._21 = -axis.z * sinAngle + oneMinusCosAngle * axis.y * axis.x;
998 mOut._22 = 1.0f + oneMinusCosAngle * (axis.y * axis.y - 1.0f);
999 mOut._23 = axis.x * sinAngle + oneMinusCosAngle * axis.y * axis.z;
1002 mOut._31 = axis.y * sinAngle + oneMinusCosAngle * axis.z * axis.x;
1003 mOut._32 = -axis.x * sinAngle + oneMinusCosAngle * axis.z * axis.y;
1004 mOut._33 = 1.0f + oneMinusCosAngle * (axis.z * axis.z - 1.0f);
1015 inline float4x4 ViewMatrixFromBasis(
const float3 &f3X,
const float3 &f3Y,
const float3 &f3Z )
1017 return float4x4( f3X.x, f3Y.x, f3Z.x, 0,
1018 f3X.y, f3Y.y, f3Z.y, 0,
1019 f3X.z, f3Y.z, f3Z.z, 0,
1023 inline void SetNearFarClipPlanes( float4x4 &ProjMatrix,
float zNear,
float zFar,
bool bIsDirectX )
1027 ProjMatrix._33 = zFar / (zFar - zNear);
1028 ProjMatrix._43 = -zNear * zFar / (zFar - zNear);
1048 ProjMatrix._33 = -(-(zFar + zNear) / (zFar - zNear));
1049 ProjMatrix._43 = -2.0f * zNear * zFar / (zFar - zNear);
1050 ProjMatrix._34 = -(-1);
1054 inline void GetNearFarPlaneFromProjMatrix(
const float4x4 &ProjMatrix,
float &zNear,
float &zFar,
bool bIsDirectX )
1058 zNear = -ProjMatrix._43 / ProjMatrix._33;
1059 zFar = ProjMatrix._33 / (ProjMatrix._33 - 1) * zNear;
1063 zNear = ProjMatrix._43 / (-1.f - ProjMatrix._33);
1064 zFar = ProjMatrix._43 / (+1.f - ProjMatrix._33);
1068 inline float4x4 Projection(
float fov,
float aspectRatio,
float zNear,
float zFar,
bool bIsDirectX)
1071 float yScale = 1.0f / tan(fov / 2.0f);
1072 float xScale = yScale / aspectRatio;
1076 SetNearFarClipPlanes( mOut, zNear, zFar, bIsDirectX );
1087 inline Quaternion RotationFromAxisAngle(
const float3& axis,
float angle)
1090 float norm = length(axis);
1091 float sina2 = sin(0.5f * angle);
1092 out.q[0] = sina2 * axis[0] / norm;
1093 out.q[1] = sina2 * axis[1] / norm;
1094 out.q[2] = sina2 * axis[2] / norm;
1095 out.q[3] = cos(0.5f * angle);
1099 inline void AxisAngleFromRotation(float3& outAxis,
float& outAngle,
const Quaternion& quat)
1101 float sina2 = sqrt(quat.q[0]*quat.q[0] + quat.q[1]*quat.q[1] + quat.q[2]*quat.q[2]);
1102 outAngle = 2.0f * atan2(sina2, quat.q[3]);
1103 float r = (sina2 > 0) ? (1.0f / sina2) : 0;
1104 outAxis[0] = r * quat.q[0];
1105 outAxis[1] = r * quat.q[1];
1106 outAxis[2] = r * quat.q[2];
1109 inline float4x4 QuaternionToMatrix(
const Quaternion& quat)
1112 float yy2 = 2.0f * quat.q[1] * quat.q[1];
1113 float xy2 = 2.0f * quat.q[0] * quat.q[1];
1114 float xz2 = 2.0f * quat.q[0] * quat.q[2];
1115 float yz2 = 2.0f * quat.q[1] * quat.q[2];
1116 float zz2 = 2.0f * quat.q[2] * quat.q[2];
1117 float wz2 = 2.0f * quat.q[3] * quat.q[2];
1118 float wy2 = 2.0f * quat.q[3] * quat.q[1];
1119 float wx2 = 2.0f * quat.q[3] * quat.q[0];
1120 float xx2 = 2.0f * quat.q[0] * quat.q[0];
1121 out[0][0] = - yy2 - zz2 + 1.0f;
1122 out[0][1] = xy2 + wz2;
1123 out[0][2] = xz2 - wy2;
1125 out[1][0] = xy2 - wz2;
1126 out[1][1] = - xx2 - zz2 + 1.0f;
1127 out[1][2] = yz2 + wx2;
1129 out[2][0] = xz2 + wy2;
1130 out[2][1] = yz2 - wx2;
1131 out[2][2] = - xx2 - yy2 + 1.0f;
1133 out[3][0] = out[3][1] = out[3][2] = 0;
1138 inline float determinant(
const float3x3& m )
1141 det += m._11 * (m._22*m._33 - m._32*m._23);
1142 det -= m._12 * (m._21*m._33 - m._31*m._23);
1143 det += m._13 * (m._21*m._32 - m._31*m._22);
1148 inline float determinant(
const float4x4& m )
1152 det += m._11 * determinant(
1153 float3x3 ( m._22,m._23,m._24,
1155 m._42,m._43,m._44) );
1157 det -= m._12 * determinant(
1158 float3x3( m._21,m._23,m._24,
1160 m._41,m._43,m._44) );
1162 det += m._13 * determinant(
1163 float3x3( m._21,m._22,m._24,
1165 m._41,m._42,m._44) );
1167 det -= m._14 * determinant(
1168 float3x3( m._21,m._22,m._23,
1170 m._41,m._42,m._43) );
1175 inline float4x4 inverseMatrix(
const float4x4& m)
1180 inv._11 = determinant(
1181 float3x3( m._22, m._23, m._24,
1182 m._32, m._33, m._34,
1183 m._42, m._43, m._44 ) );
1185 inv._12 = -determinant(
1186 float3x3( m._21, m._23, m._24,
1187 m._31, m._33, m._34,
1188 m._41, m._43, m._44) );
1190 inv._13 = determinant(
1191 float3x3 ( m._21, m._22, m._24,
1192 m._31, m._32, m._34,
1193 m._41, m._42, m._44) );
1195 inv._14 = -determinant(
1196 float3x3 ( m._21, m._22, m._23,
1197 m._31, m._32, m._33,
1198 m._41, m._42, m._43) );
1202 inv._21 = -determinant(
1203 float3x3( m._12, m._13, m._14,
1204 m._32, m._33, m._34,
1205 m._42, m._43, m._44) );
1207 inv._22 = determinant(
1208 float3x3( m._11, m._13, m._14,
1209 m._31, m._33, m._34,
1210 m._41, m._43, m._44) );
1212 inv._23 = -determinant(
1213 float3x3( m._11, m._12, m._14,
1214 m._31, m._32, m._34,
1215 m._41, m._42, m._44) );
1217 inv._24 = determinant(
1218 float3x3( m._11, m._12, m._13,
1219 m._31, m._32, m._33,
1220 m._41, m._42, m._43) );
1224 inv._31 = determinant(
1225 float3x3( m._12,m._13,m._14,
1227 m._42,m._43,m._44) );
1229 inv._32 = -determinant(
1230 float3x3( m._11,m._13,m._14,
1232 m._41,m._43,m._44) );
1234 inv._33 = determinant(
1235 float3x3( m._11,m._12,m._14,
1237 m._41,m._42,m._44) );
1239 inv._34 = -determinant(
1240 float3x3( m._11,m._12,m._13,
1242 m._41,m._42,m._43) );
1245 inv._41 = -determinant(
1246 float3x3( m._12, m._13, m._14,
1247 m._22, m._23, m._24,
1248 m._32, m._33, m._34) );
1250 inv._42 = determinant(
1251 float3x3( m._11, m._13, m._14,
1252 m._21, m._23, m._24,
1253 m._31, m._33, m._34) );
1255 inv._43 = -determinant(
1256 float3x3( m._11, m._12, m._14,
1257 m._21, m._22, m._24,
1258 m._31, m._32, m._34) );
1260 inv._44 = determinant(
1261 float3x3( m._11, m._12, m._13,
1262 m._21, m._22, m._23,
1263 m._31, m._32, m._33) );
1265 auto det = m._11 * inv._11 + m._12 * inv._12 + m._13 * inv._13 + m._14 * inv._14;
1266 inv = transposeMatrix(inv);
1274 template<
typename T>
1275 Vector2<T> max(
const Vector2<T> &Left,
const Vector2<T> &Right )
1278 std::max( Left.x, Right.x ),
1279 std::max( Left.y, Right.y )
1283 template<
typename T>
1284 Vector3<T> max(
const Vector3<T> &Left,
const Vector3<T> &Right )
1287 std::max( Left.x, Right.x ),
1288 std::max( Left.y, Right.y ),
1289 std::max( Left.z, Right.z )
1293 template<
typename T>
1294 Vector4<T> max(
const Vector4<T> &Left,
const Vector4<T> &Right )
1297 std::max( Left.x, Right.x ),
1298 std::max( Left.y, Right.y ),
1299 std::max( Left.z, Right.z ),
1300 std::max( Left.w, Right.w )
1305 template<
typename T>
1306 Vector2<T> min(
const Vector2<T> &Left,
const Vector2<T> &Right )
1309 std::min( Left.x, Right.x ),
1310 std::min( Left.y, Right.y )
1314 template<
typename T>
1315 Vector3<T> min(
const Vector3<T> &Left,
const Vector3<T> &Right )
1318 std::min( Left.x, Right.x ),
1319 std::min( Left.y, Right.y ),
1320 std::min( Left.z, Right.z )
1324 template<
typename T>
1325 Vector4<T> min(
const Vector4<T> &Left,
const Vector4<T> &Right )
1328 std::min( Left.x, Right.x ),
1329 std::min( Left.y, Right.y ),
1330 std::min( Left.z, Right.z ),
1331 std::min( Left.w, Right.w )
1336 template<
typename T>
1337 struct hash<Vector2<T>>
1339 size_t operator()(
const Vector2<T> &v2 )
const 1341 return Diligent::ComputeHash(v2.x, v2.y);
1345 template<
typename T>
1346 struct hash<Vector3<T>>
1348 size_t operator()(
const Vector3<T> &v3 )
const 1350 return Diligent::ComputeHash(v3.x, v3.y, v3.z);
1354 template<
typename T>
1355 struct hash<Vector4<T>>
1357 size_t operator()(
const Vector4<T> &v4 )
const 1359 return Diligent::ComputeHash(v4.x, v4.y, v4.z, v4.w);
1363 template<
typename T>
1364 struct hash<Matrix3x3<T>>
1366 size_t operator()(
const Matrix3x3<T> &m )
const 1368 return Diligent::ComputeHash(
1369 m._m00, m._m01, m._m02,
1370 m._m10, m._m11, m._m12,
1371 m._m20, m._m21, m._m22
1376 template<
typename T>
1377 struct hash<Matrix4x4<T>>
1379 size_t operator()(
const Matrix4x4<T> &m )
const 1381 return Diligent::ComputeHash(
1382 m._m00, m._m01, m._m02, m._m03,
1383 m._m10, m._m11, m._m12, m._m13,
1384 m._m20, m._m21, m._m22, m._m23,
1385 m._m30, m._m31, m._m32, m._m33
Definition: AdvancedMath.h:316