sculpto
Public Member Functions | Static Public Member Functions | List of all members
scl::math::matr4< T > Class Template Reference

#include <matr4.h>

Inheritance diagram for scl::math::matr4< T >:
scl::math::matr4_data< T >

Public Member Functions

 matr4 ()
 
 matr4 (T A00, T A01, T A02, T A03, T A10, T A11, T A12, T A13, T A20, T A21, T A22, T A23, T A30, T A31, T A32, T A33)
 
 matr4 (T A[4][4])
 
 matr4 (T A00)
 
 matr4 (const matr4_data< T > &Other)
 
matr4 Transpose () const
 
matr4 operator* (const matr4 &M) const
 
Det () const
 
matr4 Inverse () const
 
vec3< T > TransformPoint (const vec3< T > &V) const
 
vec3< T > TransformVector (const vec3< T > &V) const
 
vec3< T > Transform4x4 (const vec3< T > &V) const
 
T & operator[] (int Index)
 
operator[] (int Index) const
 
- Public Member Functions inherited from scl::math::matr4_data< T >
 matr4_data ()
 
 matr4_data (const matr4_data &Other)
 
 matr4_data (T A00, T A01, T A02, T A03, T A10, T A11, T A12, T A13, T A20, T A21, T A22, T A23, T A30, T A31, T A32, T A33)
 
 operator T* ()
 

Static Public Member Functions

static matr4 Identity ()
 
static matr4 Translate (const vec3< T > &Transform)
 
static matr4 Scale (vec3< T > S)
 
static matr4 Rotate (vec3< T > Axis, degrees< T > Angle)
 
static matr4 RotateX (degrees< T > Angle)
 
static matr4 RotateY (degrees< T > Angle)
 
static matr4 RotateZ (degrees< T > Angle)
 
static matr4 Frustum (T Left, T Right, T Bottom, T Top, T Near, T Far)
 
static matr4 Ortho (T Left, T Right, T Bottom, T Top, T Near, T Far)
 
static matr4 View (vec3< T > Location, vec3< T > At, vec3< T > Up)
 
static matr4 Lerp (const matr4 &Start, const matr4 &End, T Current)
 

Additional Inherited Members

- Public Attributes inherited from scl::math::matr4_data< T >
A [4][4]
 

Detailed Description

template<typename T>
class scl::math::matr4< T >

4x4 matrix declaration.

4x4 matrix class.

Definition at line 64 of file matr4.h.

Constructor & Destructor Documentation

◆ matr4() [1/5]

template<typename T >
scl::math::matr4< T >::matr4 ( )
inline

End of 'EvaluateInverseMatrix' function

  • Default matrix constructor. Set identity matrix.
Parameters
None.

Definition at line 166 of file matr4.h.

166 :
167 matr4_data<T>(),
168 InvA { {0, 0, 0, 0},
169 {0, 0, 0, 0},
170 {0, 0, 0, 0},
171 {0, 0, 0, 0} },
172 IsInverseEvaluated(false) {}

◆ matr4() [2/5]

template<typename T >
scl::math::matr4< T >::matr4 ( A00,
A01,
A02,
A03,
A10,
A11,
A12,
A13,
A20,
A21,
A22,
A23,
A30,
A31,
A32,
A33 
)
inline
  • Matrix constructor bt 16 values.
Parameters
A00-A33- matrx valeus.

Definition at line 179 of file matr4.h.

182 :
183 matr4_data<T>(A00, A01, A02, A03,
184 A10, A11, A12, A13,
185 A20, A21, A22, A23,
186 A30, A31, A32, A33),
187 InvA { {0, 0, 0, 0},
188 {0, 0, 0, 0},
189 {0, 0, 0, 0},
190 {0, 0, 0, 0} },
191 IsInverseEvaluated(false) {}

◆ matr4() [3/5]

template<typename T >
scl::math::matr4< T >::matr4 ( A[4][4])
inline
  • Matrix contructor by array of values.
Parameters
A- array of values to set in matrix

Definition at line 198 of file matr4.h.

198 :
199 InvA { {0, 0, 0, 0},
200 {0, 0, 0, 0},
201 {0, 0, 0, 0},
202 {0, 0, 0, 0} },
203 IsInverseEvaluated(false)
204 {
205 memcpy(this->A, A, 4 * 4 * sizeof(T));
206 }

◆ matr4() [4/5]

template<typename T >
scl::math::matr4< T >::matr4 ( A00)
inline
  • Matrix data constructor by 1 value.
Parameters
A00- calue to set to all matrix cells.

Definition at line 213 of file matr4.h.

213 :
214 matr4_data<T>(A00, A00, A00, A00,
215 A00, A00, A00, A00,
216 A00, A00, A00, A00,
217 A00, A00, A00, A00),
218 InvA { {0, 0, 0, 0},
219 {0, 0, 0, 0},
220 {0, 0, 0, 0},
221 {0, 0, 0, 0} },
222 IsInverseEvaluated(false) {}

