| 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(max(JPH_VECTOR_ALIGNMENT, JPH_DVECTOR_ALIGNMENT)) DMat44 |
| 13 |
{ |
| 14 |
public: |
| 15 |
JPH_OVERRIDE_NEW_DELETE |
| 16 |
|
| 17 |
|
| 18 |
using Type = Vec4::Type; |
| 19 |
using DType = DVec3::Type; |
| 20 |
using DTypeArg = DVec3::TypeArg; |
| 21 |
|
| 22 |
|
| 23 |
using ArgType = DMat44Arg; |
| 24 |
|
| 25 |
|
| 26 |
DMat44() = default; |
| 27 |
JPH_INLINE DMat44(Vec4Arg inC1, Vec4Arg inC2, Vec4Arg inC3, DVec3Arg inC4); |
| 28 |
DMat44(const DMat44 &inM2) = default; |
| 29 |
DMat44 & operator = (const DMat44 &inM2) = default; |
| 30 |
JPH_INLINE explicit DMat44(Mat44Arg inM); |
| 31 |
JPH_INLINE DMat44(Mat44Arg inRot, DVec3Arg inT); |
| 32 |
JPH_INLINE DMat44(Type inC1, Type inC2, Type inC3, DTypeArg inC4); |
| 33 |
|
| 34 |
|
| 35 |
static JPH_INLINE DMat44 sZero(); |
| 36 |
|
| 37 |
|
| 38 |
static JPH_INLINE DMat44 sIdentity(); |
| 39 |
|
| 40 |
|
| 41 |
static JPH_INLINE DMat44 sRotation(QuatArg inQuat) { return DMat44(Mat44::sRotation(inQuat), DVec3::sZero()); } |
| 42 |
|
| 43 |
|
| 44 |
static JPH_INLINE DMat44 sTranslation(DVec3Arg inV) { return DMat44(Vec4(1, 0, 0, 0), Vec4(0, 1, 0, 0), Vec4(0, 0, 1, 0), inV); } |
| 45 |
|
| 46 |
|
| 47 |
static JPH_INLINE DMat44 sRotationTranslation(QuatArg inR, DVec3Arg inT) { return DMat44(Mat44::sRotation(inR), inT); } |
| 48 |
|
| 49 |
|
| 50 |
static JPH_INLINE DMat44 sInverseRotationTranslation(QuatArg inR, DVec3Arg inT); |
| 51 |
|
| 52 |
|
| 53 |
static JPH_INLINE DMat44 sScale(Vec3Arg inV) { return DMat44(Mat44::sScale(inV), DVec3::sZero()); } |
| 54 |
|
| 55 |
|
| 56 |
JPH_INLINE Mat44 ToMat44() const { return Mat44(mCol[0], mCol[1], mCol[2], Vec3(mCol3)); } |
| 57 |
|
| 58 |
|
| 59 |
JPH_INLINE bool operator == (DMat44Arg inM2) const; |
| 60 |
JPH_INLINE bool operator != (DMat44Arg inM2) const { return !(*this == inM2); } |
| 61 |
|
| 62 |
|
| 63 |
JPH_INLINE bool IsClose(DMat44Arg inM2, float inMaxDistSq = 1.0e-12f) const; |
| 64 |
|
| 65 |
|
| 66 |
JPH_INLINE DMat44 operator * (Mat44Arg inM) const; |
| 67 |
|
| 68 |
|
| 69 |
JPH_INLINE DMat44 operator * (DMat44Arg inM) const; |
| 70 |
|
| 71 |
|
| 72 |
JPH_INLINE DVec3 operator * (Vec3Arg inV) const; |
| 73 |
|
| 74 |
|
| 75 |
JPH_INLINE DVec3 operator * (DVec3Arg inV) const; |
| 76 |
|
| 77 |
|
| 78 |
JPH_INLINE Vec3 Multiply3x3(Vec3Arg inV) const { return GetRotation().Multiply3x3(inV); } |
| 79 |
|
| 80 |
|
| 81 |
JPH_INLINE DVec3 Multiply3x3(DVec3Arg inV) const; |
| 82 |
|
| 83 |
|
| 84 |
JPH_INLINE Vec3 Multiply3x3Transposed(Vec3Arg inV) const { return GetRotation().Multiply3x3Transposed(inV); } |
| 85 |
|
| 86 |
|
| 87 |
JPH_INLINE DMat44 PreScaled(Vec3Arg inScale) const; |
| 88 |
|
| 89 |
|
| 90 |
JPH_INLINE DMat44 PostScaled(Vec3Arg inScale) const; |
| 91 |
|
| 92 |
|
| 93 |
JPH_INLINE DMat44 PreTranslated(Vec3Arg inTranslation) const; |
| 94 |
|
| 95 |
|
| 96 |
JPH_INLINE DMat44 PreTranslated(DVec3Arg inTranslation) const; |
| 97 |
|
| 98 |
|
| 99 |
JPH_INLINE DMat44 PostTranslated(Vec3Arg inTranslation) const; |
| 100 |
|
| 101 |
|
| 102 |
JPH_INLINE DMat44 PostTranslated(DVec3Arg inTranslation) const; |
| 103 |
|
| 104 |
|
| 105 |
JPH_INLINE Vec3 GetAxisX() const { return Vec3(mCol[0]); } |
| 106 |
JPH_INLINE void SetAxisX(Vec3Arg inV) { mCol[0] = Vec4(inV, 0.0f); } |
| 107 |
JPH_INLINE Vec3 GetAxisY() const { return Vec3(mCol[1]); } |
| 108 |
JPH_INLINE void SetAxisY(Vec3Arg inV) { mCol[1] = Vec4(inV, 0.0f); } |
| 109 |
JPH_INLINE Vec3 GetAxisZ() const { return Vec3(mCol[2]); } |
| 110 |
JPH_INLINE void SetAxisZ(Vec3Arg inV) { mCol[2] = Vec4(inV, 0.0f); } |
| 111 |
JPH_INLINE DVec3 GetTranslation() const { return mCol3; } |
| 112 |
JPH_INLINE void SetTranslation(DVec3Arg inV) { mCol3 = inV; } |
| 113 |
JPH_INLINE Vec3 GetColumn3(uint inCol) const { JPH_ASSERT(inCol < 3); return Vec3(mCol[inCol]); } |
| 114 |
JPH_INLINE void SetColumn3(uint inCol, Vec3Arg inV) { JPH_ASSERT(inCol < 3); mCol[inCol] = Vec4(inV, 0.0f); } |
| 115 |
JPH_INLINE Vec4 GetColumn4(uint inCol) const { JPH_ASSERT(inCol < 3); return mCol[inCol]; } |
| 116 |
JPH_INLINE void SetColumn4(uint inCol, Vec4Arg inV) { JPH_ASSERT(inCol < 3); mCol[inCol] = inV; } |
| 117 |
|
| 118 |
|
| 119 |
JPH_INLINE Mat44 Transposed3x3() const { return GetRotation().Transposed3x3(); } |
| 120 |
|
| 121 |
|
| 122 |
JPH_INLINE DMat44 Inversed() const; |
| 123 |
|
| 124 |
|
| 125 |
JPH_INLINE DMat44 InversedRotationTranslation() const; |
| 126 |
|
| 127 |
|
| 128 |
JPH_INLINE Mat44 GetRotation() const { return Mat44(mCol[0], mCol[1], mCol[2], Vec4(0, 0, 0, 1)); } |
| 129 |
|
| 130 |
|
| 131 |
JPH_INLINE void SetRotation(Mat44Arg inRotation); |
| 132 |
|
| 133 |
|
| 134 |
JPH_INLINE Quat GetQuaternion() const { return GetRotation().GetQuaternion(); } |
| 135 |
|
| 136 |
|
| 137 |
JPH_INLINE Mat44 GetDirectionPreservingMatrix() const { return GetRotation().Inversed3x3().Transposed3x3(); } |
| 138 |
|
| 139 |
|
| 140 |
JPH_INLINE DMat44 Decompose(Vec3 &outScale) const { return DMat44(GetRotation().Decompose(outScale), mCol3); } |
| 141 |
|
| 142 |
|
| 143 |
friend ostream & operator << (ostream &inStream, DMat44Arg inM) |
| 144 |
{ |
| 145 |
inStream << inM.mCol[0] << ", " << inM.mCol[1] << ", " << inM.mCol[2] << ", " << inM.mCol3; |
| 146 |
return inStream; |
| 147 |
} |
| 148 |
|
| 149 |
private: |
| 150 |
Vec4 mCol[3]; |
| 151 |
DVec3 mCol3; |
| 152 |
}; |
| 153 |
|
| 154 |
static_assert(std::is_trivial<DMat44>(), "Is supposed to be a trivial type!"); |
| 155 |
|
| 156 |
JPH_NAMESPACE_END |
| 157 |
|
| 158 |
#include "DMat44.inl" |