| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Math/MathTypes.h> |
| 8 |
|
| 9 |
JPH_NAMESPACE_BEGIN |
| 10 |
|
| 11 |
|
| 12 |
class [[nodiscard]] alignas(JPH_VECTOR_ALIGNMENT) Mat44 |
| 13 |
{ |
| 14 |
public: |
| 15 |
JPH_OVERRIDE_NEW_DELETE |
| 16 |
|
| 17 |
|
| 18 |
using Type = Vec4::Type; |
| 19 |
|
| 20 |
|
| 21 |
using ArgType = Mat44Arg; |
| 22 |
|
| 23 |
|
| 24 |
Mat44() = default; |
| 25 |
JPH_INLINE Mat44(Vec4Arg inC1, Vec4Arg inC2, Vec4Arg inC3, Vec4Arg inC4); |
| 26 |
JPH_INLINE Mat44(Vec4Arg inC1, Vec4Arg inC2, Vec4Arg inC3, Vec3Arg inC4); |
| 27 |
Mat44(const Mat44 &inM2) = default; |
| 28 |
Mat44 & operator = (const Mat44 &inM2) = default; |
| 29 |
JPH_INLINE Mat44(Type inC1, Type inC2, Type inC3, Type inC4); |
| 30 |
|
| 31 |
|
| 32 |
static JPH_INLINE Mat44 sZero(); |
| 33 |
|
| 34 |
|
| 35 |
static JPH_INLINE Mat44 sIdentity(); |
| 36 |
|
| 37 |
|
| 38 |
static JPH_INLINE Mat44 sNaN(); |
| 39 |
|
| 40 |
|
| 41 |
static JPH_INLINE Mat44 sLoadFloat4x4(const Float4 *inV); |
| 42 |
|
| 43 |
|
| 44 |
static JPH_INLINE Mat44 sLoadFloat4x4Aligned(const Float4 *inV); |
| 45 |
|
| 46 |
|
| 47 |
static JPH_INLINE Mat44 sRotationX(float inX); |
| 48 |
static JPH_INLINE Mat44 sRotationY(float inY); |
| 49 |
static JPH_INLINE Mat44 sRotationZ(float inZ); |
| 50 |
|
| 51 |
|
| 52 |
static JPH_INLINE Mat44 sRotation(Vec3Arg inAxis, float inAngle); |
| 53 |
|
| 54 |
|
| 55 |
static JPH_INLINE Mat44 sRotation(QuatArg inQuat); |
| 56 |
|
| 57 |
|
| 58 |
static JPH_INLINE Mat44 sTranslation(Vec3Arg inV); |
| 59 |
|
| 60 |
|
| 61 |
static JPH_INLINE Mat44 sRotationTranslation(QuatArg inR, Vec3Arg inT); |
| 62 |
|
| 63 |
|
| 64 |
static JPH_INLINE Mat44 sInverseRotationTranslation(QuatArg inR, Vec3Arg inT); |
| 65 |
|
| 66 |
|
| 67 |
static JPH_INLINE Mat44 sScale(float inScale); |
| 68 |
|
| 69 |
|
| 70 |
static JPH_INLINE Mat44 sScale(Vec3Arg inV); |
| 71 |
|
| 72 |
|
| 73 |
static JPH_INLINE Mat44 sOuterProduct(Vec3Arg inV1, Vec3Arg inV2); |
| 74 |
|
| 75 |
|
| 76 |
static JPH_INLINE Mat44 sCrossProduct(Vec3Arg inV); |
| 77 |
|
| 78 |
|
| 79 |
static JPH_INLINE Mat44 sQuatLeftMultiply(QuatArg inQ); |
| 80 |
|
| 81 |
|
| 82 |
static JPH_INLINE Mat44 sQuatRightMultiply(QuatArg inQ); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
static JPH_INLINE Mat44 sLookAt(Vec3Arg inPos, Vec3Arg inTarget, Vec3Arg inUp); |
| 89 |
|
| 90 |
|
| 91 |
static JPH_INLINE Mat44 sPerspective(float inFovY, float inAspect, float inNear, float inFar); |
| 92 |
|
| 93 |
|
| 94 |
JPH_INLINE float operator () (uint inRow, uint inColumn) const { JPH_ASSERT(inRow < 4); JPH_ASSERT(inColumn < 4); return mCol[inColumn].mF32[inRow]; } |
| 95 |
JPH_INLINE float & operator () (uint inRow, uint inColumn) { JPH_ASSERT(inRow < 4); JPH_ASSERT(inColumn < 4); return mCol[inColumn].mF32[inRow]; } |
| 96 |
|
| 97 |
|
| 98 |
JPH_INLINE bool operator == (Mat44Arg inM2) const; |
| 99 |
JPH_INLINE bool operator != (Mat44Arg inM2) const { return !(*this == inM2); } |
| 100 |
|
| 101 |
|
| 102 |
JPH_INLINE bool IsClose(Mat44Arg inM2, float inMaxDistSq = 1.0e-12f) const; |
| 103 |
|
| 104 |
|
| 105 |
JPH_INLINE Mat44 operator * (Mat44Arg inM) const; |
| 106 |
|
| 107 |
|
| 108 |
JPH_INLINE Vec3 operator * (Vec3Arg inV) const; |
| 109 |
JPH_INLINE Vec4 operator * (Vec4Arg inV) const; |
| 110 |
|
| 111 |
|
| 112 |
JPH_INLINE Vec3 Multiply3x3(Vec3Arg inV) const; |
| 113 |
|
| 114 |
|
| 115 |
JPH_INLINE Vec3 Multiply3x3Transposed(Vec3Arg inV) const; |
| 116 |
|
| 117 |
|
| 118 |
JPH_INLINE Mat44 Multiply3x3(Mat44Arg inM) const; |
| 119 |
|
| 120 |
|
| 121 |
JPH_INLINE Mat44 Multiply3x3LeftTransposed(Mat44Arg inM) const; |
| 122 |
|
| 123 |
|
| 124 |
JPH_INLINE Mat44 Multiply3x3RightTransposed(Mat44Arg inM) const; |
| 125 |
|
| 126 |
|
| 127 |
JPH_INLINE Mat44 operator * (float inV) const; |
| 128 |
friend JPH_INLINE Mat44 operator * (float inV, Mat44Arg inM) { return inM * inV; } |
| 129 |
|
| 130 |
|
| 131 |
JPH_INLINE Mat44 & operator *= (float inV); |
| 132 |
|
| 133 |
|
| 134 |
JPH_INLINE Mat44 operator + (Mat44Arg inM) const; |
| 135 |
|
| 136 |
|
| 137 |
JPH_INLINE Mat44 operator - () const; |
| 138 |
|
| 139 |
|
| 140 |
JPH_INLINE Mat44 operator - (Mat44Arg inM) const; |
| 141 |
|
| 142 |
|
| 143 |
JPH_INLINE Mat44 & operator += (Mat44Arg inM); |
| 144 |
|
| 145 |
|
| 146 |
JPH_INLINE Vec3 GetAxisX() const { return Vec3(mCol[0]); } |
| 147 |
JPH_INLINE void SetAxisX(Vec3Arg inV) { mCol[0] = Vec4(inV, 0.0f); } |
| 148 |
JPH_INLINE Vec3 GetAxisY() const { return Vec3(mCol[1]); } |
| 149 |
JPH_INLINE void SetAxisY(Vec3Arg inV) { mCol[1] = Vec4(inV, 0.0f); } |
| 150 |
JPH_INLINE Vec3 GetAxisZ() const { return Vec3(mCol[2]); } |
| 151 |
JPH_INLINE void SetAxisZ(Vec3Arg inV) { mCol[2] = Vec4(inV, 0.0f); } |
| 152 |
JPH_INLINE Vec3 GetTranslation() const { return Vec3(mCol[3]); } |
| 153 |
JPH_INLINE void SetTranslation(Vec3Arg inV) { mCol[3] = Vec4(inV, 1.0f); } |
| 154 |
JPH_INLINE Vec3 GetDiagonal3() const { return Vec3(mCol[0][0], mCol[1][1], mCol[2][2]); } |
| 155 |
JPH_INLINE void SetDiagonal3(Vec3Arg inV) { mCol[0][0] = inV.GetX(); mCol[1][1] = inV.GetY(); mCol[2][2] = inV.GetZ(); } |
| 156 |
JPH_INLINE Vec4 GetDiagonal4() const { return Vec4(mCol[0][0], mCol[1][1], mCol[2][2], mCol[3][3]); } |
| 157 |
JPH_INLINE void SetDiagonal4(Vec4Arg inV) { mCol[0][0] = inV.GetX(); mCol[1][1] = inV.GetY(); mCol[2][2] = inV.GetZ(); mCol[3][3] = inV.GetW(); } |
| 158 |
JPH_INLINE Vec3 GetColumn3(uint inCol) const { JPH_ASSERT(inCol < 4); return Vec3(mCol[inCol]); } |
| 159 |
JPH_INLINE void SetColumn3(uint inCol, Vec3Arg inV) { JPH_ASSERT(inCol < 4); mCol[inCol] = Vec4(inV, inCol == 3? 1.0f : 0.0f); } |
| 160 |
JPH_INLINE Vec4 GetColumn4(uint inCol) const { JPH_ASSERT(inCol < 4); return mCol[inCol]; } |
| 161 |
JPH_INLINE void SetColumn4(uint inCol, Vec4Arg inV) { JPH_ASSERT(inCol < 4); mCol[inCol] = inV; } |
| 162 |
|
| 163 |
|
| 164 |
JPH_INLINE void StoreFloat4x4(Float4 *outV) const; |
| 165 |
|
| 166 |
|
| 167 |
JPH_INLINE Mat44 Transposed() const; |
| 168 |
|
| 169 |
|
| 170 |
JPH_INLINE Mat44 Transposed3x3() const; |
| 171 |
|
| 172 |
|
| 173 |
JPH_INLINE Mat44 Inversed() const; |
| 174 |
|
| 175 |
|
| 176 |
JPH_INLINE Mat44 InversedRotationTranslation() const; |
| 177 |
|
| 178 |
|
| 179 |
JPH_INLINE float GetDeterminant3x3() const; |
| 180 |
|
| 181 |
|
| 182 |
JPH_INLINE Mat44 Adjointed3x3() const; |
| 183 |
|
| 184 |
|
| 185 |
JPH_INLINE Mat44 Inversed3x3() const; |
| 186 |
|
| 187 |
|
| 188 |
JPH_INLINE bool SetInversed3x3(Mat44Arg inM); |
| 189 |
|
| 190 |
|
| 191 |
JPH_INLINE Mat44 GetRotation() const; |
| 192 |
|
| 193 |
|
| 194 |
JPH_INLINE Mat44 GetRotationSafe() const; |
| 195 |
|
| 196 |
|
| 197 |
JPH_INLINE void SetRotation(Mat44Arg inRotation); |
| 198 |
|
| 199 |
|
| 200 |
JPH_INLINE Quat GetQuaternion() const; |
| 201 |
|
| 202 |
|
| 203 |
JPH_INLINE Mat44 GetDirectionPreservingMatrix() const { return GetRotation().Inversed3x3().Transposed3x3(); } |
| 204 |
|
| 205 |
|
| 206 |
JPH_INLINE Mat44 PreTranslated(Vec3Arg inTranslation) const; |
| 207 |
|
| 208 |
|
| 209 |
JPH_INLINE Mat44 PostTranslated(Vec3Arg inTranslation) const; |
| 210 |
|
| 211 |
|
| 212 |
JPH_INLINE Mat44 PreScaled(Vec3Arg inScale) const; |
| 213 |
|
| 214 |
|
| 215 |
JPH_INLINE Mat44 PostScaled(Vec3Arg inScale) const; |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
JPH_INLINE Mat44 Decompose(Vec3 &outScale) const; |
| 222 |
|
| 223 |
#ifndef JPH_DOUBLE_PRECISION |
| 224 |
|
| 225 |
JPH_INLINE Mat44 ToMat44() const { return *this; } |
| 226 |
#endif |
| 227 |
|
| 228 |
|
| 229 |
friend ostream & operator << (ostream &inStream, Mat44Arg inM) |
| 230 |
{ |
| 231 |
inStream << inM.mCol[0] << ", " << inM.mCol[1] << ", " << inM.mCol[2] << ", " << inM.mCol[3]; |
| 232 |
return inStream; |
| 233 |
} |
| 234 |
|
| 235 |
private: |
| 236 |
Vec4 mCol[4]; |
| 237 |
}; |
| 238 |
|
| 239 |
static_assert(std::is_trivial<Mat44>(), "Is supposed to be a trivial type!"); |
| 240 |
|
| 241 |
JPH_NAMESPACE_END |
| 242 |
|
| 243 |
#include "Mat44.inl" |