◆ matr4() [5/5]

template<typename T >
scl::math::matr4< T >::matr4 ( const matr4_data< T > &  Other)
inline
  • Matrix constructor by matrix data.
Parameters
Other- matrix data.

Definition at line 229 of file matr4.h.

229 :
230 matr4_data<T>(Other),
231 InvA { {0, 0, 0, 0},
232 {0, 0, 0, 0},
233 {0, 0, 0, 0},
234 {0, 0, 0, 0} },
235 IsInverseEvaluated(false) {}

Member Function Documentation

◆ Det()

template<typename T >
T scl::math::matr4< T >::Det ( ) const
inline
  • Calculate matrix determinant.
Parameters
None.
Returns
matrix determinant.

Definition at line 465 of file matr4.h.

466 {
467 return
468 this->A[0][0] * matr3<T>::Det(this->A[1][1], this->A[1][2], this->A[1][3],
469 this->A[2][1], this->A[2][2], this->A[2][3],
470 this->A[3][1], this->A[3][2], this->A[3][3]) +
471 -this->A[0][1] * matr3<T>::Det(this->A[1][0], this->A[1][2], this->A[1][3],
472 this->A[2][0], this->A[2][2], this->A[2][3],
473 this->A[3][0], this->A[3][2], this->A[3][3]) +
474 this->A[0][2] * matr3<T>::Det(this->A[1][0], this->A[1][1], this->A[1][3],
475 this->A[2][0], this->A[2][1], this->A[2][3],
476 this->A[3][0], this->A[3][1], this->A[3][3]) +
477 -this->A[0][3] * matr3<T>::Det(this->A[1][0], this->A[1][1], this->A[1][2],
478 this->A[2][0], this->A[2][1], this->A[2][2],
479 this->A[3][0], this->A[3][1], this->A[3][2]);
480 }

◆ Frustum()

template<typename T >
static matr4 scl::math::matr4< T >::Frustum ( Left,
Right,
Bottom,
Top,
Near,
Far 
)
inlinestatic
  • Frusum projection matrix creation function.
Parameters
Left,Right- frustrum view cone left and right sides position
Bottom,Top- frustrum view cone bottom and top sides position
Near,Far- frustrum view cone near and far planes distance.
Returns
None.

Definition at line 359 of file matr4.h.

360 {
361 return matr4(2 * Near / (Right - Left), 0, 0, 0,
362 0, 2 * Near / (Top - Bottom), 0, 0,
363 (Right + Left) / (Right - Left), (Top + Bottom) / (Top - Bottom), -(Far + Near) / (Far - Near), -1,
364 0, 0, -2 * Near * Far / (Far - Near), 0);
365 }

◆ Identity()

template<typename T >
static matr4 scl::math::matr4< T >::Identity ( )
inlinestatic

Common matrices creation functinos.

  • Identity creation function.
Returns
identity matrix.

Definition at line 243 of file matr4.h.

244 {
245 return matr4(1, 0, 0, 0,
246 0, 1, 0, 0,
247 0, 0, 1, 0,
248 0, 0, 0, 1);
249 }

◆ Inverse()

template<typename T >
matr4 scl::math::matr4< T >::Inverse ( ) const
inline
  • Get inversed matrix.
Parameters
None.
Returns
None.

Definition at line 488 of file matr4.h.

489 {
490 EvaluateInverseMatrix();
491 return matr4(InvA);
492 }

◆ Lerp()

template<typename T >
static matr4 scl::math::matr4< T >::Lerp ( const matr4< T > &  Start,
const matr4< T > &  End,
Current 
)
inlinestatic

Matrices operations.

  • Matrix lerp function.
Parameters
Start,End- matrices to interpolate.
Current- interpolation value [0;1].
Returns
interpolated matrix.

Definition at line 415 of file matr4.h.

416 {
417 matr4 M;
418
419 for (int i = 0; i < 4; i++)
420 for (int j = 0; j < 4; j++)
421 M.A[i][j] = ::scl::math::Lerp(Start.A[i][j],
422 End.A[i][j],
423 Current);
424
425 return M;
426 }
T Lerp(T Start, T End, T Current)
Definition: math_common.h:91

◆ operator*()

template<typename T >
matr4 scl::math::matr4< T >::operator* ( const matr4< T > &  M) const
inline
  • Mulpiply matrices function.
Parameters
M- matrix to multyply.
Returns
result matrix.

Definition at line 447 of file matr4.h.

448 {
449 matr4 r;
450 int k;
451
452 for (int i = 0; i < 4; i++)
453 for (int j = 0; j < 4; j++)
454 for (k = 0, r.A[i][j] = 0; k < 4; k++)
455 r.A[i][j] += this->A[i][k] * M.A[k][j];
456 return r;
457 }

