Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
DMat44.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2022 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
10
12class [[nodiscard]] alignas(JPH_DVECTOR_ALIGNMENT) DMat44
13{
14public:
16
17 // Underlying column type
21
22 // Argument type
24
26 DMat44() = default;
27 JPH_INLINE DMat44(Vec4Arg inC1, Vec4Arg inC2, Vec4Arg inC3, DVec3Arg inC4);
28 DMat44(const DMat44 &inM2) = default;
29 JPH_INLINE explicit DMat44(Mat44Arg inM);
30 JPH_INLINE DMat44(Mat44Arg inRot, DVec3Arg inT);
31 JPH_INLINE DMat44(Type inC1, Type inC2, Type inC3, DTypeArg inC4);
32
34 static JPH_INLINE DMat44 sZero();
35
37 static JPH_INLINE DMat44 sIdentity();
38
40 static JPH_INLINE DMat44 sRotation(QuatArg inQuat) { return DMat44(Mat44::sRotation(inQuat), DVec3::sZero()); }
41
43 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); }
44
46 static JPH_INLINE DMat44 sRotationTranslation(QuatArg inR, DVec3Arg inT) { return DMat44(Mat44::sRotation(inR), inT); }
47
49 static JPH_INLINE DMat44 sInverseRotationTranslation(QuatArg inR, DVec3Arg inT);
50
52 static JPH_INLINE DMat44 sScale(Vec3Arg inV) { return DMat44(Mat44::sScale(inV), DVec3::sZero()); }
53
55 JPH_INLINE Mat44 ToMat44() const { return Mat44(mCol[0], mCol[1], mCol[2], Vec3(mCol3)); }
56
58 JPH_INLINE bool operator == (DMat44Arg inM2) const;
59 JPH_INLINE bool operator != (DMat44Arg inM2) const { return !(*this == inM2); }
60
62 JPH_INLINE bool IsClose(DMat44Arg inM2, float inMaxDistSq = 1.0e-12f) const;
63
65 JPH_INLINE DMat44 operator * (Mat44Arg inM) const;
66
68 JPH_INLINE DMat44 operator * (DMat44Arg inM) const;
69
71 JPH_INLINE DVec3 operator * (Vec3Arg inV) const;
72
74 JPH_INLINE DVec3 operator * (DVec3Arg inV) const;
75
77 JPH_INLINE Vec3 Multiply3x3(Vec3Arg inV) const { return GetRotation().Multiply3x3(inV); }
78
80 JPH_INLINE DVec3 Multiply3x3(DVec3Arg inV) const;
81
83 JPH_INLINE Vec3 Multiply3x3Transposed(Vec3Arg inV) const { return GetRotation().Multiply3x3Transposed(inV); }
84
86 JPH_INLINE DMat44 PreScaled(Vec3Arg inScale) const;
87
89 JPH_INLINE DMat44 PostScaled(Vec3Arg inScale) const;
90
92 JPH_INLINE DMat44 PreTranslated(Vec3Arg inTranslation) const;
93
95 JPH_INLINE DMat44 PreTranslated(DVec3Arg inTranslation) const;
96
98 JPH_INLINE DMat44 PostTranslated(Vec3Arg inTranslation) const;
99
101 JPH_INLINE DMat44 PostTranslated(DVec3Arg inTranslation) const;
102
104 JPH_INLINE Vec3 GetAxisX() const { return Vec3(mCol[0]); }
105 JPH_INLINE void SetAxisX(Vec3Arg inV) { mCol[0] = Vec4(inV, 0.0f); }
106 JPH_INLINE Vec3 GetAxisY() const { return Vec3(mCol[1]); }
107 JPH_INLINE void SetAxisY(Vec3Arg inV) { mCol[1] = Vec4(inV, 0.0f); }
108 JPH_INLINE Vec3 GetAxisZ() const { return Vec3(mCol[2]); }
109 JPH_INLINE void SetAxisZ(Vec3Arg inV) { mCol[2] = Vec4(inV, 0.0f); }
110 JPH_INLINE DVec3 GetTranslation() const { return mCol3; }
111 JPH_INLINE void SetTranslation(DVec3Arg inV) { mCol3 = inV; }
112 JPH_INLINE Vec3 GetColumn3(uint inCol) const { JPH_ASSERT(inCol < 3); return Vec3(mCol[inCol]); }
113 JPH_INLINE void SetColumn3(uint inCol, Vec3Arg inV) { JPH_ASSERT(inCol < 3); mCol[inCol] = Vec4(inV, 0.0f); }
114 JPH_INLINE Vec4 GetColumn4(uint inCol) const { JPH_ASSERT(inCol < 3); return mCol[inCol]; }
115 JPH_INLINE void SetColumn4(uint inCol, Vec4Arg inV) { JPH_ASSERT(inCol < 3); mCol[inCol] = inV; }
116
118 JPH_INLINE DMat44 Inversed() const;
119
121 JPH_INLINE DMat44 InversedRotationTranslation() const;
122
124 JPH_INLINE Mat44 GetRotation() const { return Mat44(mCol[0], mCol[1], mCol[2], Vec4(0, 0, 0, 1)); }
125
127 JPH_INLINE void SetRotation(Mat44Arg inRotation);
128
130 JPH_INLINE Quat GetQuaternion() const { return GetRotation().GetQuaternion(); }
131
133 JPH_INLINE Mat44 GetDirectionPreservingMatrix() const { return GetRotation().Inversed3x3().Transposed3x3(); }
134
136 JPH_INLINE DMat44 Decompose(Vec3 &outScale) const { return DMat44(GetRotation().Decompose(outScale), mCol3); }
137
139 friend ostream & operator << (ostream &inStream, DMat44Arg inM)
140 {
141 inStream << inM.mCol[0] << ", " << inM.mCol[1] << ", " << inM.mCol[2] << ", " << inM.mCol3;
142 return inStream;
143 }
144
145private:
146 Vec4 mCol[3];
147 DVec3 mCol3;
148};
149
150static_assert(is_trivial<DMat44>(), "Is supposed to be a trivial type!");
151
153
154#include "DMat44.inl"
unsigned int uint
Definition: Core.h:309
#define JPH_NAMESPACE_END
Definition: Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
DVec3 operator*(double inV1, DVec3Arg inV2)
Definition: DVec3.inl:447
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
const DMat44 & DMat44Arg
Definition: MathTypes.h:32
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
Holds a 4x4 matrix of floats with the last column consisting of doubles.
Definition: DMat44.h:13
JPH_INLINE void SetColumn4(uint inCol, Vec4Arg inV)
Definition: DMat44.h:115
DVec3::Type DType
Definition: DMat44.h:19
DVec3::TypeArg DTypeArg
Definition: DMat44.h:20
JPH_INLINE void SetColumn3(uint inCol, Vec3Arg inV)
Definition: DMat44.h:113
JPH_INLINE void SetTranslation(DVec3Arg inV)
Definition: DMat44.h:111
JPH_INLINE void SetAxisZ(Vec3Arg inV)
Definition: DMat44.h:109
JPH_INLINE void SetAxisX(Vec3Arg inV)
Definition: DMat44.h:105
JPH_INLINE Mat44 GetDirectionPreservingMatrix() const
Get matrix that transforms a direction with the same transform as this matrix (length is not preserve...
Definition: DMat44.h:133
JPH_INLINE Vec4 GetColumn4(uint inCol) const
Definition: DMat44.h:114
static JPH_INLINE DMat44 sRotationTranslation(QuatArg inR, DVec3Arg inT)
Get matrix that rotates and translates.
Definition: DMat44.h:46
JPH_INLINE Mat44 ToMat44() const
Convert to Mat44 rounding to nearest.
Definition: DMat44.h:55
JPH_INLINE Vec3 Multiply3x3Transposed(Vec3Arg inV) const
Multiply vector by only 3x3 part of the transpose of the matrix ( )
Definition: DMat44.h:83
static JPH_INLINE DMat44 sScale(Vec3Arg inV)
Get matrix that scales (produces a matrix with (inV, 1) on its diagonal)
Definition: DMat44.h:52
DMat44()=default
Constructor.
JPH_INLINE void SetAxisY(Vec3Arg inV)
Definition: DMat44.h:107
JPH_INLINE Quat GetQuaternion() const
Convert to quaternion.
Definition: DMat44.h:130
static JPH_INLINE DMat44 sRotation(QuatArg inQuat)
Rotate from quaternion.
Definition: DMat44.h:40
JPH_INLINE Vec3 Multiply3x3(Vec3Arg inV) const
Multiply vector by only 3x3 part of the matrix.
Definition: DMat44.h:77
static JPH_INLINE DMat44 sTranslation(DVec3Arg inV)
Get matrix that translates.
Definition: DMat44.h:43
JPH_INLINE Vec3 GetAxisX() const
Access to the columns.
Definition: DMat44.h:104
JPH_INLINE DMat44 Decompose(Vec3 &outScale) const
Works identical to Mat44::Decompose.
Definition: DMat44.h:136
DMat44(const DMat44 &inM2)=default
JPH_INLINE DVec3 GetTranslation() const
Definition: DMat44.h:110
JPH_INLINE Mat44 GetRotation() const
Get rotation part only (note: retains the first 3 values from the bottom row)
Definition: DMat44.h:124
Vec4::Type Type
Definition: DMat44.h:18
JPH_INLINE Vec3 GetColumn3(uint inCol) const
Definition: DMat44.h:112
JPH_INLINE Vec3 GetAxisZ() const
Definition: DMat44.h:108
JPH_INLINE Vec3 GetAxisY() const
Definition: DMat44.h:106
Definition: DVec3.h:14
{ double mData[4] Type
Definition: DVec3.h:29
const Type & TypeArg
Definition: DVec3.h:30
static JPH_INLINE DVec3 sZero()
Vector with all zeros.
Definition: DVec3.inl:120
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition: Mat44.h:13
JPH_INLINE Mat44 Transposed3x3() const
Transpose 3x3 subpart of matrix.
Definition: Mat44.inl:493
static JPH_INLINE Mat44 sScale(float inScale)
Get matrix that scales uniformly.
Definition: Mat44.inl:163
static JPH_INLINE Mat44 sRotation(Vec3Arg inAxis, float inAngle)
Rotate around arbitrary axis.
Definition: Mat44.inl:139
JPH_INLINE Mat44 Inversed3x3() const
Inverse 3x3 matrix.
Definition: Mat44.inl:883
Definition: Quat.h:33
Definition: Vec3.h:16
Definition: Vec4.h:14
{ float mData[4] Type
Definition: Vec4.h:24