OpenBarnyard
 
Loading...
Searching...
No Matches
TMatrix44.h
Go to the documentation of this file.
1
11
12#pragma once
13#include "TQuaternion.h"
14#include "TPlane.h"
15
16#ifdef TRENDERINTERFACE_DX8
17# include <d3dx8math.h>
18#endif
19
21
30
32{
33public:
34 constexpr TMatrix44() = default;
35
36 constexpr TMatrix44( const TMatrix44& a_rMatrix )
37 : m_f11( a_rMatrix.m_f11 ), m_f12( a_rMatrix.m_f12 ), m_f13( a_rMatrix.m_f13 ), m_f14( a_rMatrix.m_f14 ), m_f21( a_rMatrix.m_f21 ), m_f22( a_rMatrix.m_f22 ), m_f23( a_rMatrix.m_f23 ), m_f24( a_rMatrix.m_f24 ), m_f31( a_rMatrix.m_f31 ), m_f32( a_rMatrix.m_f32 ), m_f33( a_rMatrix.m_f33 ), m_f34( a_rMatrix.m_f34 ), m_f41( a_rMatrix.m_f41 ), m_f42( a_rMatrix.m_f42 ), m_f43( a_rMatrix.m_f43 ), m_f44( a_rMatrix.m_f44 )
38 {}
39
40 constexpr TMatrix44(
41 TFLOAT a_f11,
42 TFLOAT a_f12,
43 TFLOAT a_f13,
44 TFLOAT a_f14,
45 TFLOAT a_f21,
46 TFLOAT a_f22,
47 TFLOAT a_f23,
48 TFLOAT a_f24,
49 TFLOAT a_f31,
50 TFLOAT a_f32,
51 TFLOAT a_f33,
52 TFLOAT a_f34,
53 TFLOAT a_f41,
54 TFLOAT a_f42,
55 TFLOAT a_f43,
56 TFLOAT a_f44
57 )
58 : m_f11( a_f11 ), m_f12( a_f12 ), m_f13( a_f13 ), m_f14( a_f14 ), m_f21( a_f21 ), m_f22( a_f22 ), m_f23( a_f23 ), m_f24( a_f24 ), m_f31( a_f31 ), m_f32( a_f32 ), m_f33( a_f33 ), m_f34( a_f34 ), m_f41( a_f41 ), m_f42( a_f42 ), m_f43( a_f43 ), m_f44( a_f44 )
59 {}
60
61 // $Barnyard: FUNCTION 0041fa30
62 constexpr void Set(
63 TFLOAT a_f11,
64 TFLOAT a_f12,
65 TFLOAT a_f13,
66 TFLOAT a_f14,
67 TFLOAT a_f21,
68 TFLOAT a_f22,
69 TFLOAT a_f23,
70 TFLOAT a_f24,
71 TFLOAT a_f31,
72 TFLOAT a_f32,
73 TFLOAT a_f33,
74 TFLOAT a_f34,
75 TFLOAT a_f41,
76 TFLOAT a_f42,
77 TFLOAT a_f43,
78 TFLOAT a_f44
79 )
80 {
81 m_f11 = a_f11;
82 m_f12 = a_f12;
83 m_f13 = a_f13;
84 m_f14 = a_f14;
85 m_f21 = a_f21;
86 m_f22 = a_f22;
87 m_f23 = a_f23;
88 m_f24 = a_f24;
89 m_f31 = a_f31;
90 m_f32 = a_f32;
91 m_f33 = a_f33;
92 m_f34 = a_f34;
93 m_f41 = a_f41;
94 m_f42 = a_f42;
95 m_f43 = a_f43;
96 m_f44 = a_f44;
97 }
98
99 constexpr void Set( const TMatrix44& a_rcMatrix )
100 {
101 Set(
102 a_rcMatrix.m_f11, a_rcMatrix.m_f12, a_rcMatrix.m_f13, a_rcMatrix.m_f14,
103 a_rcMatrix.m_f21, a_rcMatrix.m_f22, a_rcMatrix.m_f23, a_rcMatrix.m_f24,
104 a_rcMatrix.m_f31, a_rcMatrix.m_f32, a_rcMatrix.m_f33, a_rcMatrix.m_f34,
105 a_rcMatrix.m_f41, a_rcMatrix.m_f42, a_rcMatrix.m_f43, a_rcMatrix.m_f44
106 );
107 }
108
109 // $Barnyard: FUNCTION 006c8500
110 constexpr void Identity()
111 {
112 Set( IDENTITY );
113 }
114
115 const TVector3& AsBasisVector3( BASISVECTOR a_iIndex ) const
116 {
117 return *TREINTERPRETCAST(
118 TVector3*,
119 TREINTERPRETCAST( TUINTPTR, this ) + a_iIndex * sizeof( TVector4 )
120 );
121 }
122
124 {
125 return *TREINTERPRETCAST(
126 TVector3*,
127 TREINTERPRETCAST( TUINTPTR, this ) + a_iIndex * sizeof( TVector4 )
128 );
129 }
130
131 const TVector4& AsBasisVector4( BASISVECTOR a_iIndex ) const
132 {
133 return *TREINTERPRETCAST(
134 TVector4*,
135 TREINTERPRETCAST( TUINTPTR, this ) + a_iIndex * sizeof( TVector4 )
136 );
137 }
138
140 {
141 return *TREINTERPRETCAST(
142 TVector4*,
143 TREINTERPRETCAST( TUINTPTR, this ) + a_iIndex * sizeof( TVector4 )
144 );
145 }
146
151
153 {
155 }
156
161
163 {
165 }
166
167 void SetTranslation( const TVector4& a_rTranslation )
168 {
169 GetTranslation() = a_rTranslation;
170 }
171
172 void LookAtTarget( const TVector4& a_rTarget, const TVector4& a_rUp );
173 void LookAtDirection( const TVector4& a_rVec, const TVector4& a_rVec2 );
174
175 // $Barnyard: FUNCTION 006c86f0
176 constexpr void Scale( TFLOAT a_fScalar1, TFLOAT a_fScalar2, TFLOAT a_fScalar3 )
177 {
178 m_f11 *= a_fScalar1;
179 m_f12 *= a_fScalar1;
180 m_f13 *= a_fScalar1;
181 m_f21 *= a_fScalar2;
182 m_f22 *= a_fScalar2;
183 m_f23 *= a_fScalar2;
184 m_f31 *= a_fScalar3;
185 m_f32 *= a_fScalar3;
186 m_f33 *= a_fScalar3;
187 }
188
189 // $Barnyard: FUNCTION 006c8750
190 constexpr void Scale( const TVector4& a_rScalars )
191 {
192 m_f11 *= a_rScalars.x;
193 m_f12 *= a_rScalars.x;
194 m_f13 *= a_rScalars.x;
195 m_f21 *= a_rScalars.y;
196 m_f22 *= a_rScalars.y;
197 m_f23 *= a_rScalars.y;
198 m_f31 *= a_rScalars.z;
199 m_f32 *= a_rScalars.z;
200 m_f33 *= a_rScalars.z;
201 }
202
203 constexpr void Scale( TFLOAT a_fScale )
204 {
205 Scale( a_fScale, a_fScale, a_fScale );
206 }
207
208 constexpr TBOOL IsOrthonormal() const
209 {
210 TFLOAT fVar1 = ( m_f32 * m_f32 + m_f31 * m_f31 + m_f33 * m_f33 ) - 1.0f;
211 TFLOAT fVar2 = ( m_f22 * m_f22 + m_f21 * m_f21 + m_f23 * m_f23 ) - 1.0f;
212 TFLOAT fVar3 = m_f22 * m_f32 + m_f31 * m_f21 + m_f23 * m_f33;
213 TFLOAT fVar4 = m_f32 * m_f12 + m_f11 * m_f31 + m_f33 * m_f13;
214 TFLOAT fVar5 = m_f22 * m_f12 + m_f11 * m_f21 + m_f23 * m_f13;
215 TFLOAT fVar6 = ( m_f11 * m_f11 + m_f12 * m_f12 + m_f13 * m_f13 ) - 1.0f;
216
217 return !( ( ( 0.01 <= fVar6 * fVar6 + fVar2 * fVar2 + fVar1 * fVar1 + fVar4 * fVar4 + fVar5 * fVar5 + fVar3 * fVar3 ) || ( m_f14 != 0.0 ) ) || ( m_f24 != 0.0 ) ) || ( ( m_f34 != 0.0 || ( m_f44 != 1.0 ) ) );
218 }
219
220 void Multiply( const TMatrix44& a_rLeft, const TMatrix44& a_rRight );
221 void Multiply( const TMatrix44& a_rRight );
222
223 TBOOL Invert( const TMatrix44& a_rRight );
224
225 void InvertOrthogonal();
226 void InvertOrthogonal( const TMatrix44& a_rRight );
227 void InvertOrthonormal();
228
229 TMatrix44& SetFromQuaternion( const TQuaternion& a_rQuaternion );
230 TMatrix44& PushQuaternion( const TQuaternion& a_rQuaternion, const TMatrix44& a_rMatrix, const TVector3& a_rOrigin );
231
232 void RotateX( TFLOAT a_fAngle );
233 void RotateY( TFLOAT a_fAngle );
234 void RotateZ( TFLOAT a_fAngle );
235
236 void GetEulerXYZ( TVector3& a_rOutVec ) const;
237
238 // $Barnyard: FUNCTION 006c8bf0
239 static void TransformPlaneOrthogonal( TPlane& a_rOutPlane, const TMatrix44& a_rMatrix, const TPlane& a_rcSourcePlane )
240 {
241 RotateVector( a_rOutPlane.AsVector4(), a_rMatrix, a_rcSourcePlane.AsVector4() );
242
243 a_rOutPlane.SetD(
244 a_rcSourcePlane.GetD() +
246 a_rOutPlane.AsVector4(), a_rMatrix.AsBasisVector4( BASISVECTOR_TRANSLATION )
247 )
248 );
249 }
250
251 // $Barnyard: FUNCTION 006c8b80
252 constexpr static void RotateVector( TVector4& a_rOutVector, const TMatrix44& a_rMatrix, const TVector4& a_rVector )
253 {
254 TFLOAT fVar1 = a_rMatrix.m_f32;
255 TFLOAT fVar2 = a_rVector.z;
256 TFLOAT fVar3 = a_rMatrix.m_f12;
257 TFLOAT fVar4 = a_rVector.x;
258 TFLOAT fVar5 = a_rMatrix.m_f22;
259 TFLOAT fVar6 = a_rVector.y;
260 TFLOAT fVar7 = a_rMatrix.m_f33;
261 TFLOAT fVar8 = a_rVector.z;
262 TFLOAT fVar9 = a_rMatrix.m_f13;
263 TFLOAT fVar10 = a_rVector.x;
264 TFLOAT fVar11 = a_rMatrix.m_f23;
265 TFLOAT fVar12 = a_rVector.y;
266 TFLOAT fVar13 = a_rMatrix.m_f31;
267 TFLOAT fVar14 = a_rVector.z;
268 TFLOAT fVar15 = a_rMatrix.m_f21;
269 TFLOAT fVar16 = a_rVector.y;
270 TFLOAT fVar17 = a_rMatrix.m_f11;
271 TFLOAT fVar18 = a_rVector.x;
272
273 a_rOutVector.x = fVar17 * fVar18 + fVar15 * fVar16 + fVar13 * fVar14;
274 a_rOutVector.y = fVar5 * fVar6 + fVar3 * fVar4 + fVar1 * fVar2;
275 a_rOutVector.z = fVar11 * fVar12 + fVar9 * fVar10 + fVar7 * fVar8;
276 a_rOutVector.w = a_rVector.w;
277 }
278
279 // $Barnyard: FUNCTION 006c8a20
280 constexpr static void TransformVector( TVector3& a_rOutVector, const TMatrix44& a_rMatrix, const TVector3& a_rVector )
281 {
282 TFLOAT fVar1 = a_rMatrix.m_f32;
283 TFLOAT fVar2 = a_rVector.z;
284 TFLOAT fVar3 = a_rMatrix.m_f12;
285 TFLOAT fVar4 = a_rVector.x;
286 TFLOAT fVar5 = a_rMatrix.m_f22;
287 TFLOAT fVar6 = a_rVector.y;
288 TFLOAT fVar7 = a_rMatrix.m_f42;
289 TFLOAT fVar8 = a_rMatrix.m_f33;
290 TFLOAT fVar9 = a_rVector.z;
291 TFLOAT fVar10 = a_rMatrix.m_f13;
292 TFLOAT fVar11 = a_rVector.x;
293 TFLOAT fVar12 = a_rMatrix.m_f23;
294 TFLOAT fVar13 = a_rVector.y;
295 TFLOAT fVar14 = a_rMatrix.m_f43;
296 a_rOutVector.x = a_rMatrix.m_f11 * a_rVector.x + a_rMatrix.m_f21 * a_rVector.y + a_rMatrix.m_f31 * a_rVector.z + a_rMatrix.m_f41;
297 a_rOutVector.y = fVar5 * fVar6 + fVar3 * fVar4 + fVar1 * fVar2 + fVar7;
298 a_rOutVector.z = fVar12 * fVar13 + fVar10 * fVar11 + fVar8 * fVar9 + fVar14;
299 }
300
301 // $Barnyard: FUNCTION 006c8a80
302 constexpr static void TransformVector( TVector4& a_rOutVector, const TMatrix44& a_rMatrix, const TVector4& a_rVector )
303 {
304 TFLOAT fVar1 = a_rMatrix.m_f42;
305 TFLOAT fVar2 = a_rVector.w;
306 TFLOAT fVar3 = a_rMatrix.m_f12;
307 TFLOAT fVar4 = a_rVector.x;
308 TFLOAT fVar5 = a_rMatrix.m_f32;
309 TFLOAT fVar6 = a_rVector.z;
310 TFLOAT fVar7 = a_rMatrix.m_f22;
311 TFLOAT fVar8 = a_rVector.y;
312 TFLOAT fVar9 = a_rMatrix.m_f43;
313 TFLOAT fVar10 = a_rVector.w;
314 TFLOAT fVar11 = a_rMatrix.m_f13;
315 TFLOAT fVar12 = a_rVector.x;
316 TFLOAT fVar13 = a_rMatrix.m_f33;
317 TFLOAT fVar14 = a_rVector.z;
318 TFLOAT fVar15 = a_rMatrix.m_f23;
319 TFLOAT fVar16 = a_rVector.y;
320 TFLOAT fVar17 = a_rMatrix.m_f41;
321 TFLOAT fVar18 = a_rVector.w;
322 TFLOAT fVar19 = a_rMatrix.m_f31;
323 TFLOAT fVar20 = a_rVector.z;
324 TFLOAT fVar21 = a_rMatrix.m_f21;
325 TFLOAT fVar22 = a_rVector.y;
326 TFLOAT fVar23 = a_rMatrix.m_f11;
327 TFLOAT fVar24 = a_rVector.x;
328 a_rOutVector.w = a_rMatrix.m_f24 * a_rVector.y + a_rMatrix.m_f34 * a_rVector.z + a_rMatrix.m_f14 * a_rVector.x + a_rMatrix.m_f44 * a_rVector.w;
329 a_rOutVector.x = fVar23 * fVar24 + fVar21 * fVar22 + fVar19 * fVar20 + fVar17 * fVar18;
330 a_rOutVector.y = fVar7 * fVar8 + fVar5 * fVar6 + fVar3 * fVar4 + fVar1 * fVar2;
331 a_rOutVector.z = fVar15 * fVar16 + fVar13 * fVar14 + fVar11 * fVar12 + fVar9 * fVar10;
332 }
333
334 constexpr void operator=( const TMatrix44& a_rcMatrix )
335 {
336 Set(
337 a_rcMatrix.m_f11, a_rcMatrix.m_f12, a_rcMatrix.m_f13, a_rcMatrix.m_f14,
338 a_rcMatrix.m_f21, a_rcMatrix.m_f22, a_rcMatrix.m_f23, a_rcMatrix.m_f24,
339 a_rcMatrix.m_f31, a_rcMatrix.m_f32, a_rcMatrix.m_f33, a_rcMatrix.m_f34,
340 a_rcMatrix.m_f41, a_rcMatrix.m_f42, a_rcMatrix.m_f43, a_rcMatrix.m_f44
341 );
342 }
343
344#ifdef TRENDERINTERFACE_DX8
345 operator D3DXMATRIX*()
346 {
347 return TREINTERPRETCAST( D3DXMATRIX*, this );
348 }
349
350 operator const D3DXMATRIX*() const
351 {
352 return TREINTERPRETCAST( const D3DXMATRIX*, this );
353 }
354#endif
355
356public:
357 static constinit TMatrix44 IDENTITY;
358
359public:
364};
365
BASISVECTOR_
Definition TMatrix44.h:24
@ BASISVECTOR_TRANSLATION
Definition TMatrix44.h:28
@ BASISVECTOR_RIGHT
Definition TMatrix44.h:25
@ BASISVECTOR_UP
Definition TMatrix44.h:26
@ BASISVECTOR_FORWARD
Definition TMatrix44.h:27
TINT BASISVECTOR
Definition TMatrix44.h:22
Quaternion implementation for the Toshi engine.
#define TREINTERPRETCAST(TYPE, VALUE)
Definition Defines.h:68
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
uintptr_t TUINTPTR
Definition Typedefs.h:18
float TFLOAT
Definition Typedefs.h:4
int TINT
Definition Typedefs.h:7
bool TBOOL
Definition Typedefs.h:6
TVector3 & GetTranslation3()
Definition TMatrix44.h:147
constexpr void Set(const TMatrix44 &a_rcMatrix)
Definition TMatrix44.h:99
static constexpr void TransformVector(TVector3 &a_rOutVector, const TMatrix44 &a_rMatrix, const TVector3 &a_rVector)
Definition TMatrix44.h:280
void RotateZ(TFLOAT a_fAngle)
constexpr void Scale(TFLOAT a_fScale)
Definition TMatrix44.h:203
TVector4 & AsBasisVector4(BASISVECTOR a_iIndex)
Definition TMatrix44.h:139
constexpr TBOOL IsOrthonormal() const
Definition TMatrix44.h:208
TFLOAT m_f21
Definition TMatrix44.h:361
void RotateX(TFLOAT a_fAngle)
TFLOAT m_f12
Definition TMatrix44.h:360
constexpr void Scale(TFLOAT a_fScalar1, TFLOAT a_fScalar2, TFLOAT a_fScalar3)
Definition TMatrix44.h:176
void LookAtTarget(const TVector4 &a_rTarget, const TVector4 &a_rUp)
Definition TMatrix44.cpp:25
static void TransformPlaneOrthogonal(TPlane &a_rOutPlane, const TMatrix44 &a_rMatrix, const TPlane &a_rcSourcePlane)
Definition TMatrix44.h:239
constexpr void Identity()
Definition TMatrix44.h:110
TBOOL Invert(const TMatrix44 &a_rRight)
Definition TMatrix44.cpp:88
TFLOAT m_f44
Definition TMatrix44.h:363
void LookAtDirection(const TVector4 &a_rVec, const TVector4 &a_rVec2)
Definition TMatrix44.cpp:41
TFLOAT m_f43
Definition TMatrix44.h:363
TFLOAT m_f32
Definition TMatrix44.h:362
void InvertOrthonormal()
TFLOAT m_f13
Definition TMatrix44.h:360
static constinit TMatrix44 IDENTITY
Definition TMatrix44.h:357
constexpr TMatrix44(const TMatrix44 &a_rMatrix)
Definition TMatrix44.h:36
constexpr void operator=(const TMatrix44 &a_rcMatrix)
Definition TMatrix44.h:334
TFLOAT m_f14
Definition TMatrix44.h:360
const TVector3 & AsBasisVector3(BASISVECTOR a_iIndex) const
Definition TMatrix44.h:115
TFLOAT m_f11
Definition TMatrix44.h:360
TFLOAT m_f23
Definition TMatrix44.h:361
void InvertOrthogonal()
TMatrix44 & PushQuaternion(const TQuaternion &a_rQuaternion, const TMatrix44 &a_rMatrix, const TVector3 &a_rOrigin)
constexpr TMatrix44(TFLOAT a_f11, TFLOAT a_f12, TFLOAT a_f13, TFLOAT a_f14, TFLOAT a_f21, TFLOAT a_f22, TFLOAT a_f23, TFLOAT a_f24, TFLOAT a_f31, TFLOAT a_f32, TFLOAT a_f33, TFLOAT a_f34, TFLOAT a_f41, TFLOAT a_f42, TFLOAT a_f43, TFLOAT a_f44)
Definition TMatrix44.h:40
constexpr void Set(TFLOAT a_f11, TFLOAT a_f12, TFLOAT a_f13, TFLOAT a_f14, TFLOAT a_f21, TFLOAT a_f22, TFLOAT a_f23, TFLOAT a_f24, TFLOAT a_f31, TFLOAT a_f32, TFLOAT a_f33, TFLOAT a_f34, TFLOAT a_f41, TFLOAT a_f42, TFLOAT a_f43, TFLOAT a_f44)
Definition TMatrix44.h:62
void SetTranslation(const TVector4 &a_rTranslation)
Definition TMatrix44.h:167
TVector4 & GetTranslation()
Definition TMatrix44.h:157
static constexpr void RotateVector(TVector4 &a_rOutVector, const TMatrix44 &a_rMatrix, const TVector4 &a_rVector)
Definition TMatrix44.h:252
const TVector3 & GetTranslation3() const
Definition TMatrix44.h:152
void RotateY(TFLOAT a_fAngle)
constexpr TMatrix44()=default
TFLOAT m_f22
Definition TMatrix44.h:361
TFLOAT m_f41
Definition TMatrix44.h:363
TFLOAT m_f31
Definition TMatrix44.h:362
void GetEulerXYZ(TVector3 &a_rOutVec) const
TFLOAT m_f24
Definition TMatrix44.h:361
TVector3 & AsBasisVector3(BASISVECTOR a_iIndex)
Definition TMatrix44.h:123
const TVector4 & AsBasisVector4(BASISVECTOR a_iIndex) const
Definition TMatrix44.h:131
TMatrix44 & SetFromQuaternion(const TQuaternion &a_rQuaternion)
static constexpr void TransformVector(TVector4 &a_rOutVector, const TMatrix44 &a_rMatrix, const TVector4 &a_rVector)
Definition TMatrix44.h:302
const TVector4 & GetTranslation() const
Definition TMatrix44.h:162
constexpr void Scale(const TVector4 &a_rScalars)
Definition TMatrix44.h:190
TFLOAT m_f34
Definition TMatrix44.h:362
void Multiply(const TMatrix44 &a_rLeft, const TMatrix44 &a_rRight)
Definition TMatrix44.cpp:61
TFLOAT m_f42
Definition TMatrix44.h:363
TFLOAT m_f33
Definition TMatrix44.h:362
Definition TPlane.h:7
TFORCEINLINE TVector4 & AsVector4()
Definition TPlane.h:124
TFORCEINLINE constexpr TFLOAT GetD() const
Definition TPlane.h:69
TFORCEINLINE constexpr void SetD(TFLOAT a_fDistance)
Definition TPlane.h:74
TFLOAT y
Definition TVector3.h:163
TFLOAT z
Definition TVector3.h:163
TFLOAT x
Definition TVector3.h:163
TFLOAT w
Definition TVector4.h:367
TFLOAT x
Definition TVector4.h:367
TFLOAT y
Definition TVector4.h:367
TFLOAT z
Definition TVector4.h:367
TFLOAT constexpr DotProduct3(const TVector4 &vec) const
Definition TVector4.h:339