◆ operator[]() [1/2]

template<typename T >
T & scl::math::matr4< T >::operator[] ( int  Index)
inline
  • Getting matrix cell value operator overloading.
Parameters
Index- cell index.
Returns
vector cartesian coordinate.

Definition at line 541 of file matr4.h.

542 {
543 return this->A[math::Clamp(Index, 0, 15)];
544 }
T Clamp(T Num, T Min=0, T Max=1)
Definition: math_common.h:77

◆ operator[]() [2/2]

template<typename T >
T scl::math::matr4< T >::operator[] ( int  Index) const
inline
  • Getting coordinate operator overloading.
Parameters
Index- coordinate index.
Returns
vector cartesian coordinate.

Definition at line 552 of file matr4.h.

553 {
554 return this->A[math::Clamp(Index, 0, 15)];
555 }

◆ Ortho()

template<typename T >
static matr4 scl::math::matr4< T >::Ortho ( Left,
Right,
Bottom,
Top,
Near,
Far 
)
inlinestatic
  • Ortho projection matrix creation function.
Parameters
Left,Right- view cube left and right sides position
Bottom,Top- view cube bottom and top sides position
Near,Far- view cube near and far planes distance.
Returns
ortho matrix.

Definition at line 375 of file matr4.h.

376 {
377 return matr4(2 / (Right - Left), 0, 0, 0,
378 0, 2 / (Top - Bottom), 0, 0,
379 0, 0, -2 / (Far - Near), 0,
380 -(Right + Left) / (Right - Left), -(Top + Bottom) / (Top - Bottom), -(Near + Far) / (Far - Near), 1);
381 }

◆ Rotate()

template<typename T >
static matr4 scl::math::matr4< T >::Rotate ( vec3< T >  Axis,
degrees< T >  Angle 
)
inlinestatic
  • Rotation matrix creation function.
Parameters
Axis- axis to rotate around of.
Angle- angle in degrees to roate on.
Returns
rotation matrix.

Definition at line 288 of file matr4.h.

289 {
290 T c = cos((radians<T>)Angle);
291 T s = sin((radians<T>)Angle);
292 vec3<T> v = Axis.Normalized();
293
294 return matr4(c + v.X * v.X * (1 - c), v.X * v.Y * (1 - c) + v.Z * s, v.X * v.Z * (1 - c) - v.Y * s, 0,
295 v.Y * v.X * (1 - c) - v.Z * s, c + v.Y * v.Y * (1 - c), v.Y * v.Z * (1 - c) + v.X * s, 0,
296 v.Z * v.X * (1 - c) + v.Y * s, v.Z * v.Y * (1 - c) - v.X * s, c + v.Z * v.Z * (1 - c), 0,
297 0, 0, 0, 1);
298 }

◆ RotateX()

template<typename T >
static matr4 scl::math::matr4< T >::RotateX ( degrees< T >  Angle)
inlinestatic
  • Rotation around X axis matrix creation function.
Parameters
Angle- angle in degrees to roate on.
Returns
rotation matrix.

Definition at line 306 of file matr4.h.

307 {
308 T c = cos((radians<T>)Angle);
309 T s = sin((radians<T>)Angle);
310
311 return matr4(1, 0, 0, 0,
312 0, c, s, 0,
313 0, -s, c, 0,
314 0, 0, 0, 1);
315 }

◆ RotateY()

template<typename T >
static matr4 scl::math::matr4< T >::RotateY ( degrees< T >  Angle)
inlinestatic
  • Rotation around Y axis matrix creation function.
Parameters
Angle- angle in degrees to roate on.
Returns
rotation matrix.

Definition at line 323 of file matr4.h.

324 {
325 T c = cos((radians<T>)Angle);
326 T s = sin((radians<T>)Angle);
327
328 return matr4(c, 0, -s, 0,
329 0, 1, 0, 0,
330 s, 0, c, 0,
331 0, 0, 0, 1);
332 }

◆ RotateZ()

template<typename T >
static matr4 scl::math::matr4< T >::RotateZ ( degrees< T >  Angle)
inlinestatic
  • Rotation around Z axis matrix creation function.
Parameters
Angle- angle in degrees to roate on.
Returns
rotation matrix.

Definition at line 340 of file matr4.h.

341 {
342 T c = cos((radians<T>)Angle);
343 T s = sin((radians<T>)Angle);
344
345 return matr4(c, -s, 0, 0,
346 s, c, 0, 0,
347 0, 0, 1, 0,
348 0, 0, 0, 1);
349 }

◆ Scale()

template<typename T >
static matr4 scl::math::matr4< T >::Scale ( vec3< T >  S)
inlinestatic
  • Scale matrix creation function.
Parameters
S- scale factor.
Returns
scale matrix.

Definition at line 272 of file matr4.h.

273 {
274 T x = S.X, y = S.Y, z = S.Z;
275 return matr4(x, 0, 0, 0,
276 0, y, 0, 0,
277 0, 0, z, 0,
278 0, 0, 0, 1);
279 }

◆ Transform4x4()

template<typename T >
vec3< T > scl::math::matr4< T >::Transform4x4 ( const vec3< T > &  V) const
inline
  • Multiply matrix and vector.
Parameters
V- vectors to transform.
Returns
None.

Definition at line 526 of file matr4.h.

527 {
528 float w = V.X * this->A[0][3] + V.Y * this->A[1][3] + V.Z * this->A[2][3] + this->A[3][3];
529
530 return vec3<T>((V.X * this->A[0][0] + V.Y * this->A[1][0] + V.Z * this->A[2][0] + this->A[3][0]) / w,
531 (V.X * this->A[0][1] + V.Y * this->A[1][1] + V.Z * this->A[2][1] + this->A[3][1]) / w,
532 (V.X * this->A[0][2] + V.Y * this->A[1][2] + V.Z * this->A[2][2] + this->A[3][2]) / w);
533 }

◆ TransformPoint()

template<typename T >
vec3< T > scl::math::matr4< T >::TransformPoint ( const vec3< T > &  V) const
inline
  • Transform point position.
Parameters
V- vectors to transform.
Returns
None.

Definition at line 500 of file matr4.h.

501 {
502 return vec3<T>(V.X * this->A[0][0] + V.Y * this->A[1][0] + V.Z * this->A[2][0] + this->A[3][0],
503 V.X * this->A[0][1] + V.Y * this->A[1][1] + V.Z * this->A[2][1] + this->A[3][1],
504 V.X * this->A[0][2] + V.Y * this->A[1][2] + V.Z * this->A[2][2] + this->A[3][2]);
505 }

◆ TransformVector()

template<typename T >
vec3< T > scl::math::matr4< T >::TransformVector ( const vec3< T > &  V) const
inline
  • Vector linear transformation.
Parameters
V- vectors to transform.
Returns
None.

Definition at line 513 of file matr4.h.

514 {
515 return vec3<T>(V.X * this->A[0][0] + V.Y * this->A[1][0] + V.Z * this->A[2][0],
516 V.X * this->A[0][1] + V.Y * this->A[1][1] + V.Z * this->A[2][1],
517 V.X * this->A[0][2] + V.Y * this->A[1][2] + V.Z * this->A[2][2]);
518 }

◆ Translate()

template<typename T >
static matr4 scl::math::matr4< T >::Translate ( const vec3< T > &  Transform)
inlinestatic
  • Translate matrix creation function.
Parameters
Transform- translatino vector.
Returns
translation matrix.

Definition at line 257 of file matr4.h.

258 {
259 T x = Transform.GetX(), y = Transform.GetY(), z = Transform.GetZ();
260 return matr4(1, 0, 0, 0,
261 0, 1, 0, 0,
262 0, 0, 1, 0,
263 x, y, z, 1);
264 }

◆ Transpose()

template<typename T >
matr4 scl::math::matr4< T >::Transpose ( ) const
inline
  • Transpose matrix function.
Returns
result matrix.

Definition at line 433 of file matr4.h.

434 {
435 return matr4(this->A[0][0], this->A[1][0], this->A[2][0], this->A[3][0],
436 this->A[0][1], this->A[1][1], this->A[2][1], this->A[3][1],
437 this->A[0][2], this->A[1][2], this->A[2][2], this->A[3][2],
438 this->A[0][3], this->A[1][3], this->A[2][3], this->A[3][3]);
439 }

◆ View()

template<typename T >
static matr4 scl::math::matr4< T >::View ( vec3< T >  Location,
vec3< T >  At,
vec3< T >  Up 
)
inlinestatic
  • Viewer coordinate system transformation.
Parameters
Location- viewer position in global coordinate system.
At- viewer looking at point.
Up- viewer up direction point.
Returns
view matrix.

Definition at line 391 of file matr4.h.

392 {
393 vec3<T> d = (At - Location).Normalized();
394 vec3<T> r = (
395 d.Dot(Up.Normalized()) == -1 ?
396 vec3 { -d.Y, d.X, d.Z } :
397 r = d.Cross(Up).Normalized()
398 );
399 vec3<T> u = r.Cross(d);
400
401 return matr4(r.X, u.X, -d.X, 0,
402 r.Y, u.Y, -d.Y, 0,
403 r.Z, u.Z, -d.Z, 0,
404 -Location.Dot(r), -Location.Dot(u), Location.Dot(d), 1);
405 }
math::vec3< float > vec3
Definition: base.h:38

The documentation for this class was generated from the following files: