SH4ZAM! 0.8.0
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz_matrix.hpp
Go to the documentation of this file.
1/*! \file
2 \brief C++ routines for operating on in-memory matrices.
3 \ingroup matrix
4
5 This file provides a C++ binding layer over the C API provided by
6 shz_matrix.h.
7
8 \author 2025, 2026 Falco Girgis
9 \copyright MIT License
10
11 \todo
12 - Fully document
13 - Operator overloading
14 - full transforms (GL-style) taking a separate destination matrix?
15*/
16
17#ifndef SHZ_MATRIX_HPP
18#define SHZ_MATRIX_HPP
19
20#include "shz_matrix.h"
21#include "shz_vector.hpp"
22#include "shz_quat.hpp"
23#include "shz_xmtrx.hpp"
24
25namespace shz {
26
27 struct mat4x4: public shz_mat4x4_t {
28 static constexpr size_t Rows = 4; //!< Number of rows
29 static constexpr size_t Cols = 4; //!< Number of columns
30
31 mat4x4() noexcept = default;
32
33 SHZ_FORCE_INLINE mat4x4(const mat4x4& other) noexcept {
34 shz_mat4x4_copy(this, &other);
35 }
36
37 SHZ_FORCE_INLINE mat4x4(const shz_mat4x4_t& other) noexcept {
38 shz_mat4x4_copy(this, &other);
39 }
40
41#ifdef SHZ_CPP23
42 //! Returns a pointer to the internal floating-point array held by the matrix.
43 SHZ_FORCE_INLINE auto data(this auto&& self) noexcept {
44 return &self[0];
45 }
46
47 //! Overloaded subscript operator -- allows for indexing matrices like an array.
48 SHZ_FORCE_INLINE auto&& operator[](this auto&& self, size_t index) noexcept {
49 return std::forward<decltype(self)>(self).elem[index];
50 }
51
52 //! Returns an iterator to the beginning of the matrix -- For STL support.
53 SHZ_FORCE_INLINE auto begin(this auto&& self) noexcept {
54 return &self[0];
55 }
56
57 //! Returns an iterator to the end of the matrix -- For STL support.
58 SHZ_FORCE_INLINE auto end(this auto&& self) noexcept {
59 return &self[Rows * Cols];
60 }
61
62 //! Overloaded space-ship operator, for generic lexicographical comparison of matrices.
63 friend constexpr auto operator<=>(const mat4x4& lhs, const mat4x4& rhs) noexcept {
65 rhs.begin(), rhs.end());
66 }
67
68 //! Overloaded "less-than" operator, for comparing matrices.
69 friend constexpr auto operator<(const mat4x4& lhs, const mat4x4& rhs) noexcept {
71 rhs.begin(), rhs.end());
72 }
73#endif
74 //! Overloaded equality operator, for comparing vectors.
75 friend bool operator==(const mat4x4& lhs, const mat4x4& rhs) noexcept {
76 return shz_mat4x4_equal(&lhs, &rhs);
77 }
78
79 mat4x4& operator=(const shz_mat4x4_t& other) noexcept {
80 shz_mat4x4_copy(this, &other);
81 return *this;
82 }
83
84 /*! \name Initialization
85 \brief Routines for fully initializing a matrix.
86 @{
87 */
88
89 SHZ_FORCE_INLINE void init_identity() noexcept {
91 }
92
93 SHZ_DEPRECATED("Operation is always safe now. Use default version.")
94 SHZ_FORCE_INLINE void init_identity_safe() noexcept {
96 }
97
98 SHZ_FORCE_INLINE void init_zero() noexcept {
100 }
101
102 SHZ_FORCE_INLINE void init_one() noexcept {
104 }
105
106 SHZ_FORCE_INLINE void init_fill(float value) noexcept {
107 shz_mat4x4_init_fill(this, value);
108 }
109
110 SHZ_FORCE_INLINE void init_translation(float x, float y, float z) noexcept {
112 }
113
114 SHZ_FORCE_INLINE void init_translation(const vec3& v) noexcept {
115 init_translation(v.x, v.y, v.z);
116 }
117
118 SHZ_FORCE_INLINE void init_scale(float x, float y, float z) noexcept {
120 }
121
122 SHZ_FORCE_INLINE void init_scale(const vec3& v) noexcept {
123 init_scale(v.x, v.y, v.z);
124 }
125
126 SHZ_FORCE_INLINE void init_rotation_x(float angle) noexcept {
128 }
129
130 SHZ_FORCE_INLINE void init_rotation_y(float angle) noexcept {
132 }
133
134 SHZ_FORCE_INLINE void init_rotation_z(float angle) noexcept {
136 }
137
138 SHZ_FORCE_INLINE void init_rotation_xyz(float xAngle, float yAngle, float zAngle) noexcept {
139 shz_mat4x4_init_rotation_xyz(this, xAngle, yAngle, zAngle);
140 }
141
142 SHZ_FORCE_INLINE void init_rotation_zyx(float zAngle, float yAngle, float xAngle) noexcept {
143 shz_mat4x4_init_rotation_zyx(this, zAngle, yAngle, xAngle);
144 }
145
146 SHZ_FORCE_INLINE void init_rotation_zxy(float zAngle, float xAngle, float yAngle) noexcept {
147 shz_mat4x4_init_rotation_zxy(this, zAngle, xAngle, yAngle);
148 }
149
150 SHZ_FORCE_INLINE void init_rotation_yxz(float yAngle, float xAngle, float zAngle) noexcept {
151 shz_mat4x4_init_rotation_yxz(this, yAngle, xAngle, zAngle);
152 }
153
154 SHZ_FORCE_INLINE void init_rotation(float angle, float x, float y, float z) noexcept {
155 shz_mat4x4_init_rotation(this, angle, x, y, z);
156 }
157
158 SHZ_FORCE_INLINE void init_rotation(float angle, const vec3& axis) noexcept {
159 init_rotation(angle, axis.x, axis.y, axis.z);
160 }
161
162 SHZ_FORCE_INLINE void init_rotation_dir(float angle, float x, float y, float z) noexcept {
164 }
165
166 SHZ_FORCE_INLINE void init_rotation_dir(float angle, const vec3& dir) noexcept {
167 init_rotation_dir(angle, dir.x, dir.y, dir.z);
168 }
169
170 SHZ_FORCE_INLINE void init_rotation(const quat& q) noexcept {
172 }
173
174 SHZ_FORCE_INLINE void init_diagonal(float x, float y, float z, float w) noexcept {
176 }
177
178 SHZ_FORCE_INLINE void init_diagonal(const vec4& v) noexcept {
179 init_diagonal(v.x, v.y, v.z, v.w);
180 }
181
182 SHZ_FORCE_INLINE void init_upper_triangular(float col1, const vec2& col2, const vec3& col3, const vec4& col4) noexcept{
183 shz_mat4x4_init_upper_triangular(this, col1, col2, col3, col4);
184 }
185
186 SHZ_FORCE_INLINE void init_lower_triangular(const vec4& col1, const vec3& col2, const vec2& col3, float col4) noexcept {
187 shz_mat4x4_init_lower_triangular(this, col1, col2, col3, col4);
188 }
189
190 SHZ_FORCE_INLINE void init_symmetric_skew(float x, float y, float z) noexcept {
192 }
193
194 SHZ_FORCE_INLINE void init_symmetric_skew(const vec3& v) noexcept {
195 init_symmetric_skew(v.x, v.y, v.z);
196 }
197
198 SHZ_FORCE_INLINE void init_outer_product(const vec4& v1, const vec4& v2) noexcept {
199 shz_mat4x4_init_outer_product(this, v1, v2);
200 }
201
202 SHZ_FORCE_INLINE void init_permutation_wxyz() noexcept {
204 }
205
206 SHZ_FORCE_INLINE void init_permutation_yzwx() noexcept {
208 }
209
210 SHZ_FORCE_INLINE void init_screen(float width, float height) noexcept {
211 shz_mat4x4_init_screen(this, width, height);
212 }
213
214 SHZ_FORCE_INLINE void init_lookat(const vec3& eye, const vec3& center, const vec3& up) noexcept {
215 shz_mat4x4_init_lookat(this, eye, center, up);
216 }
217
218 SHZ_FORCE_INLINE void init_ortho(float left, float right, float bottom, float top, float znear, float zfar) noexcept {
219 shz_mat4x4_init_ortho(this, left, right, bottom, top, znear, zfar);
220 }
221
222 SHZ_FORCE_INLINE void init_frustum(float left, float right, float bottom, float top, float znear, float zfar) noexcept {
223 shz_mat4x4_init_frustum(this, left, right, bottom, top, znear, zfar);
224 }
225
226 SHZ_FORCE_INLINE void init_perspective(float fov, float aspect, float znear) noexcept {
227 shz_mat4x4_init_perspective(this, fov, aspect, znear);
228 }
229
230 //! @}
231
232 /*! \name Getting
233 \brief Routines for getting specific values within a matrix
234 @{
235 */
236
237 //! C++ wrapper for shz_mat4x4_row().
238 SHZ_FORCE_INLINE vec4 row(size_t index) const noexcept {
239 return shz_mat4x4_row(this, index);
240 }
241
242 //! C++ wrapper for shz_mat4x4_col().
243 SHZ_FORCE_INLINE vec4 col(size_t index) const noexcept {
244 return shz_mat4x4_col(this, index);
245 }
246
247 SHZ_FORCE_INLINE vec3 get_translation() const noexcept {
249 }
250
251 /*! Returns the scaling components from the inner 3x3 matrix of XMTRX, as a 3D vector.
252
253 \warning This routine assumes XMTRX is a standard TRS-style transform matrix,
254 without shearing or reflection.
255 */
256 SHZ_FORCE_INLINE vec3 get_scale() const noexcept {
257 return shz_mat4x4_get_scale(this);
258 }
259
260 //! @}
261
262 /*! \name Setting
263 \brief Routines for setting specific values within a matrix
264 @{
265 */
266
267 SHZ_FORCE_INLINE void set_row(size_t index, vec4 values) noexcept {
268 shz_mat4x4_set_row(this, index, values);
269 }
270
271 SHZ_FORCE_INLINE void set_col(size_t index, vec4 values) noexcept {
272 shz_mat4x4_set_col(this, index, values);
273 }
274
275 SHZ_FORCE_INLINE void swap_rows(size_t row1, size_t row2) noexcept {
276 shz_mat4x4_swap_rows(this, row1, row2);
277 }
278
279 SHZ_FORCE_INLINE void swap_cols(size_t col1, size_t col2) noexcept {
280 shz_mat4x4_swap_cols(this, col1, col2);
281 }
282
283 SHZ_FORCE_INLINE void set_translation(float x, float y, float z) noexcept {
285 }
286
287 SHZ_FORCE_INLINE void set_translation(const vec3& v) noexcept {
288 set_translation(v.x, v.y, v.z);
289 }
290
291 SHZ_FORCE_INLINE void set_scale(float x, float y, float z) noexcept {
293 }
294
295 SHZ_FORCE_INLINE void set_scale(const vec3& v) noexcept {
296 set_scale(v.x, v.y, v.z);
297 }
298
299 SHZ_FORCE_INLINE void set_rotation(const quat& rot) noexcept {
301 }
302
303 SHZ_FORCE_INLINE void set_diagonal(float x, float y, float z, float w) noexcept {
305 }
306
307 SHZ_FORCE_INLINE void set_diagonal(const vec4& v) noexcept {
308 set_diagonal(v.x, v.y, v.z, v.w);
309 }
310
311 //! @}
312
313 /*! \name Applying
314 \brief Routines for multiplying and accumulating onto the given matrix.
315 @{
316 */
317
318 SHZ_FORCE_INLINE void apply(const shz_mat4x4_t& mat) noexcept {
319 shz_mat4x4_apply(this, &mat);
320 }
321
322 SHZ_FORCE_INLINE void apply(const float mat[16]) noexcept {
324 }
325
326 SHZ_FORCE_INLINE void apply_transpose(const shz_mat4x4_t& mat) noexcept {
328 }
329
330 SHZ_FORCE_INLINE void apply_transpose(const float mat[16]) noexcept {
332 }
333
334 SHZ_FORCE_INLINE void apply_scale(float x, float y, float z) noexcept {
336 }
337
338 SHZ_FORCE_INLINE void apply_scale(const vec3& v) noexcept {
339 apply_scale(v.x, v.y, v.z);
340 }
341
342 SHZ_FORCE_INLINE void apply_translation(float x, float y, float z) noexcept {
344 }
345
346 SHZ_FORCE_INLINE void apply_translation(const vec3& v) noexcept {
347 apply_translation(v.x, v.y, v.z);
348 }
349
350 SHZ_FORCE_INLINE void apply_rotation_x(float angle) noexcept {
352 }
353
354 SHZ_FORCE_INLINE void apply_rotation_y(float angle) noexcept {
356 }
357
358 SHZ_FORCE_INLINE void apply_rotation_z(float angle) noexcept {
360 }
361
362 SHZ_FORCE_INLINE void apply_rotation_xyz(float xAngle, float yAngle, float zAngle) noexcept {
363 shz_mat4x4_apply_rotation_xyz(this, xAngle, yAngle, zAngle);
364 }
365
366 SHZ_FORCE_INLINE void apply_rotation_zyx(float zAngle, float yAngle, float xAngle) noexcept {
367 shz_mat4x4_apply_rotation_zyx(this, zAngle, yAngle, xAngle);
368 }
369
370 SHZ_FORCE_INLINE void apply_rotation_zxy(float zAngle, float xAngle, float yAngle) noexcept {
371 shz_mat4x4_apply_rotation_zxy(this, zAngle, xAngle, yAngle);
372 }
373
374 SHZ_FORCE_INLINE void apply_rotation_yxz(float yAngle, float xAngle, float zAngle) noexcept {
375 shz_mat4x4_apply_rotation_yxz(this, yAngle, xAngle, zAngle);
376 }
377
378 SHZ_FORCE_INLINE void apply_rotation(float angle, float x, float y, float z) noexcept {
379 shz_mat4x4_apply_rotation(this, angle, x, y, z);
380 }
381
382 SHZ_FORCE_INLINE void apply_rotation(float angle, vec3 axis) noexcept {
383 apply_rotation(angle, axis.x, axis.y, axis.z);
384 }
385
386 SHZ_FORCE_INLINE void apply_rotation(const quat& q) noexcept {
388 }
389
390 SHZ_FORCE_INLINE void apply_lookat(vec3 pos, vec3 target, vec3 up) noexcept {
391 shz_mat4x4_apply_lookat(this, pos, target, up);
392 }
393
394 SHZ_FORCE_INLINE void apply_ortho(float left, float right, float bottom, float top, float znear, float zfar) noexcept {
395 shz_mat4x4_apply_ortho(this, left, right, bottom, top, znear, zfar);
396 }
397
398 SHZ_FORCE_INLINE void apply_frustum(float left, float right, float bottom, float top, float znear, float zfar) noexcept {
399 shz_mat4x4_apply_frustum(this, left, right, bottom, top, znear, zfar);
400 }
401
402 SHZ_FORCE_INLINE void apply_perspective(float fov, float aspect, float znear) noexcept {
403 shz_mat4x4_apply_perspective(this, fov, aspect, znear);
404 }
405
406 SHZ_FORCE_INLINE void apply_screen(float width, float height) noexcept {
407 shz_mat4x4_apply_screen(this, width, height);
408 }
409
410 SHZ_FORCE_INLINE void apply_symmetric_skew(float x, float y, float z) noexcept {
412 }
413
414 SHZ_FORCE_INLINE void apply_permutation_wxyz() noexcept {
416 }
417
418 SHZ_FORCE_INLINE void apply_permutation_yzwx() noexcept {
420 }
421
422 SHZ_FORCE_INLINE void apply_self() noexcept {
424 }
425
426 //! @}
427
428 /*! \name GL Transformations
429 \brief OpenGL-style 4x4 matrix transforms.
430 @{
431 */
432
433 SHZ_FORCE_INLINE void translate(float x, float y, float z) noexcept {
435 }
436
437 SHZ_FORCE_INLINE void translate(vec3 v) noexcept {
438 translate(v.x, v.y, v.z);
439 }
440
441 SHZ_FORCE_INLINE void scale(float x, float y, float z) noexcept {
442 shz_mat4x4_scale(this, x, y, z);
443 }
444
445 SHZ_FORCE_INLINE void scale(vec3 v) noexcept {
446 scale(v.x, v.y, v.z);
447 }
448
449 SHZ_FORCE_INLINE void rotate_x(float radians) noexcept {
450 shz_mat4x4_rotate_x(this, radians);
451 }
452
453 SHZ_FORCE_INLINE void rotate_y(float radians) noexcept {
454 shz_mat4x4_rotate_y(this, radians);
455 }
456
457 SHZ_FORCE_INLINE void rotate_z(float radians) noexcept {
458 shz_mat4x4_rotate_z(this, radians);
459 }
460
461 SHZ_FORCE_INLINE void rotate_xyz(float xRadians, float yRadians, float zRadians) noexcept {
462 shz_mat4x4_rotate_xyz(this, xRadians, yRadians, zRadians);
463 }
464
465 SHZ_FORCE_INLINE void rotate_zyx(float zRadians, float yRadians, float xRadians) noexcept {
466 shz_mat4x4_rotate_zyx(this, zRadians, yRadians, xRadians);
467 }
468
469 SHZ_FORCE_INLINE void rotate_zxy(float zRadians, float xRadians, float yRadians) noexcept {
470 shz_mat4x4_rotate_zxy(this, zRadians, xRadians, yRadians);
471 }
472
473 SHZ_FORCE_INLINE void rotate_yxz(float yRadians, float xRadians, float zRadians) noexcept {
474 shz_mat4x4_rotate_yxz(this, yRadians, xRadians, zRadians);
475 }
476
477 SHZ_FORCE_INLINE void rotate(float radians, float xAxis, float yAxis, float zAxis) noexcept {
478 shz_mat4x4_rotate(this, radians, xAxis, yAxis, zAxis);
479 }
480
481 SHZ_FORCE_INLINE void rotate(float radians, vec3 axis) noexcept {
482 rotate(radians, axis.x, axis.y, axis.z);
483 }
484
485 //! @}
486
487 /*! \name Reverse GL Transformations
488 \brief Pre-multiplication variants of OpenGL-style 4x4 matrix transforms.
489 @{
490 */
491
492 /*! Pre-multiplies and accumulates the given matrix onto the 3D translation matrix with the given components.
493
494 \warning This routin clobbers XMTRX.
495 */
496 SHZ_FORCE_INLINE void translate_reverse(float x, float y, float z) noexcept {
498 }
499
500 /*! Pre-multiplies and accumulates the given matrix onto the 3D translation matrix with the given position vector.
501
502 \warning This routin clobbers XMTRX.
503 */
504 SHZ_FORCE_INLINE void translate_reverse(const shz::vec3& pos) noexcept {
505 translate_reverse(pos.x, pos.y, pos.z);
506 }
507
508 /*! Pre-multiplies and accumulates the given matrix onto the 3D scaling matrix with the given components.
509
510 \warning This routine clobbers XMTRX
511 */
512 SHZ_FORCE_INLINE void scale_reverse(float x, float y, float z) noexcept {
514 }
515
516 /*! Pre-multiplies and accumulates the given matrix onto the 3D scaling matrix with the given size vector.
517
518 \warning This routine clobbers XMTRX
519 */
520 SHZ_FORCE_INLINE void scale_reverse(const shz::vec3& size) noexcept {
521 scale_reverse(size.x, size.y, size.z);
522 }
523
524 //! @}
525
526 /*! \name Multiplication
527 \brief Routines for multiplying two matrices and storing the result in a third.
528 @{
529 */
530
531 SHZ_FORCE_INLINE static void mult(shz_mat4x4_t* dst, const shz_mat4x4_t& lhs, const shz_mat4x4_t& rhs) noexcept {
532 shz_mat4x4_mult(dst, &lhs, &rhs);
533 }
534
535 SHZ_FORCE_INLINE static void mult(shz_mat4x4_t* dst, const shz_mat4x4_t& lhs, const float rhs[16]) noexcept {
537 }
538
539 SHZ_FORCE_INLINE static void mult_transpose(shz_mat4x4_t* dst, const shz_mat4x4_t& lhs, const shz_mat4x4_t& rhs) noexcept {
541 }
542
543 SHZ_FORCE_INLINE static void mult_transpose(shz_mat4x4_t* dst, const shz_mat4x4_t& lhs, const float rhs[16]) noexcept {
545 }
546
547 //! @}
548
549 /*! \name Transforming
550 \brief Routines for transforming vectors and points by a matrix.
551 @{
552 */
553
554 SHZ_FORCE_INLINE vec2 transform(const vec2& in) const noexcept {
555 return shz_mat4x4_transform_vec2(this, in);
556 }
557
558 SHZ_FORCE_INLINE vec3 transform(const vec3& in) const noexcept {
559 return shz_mat4x4_transform_vec3(this, in);
560 }
561
562 SHZ_FORCE_INLINE vec4 transform(const vec4& in) const noexcept {
563 return shz_mat4x4_transform_vec4(this, in);
564 }
565
566 SHZ_FORCE_INLINE vec2 transform_point(const vec2& pt) const noexcept {
567 return shz_mat4x4_transform_point2(this, pt);
568 }
569
570 SHZ_FORCE_INLINE vec3 transform_point(const vec3& pt) const noexcept {
571 return shz_mat4x4_transform_point3(this, pt);
572 }
573
574 SHZ_FORCE_INLINE vec2 transform_transpose(const vec2& in) const noexcept {
575 return shz_mat4x4_transform_vec2_transpose(this, in);
576 }
577
578 SHZ_FORCE_INLINE vec3 transform_transpose(const vec3& in) const noexcept {
579 return shz_mat4x4_transform_vec3_transpose(this, in);
580 }
581
582 SHZ_FORCE_INLINE vec4 transform_transpose(const vec4& in) const noexcept {
583 return shz_mat4x4_transform_vec4_transpose(this, in);
584 }
585
586 SHZ_FORCE_INLINE vec2 transform_point_transpose(const vec2& pt) const noexcept {
587 return shz_mat4x4_transform_point2_transpose(this, pt);
588 }
589
590 SHZ_FORCE_INLINE vec3 transform_point_transpose(const vec3& pt) const noexcept {
591 return shz_mat4x4_transform_point3_transpose(this, pt);
592 }
593
594 //! @}
595
596 /*! \name Miscellaneous
597 \brief Other matrix-related operations and routines
598 @{
599 */
600
601 SHZ_FORCE_INLINE static void copy(shz_mat4x4_t* lhs, const shz_mat4x4_t& rhs) noexcept {
602 shz_mat4x4_copy(lhs, &rhs);
603 }
604
605 SHZ_FORCE_INLINE static void copy(shz_mat4x4_t* lhs, const float rhs[16]) noexcept {
607 }
608
609 friend SHZ_FORCE_INLINE void swap(shz_mat4x4_t& matA, shz_mat4x4_t& matB) noexcept {
610 shz_mat4x4_swap(&matA, &matB);
611 }
612
613 SHZ_FORCE_INLINE quat to_quat() const noexcept {
614 return shz_mat4x4_to_quat(this);
615 }
616
617 SHZ_FORCE_INLINE float determinant() const noexcept {
618 return shz_mat4x4_determinant(this);
619 }
620
621 SHZ_FORCE_INLINE float trace() const noexcept {
622 return shz_mat4x4_trace(this);
623 }
624
625 SHZ_FORCE_INLINE void inverse(mat4x4* out) const noexcept {
626 shz_mat4x4_inverse(this, out);
627 }
628
629 SHZ_FORCE_INLINE void inverse_block_triangular(mat4x4* out) const noexcept {
631 }
632
633 SHZ_FORCE_INLINE void decompose(vec3* translation, quat* rotation, vec3* scale) const noexcept {
634 shz_mat4x4_decompose(this, translation, rotation, scale);
635 }
636
637 /*! Adds and accumulates a scaled 4x4 matrix into the given matrix.
638
639 Each component of \p joint_matrix will be multiplied by \p weight, with the result
640 being added to the existing value of that component in \p dst.
641
642 This is useful for accumulating weighted joint matrices onto an initially
643 zeroed-out matrix.
644
645 \warning This routine clobbers XMTRX.
646
647 \sa shz_mat4x4_init_zero()
648 */
649 SHZ_FORCE_INLINE void blend(const shz_mat4x4_t& joint_matrix, float weight) noexcept {
650 shz_mat4x4_blend(this, &joint_matrix, weight);
651 }
652
653 //! @}
654 };
655
656 //! Alternate mat4x4 C++ alias for those who like POSIX style.
657 using mat4x4_t = mat4x4;
658}
659
660#endif
Namespace enclosing the SH4ZAM C++ API.
Definition shz_cdefs.hpp:21
void shz_mat4x4_apply_rotation_y(shz_mat4x4_t *mat, float yAngle) SHZ_NOEXCEPT
Multiplies and accumulates a rotation matrix by yAngle radians about the Y-axis onto the given matrix...
void shz_mat4x4_scale(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Multiplies and accumulates mat by a 3D scaling matrix with the given components.
void shz_mat4x4_init_rotation_z(shz_mat4x4_t *mat, float zAngle) SHZ_NOEXCEPT
Initializes the given matrix to a 3D rotation matrix by zAngle radians over the Z-axis.
void shz_mat4x4_set_diagonal(shz_mat4x4_t *mat, float x, float y, float z, float w) SHZ_NOEXCEPT
Assigns only the 4 elements along the diagonal of the given matrix to the given values.
void shz_mat4x4_init_rotation_zxy(shz_mat4x4_t *mat, float zAngle, float xAngle, float yAngle) SHZ_NOEXCEPT
Initializes the given matrix to a 3D rotation matrix from the intrinsic rotation created by the given...
void shz_mat4x4_apply_permutation_yzwx(shz_mat4x4_t *mat) SHZ_NOEXCEPT
Multiplies and accumulates a permutation matrix, which reorders the components of transformed vectors...
void shz_mat4x4_init_frustum(shz_mat4x4_t *mat, float left, float right, float bottom, float top, float znear, float zfar) SHZ_NOEXCEPT
Initializes the given matrix to a frustum projection matrix.
void shz_mat4x4_mult_transpose_unaligned(shz_mat4x4_t *mat, const shz_mat4x4_t *lhs, const float rhs[16]) SHZ_NOEXCEPT
Multiplies the regular matrix, lhs, by the transpose of the unaligned matrix, rhs,...
void shz_mat4x4_copy_unaligned(shz_mat4x4_t *dst, const float src[16]) SHZ_NOEXCEPT
Copies the given unaligned src 4x4 matrix into the given dst 4x4 matrix.
void shz_mat4x4_rotate_y(shz_mat4x4_t *mat, float radians) SHZ_NOEXCEPT
Multiplies and accumulates mat by a 3D rotation matrix about the Y axis.
void shz_mat4x4_mult_transpose(shz_mat4x4_t *mat, const shz_mat4x4_t *lhs, const shz_mat4x4_t *rhs) SHZ_NOEXCEPT
Multiplies the regular matrix, lhs, by the transpose of the matrix, rhs, storing the result into mat.
void shz_mat4x4_mult(shz_mat4x4_t *mat, const shz_mat4x4_t *lhs, const shz_mat4x4_t *rhs) SHZ_NOEXCEPT
Multiplies two 4x4 matrices together, storing the result into a third.
void shz_mat4x4_apply_transpose(shz_mat4x4_t *dst, const shz_mat4x4_t *src) SHZ_NOEXCEPT
Multiplies and accumulates the transposed src 4x4 matrix onto the dst 4x4 matrix.
void shz_mat4x4_apply_transpose_unaligned(shz_mat4x4_t *dst, const float src[16]) SHZ_NOEXCEPT
Multiplies and accumulates the transposed unaligned src 4x4 matrix onto the dst 4x4 matrix.
void shz_mat4x4_init_identity(shz_mat4x4_t *mat) SHZ_NOEXCEPT
Initializes the given matrix to the 4x4 identity matrix.
void shz_mat4x4_init_rotation(shz_mat4x4_t *mat, float radians, float xAxis, float yAxis, float zAxis) SHZ_NOEXCEPT
Initializes the given 4x4 matrix to a 3D rotation matrix of angle radians about the vector with the g...
void shz_mat4x4_init_permutation_wxyz(shz_mat4x4_t *mat) SHZ_NOEXCEPT
Initializes the matrix to to a permutation matrix, which reorders the components of transformed vecto...
void shz_mat4x4_init_rotation_xyz(shz_mat4x4_t *mat, float xAngle, float yAngle, float zAngle) SHZ_NOEXCEPT
Initializes the given matrix to a 3D rotation matrix from the intrinsic rotation created by the given...
void shz_mat4x4_apply_perspective(shz_mat4x4_t *m, float fov, float aspect, float znear) SHZ_NOEXCEPT
Multiplies and accumulates the perspective matrix constructed from the given values onto the given ma...
void shz_mat4x4_apply_rotation_quat(shz_mat4x4_t *m, shz_quat_t q) SHZ_NOEXCEPT
Multiplies and accumulates the given matrix with a rotation matrix whose orientation is given by a qu...
void shz_mat4x4_init_rotation_y(shz_mat4x4_t *mat, float yAngle) SHZ_NOEXCEPT
Initializes the given matrix to a 3D rotation matrix by yAngle radians over the Y-axis.
void shz_mat4x4_init_zero(shz_mat4x4_t *mat) SHZ_NOEXCEPT
Initializes the given matrix with all 0s for its element values.
void shz_mat4x4_swap_rows(shz_mat4x4_t *mat, size_t row1, size_t row2) SHZ_NOEXCEPT
Swaps the 4D row vectors located at row1 and row2 within mat.
float shz_mat4x4_determinant(const shz_mat4x4_t *mat) SHZ_NOEXCEPT
Returns the determinant of the given 4x4 matrix.
void shz_mat4x4_apply_screen(shz_mat4x4_t *m, float width, float height) SHZ_NOEXCEPT
Multiplies and accumulates the viewport matrix created with the given components ont othe given matri...
void shz_mat4x4_init_rotation_x(shz_mat4x4_t *mat, float xAngle) SHZ_NOEXCEPT
Initializes the given matrix to a 3D rotation matrix by xAngle radians over the X-axis.
float shz_mat4x4_trace(const shz_mat4x4_t *mat) SHZ_NOEXCEPT
Returns the trace of the given 4x4 matrix.
void shz_mat4x4_apply_rotation_zxy(shz_mat4x4_t *mat, float zAngle, float xAngle, float yAngle) SHZ_NOEXCEPT
Rotates the given transform matrix about the Z axis, then the X axis, then the Y axis by the given an...
void shz_mat4x4_apply_symmetric_skew(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Multiplies and accumulates the given matrix with a symmetric skew matrix formed from the given 3D vec...
void shz_mat4x4_apply_self(shz_mat4x4_t *mat) SHZ_NOEXCEPT
Multiplies and accumulates the given matrix onto itself.
void shz_mat4x4_init_scale(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Initializes the given matrix to a 3D scaling matrix with the given dimensions.
void shz_mat4x4_init_ortho(shz_mat4x4_t *mat, float left, float right, float bottom, float top, float znear, float zfar) SHZ_NOEXCEPT
Initializes the given matrix to an orthographic projection matrix.
void shz_mat4x4_apply_rotation_xyz(shz_mat4x4_t *mat, float xAngle, float yAngle, float zAngle) SHZ_NOEXCEPT
Rotates the given transform matrix about the X axis, then the Y axis, then the Z axis by the given an...
void shz_mat4x4_translate(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Multiplies and accumulates mat by a 3D translation matrix with the given components.
shz_vec4_t shz_mat4x4_col(const shz_mat4x4_t *mat, size_t col) SHZ_NOEXCEPT
Extracts the col index as a 4D column vector from the given matrix.
void shz_mat4x4_apply_permutation_wxyz(shz_mat4x4_t *mat) SHZ_NOEXCEPT
Multiplies and accumulates a permutation matrix, which reorders the components of transformed vectors...
void shz_mat4x4_rotate(shz_mat4x4_t *mat, float radians, float xAxis, float yAxis, float zAxis) SHZ_NOEXCEPT
Multiplies and accumulates mat by the 3D rotation matrix formed by the given axis and angle.
void shz_mat4x4_apply_rotation_yxz(shz_mat4x4_t *mat, float yAngle, float xAngle, float zAngle) SHZ_NOEXCEPT
Rotates the given transform matrix about the Y axis, then the X axis, then the Z axis by the given an...
void shz_mat4x4_set_translation(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Assigns only the 3D translation-related elements of the given matrix to the given values.
void shz_mat4x4_init_perspective(shz_mat4x4_t *mat, float fov, float aspect, float znear) SHZ_NOEXCEPT
Initializes the given matrix to a perspective projection matrix.
void shz_mat4x4_rotate_xyz(shz_mat4x4_t *mat, float xRadians, float yRadians, float zRadians) SHZ_NOEXCEPT
Multiplies and accumulates mat by 3D rotation matrices about the X then Y then Z axes.
shz_vec3_t shz_mat4x4_get_scale(const shz_mat4x4_t *mat) SHZ_NOEXCEPT
Exracts the 3D scale factors from the given 4x4 matrix.
void shz_mat4x4_apply_frustum(shz_mat4x4_t *m, float left, float right, float bottom, float top, float znear, float zfar) SHZ_NOEXCEPT
Multiplies and accumulates the frustum matrix constructed from the given values onto the given matrix...
void shz_mat4x4_rotate_yxz(shz_mat4x4_t *mat, float yRadians, float xRadians, float zRadians) SHZ_NOEXCEPT
Multiplies and accumulates mat by 3D rotation matrices about the Y then X then Z axes.
shz_quat_t shz_mat4x4_to_quat(const shz_mat4x4_t *mat) SHZ_NOEXCEPT
Converts the given 4x4 orientation matrix into a quaternion.
void shz_mat4x4_translate_reverse(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Pre-multiplies and accumulates the given matrix onto the 3D translation matrix with the given compone...
void shz_mat4x4_apply(shz_mat4x4_t *dst, const shz_mat4x4_t *src) SHZ_NOEXCEPT
Multiplies and accumulates the src 4x4 matrix onto the dst 4x4 matrix.
void shz_mat4x4_rotate_zxy(shz_mat4x4_t *mat, float zRadians, float xRadians, float yRadians) SHZ_NOEXCEPT
Multiplies and accumulates mat by 3D rotation matrices about the Z then X then Y axes.
void shz_mat4x4_blend(shz_mat4x4_t *dst, const shz_mat4x4_t *joint_matrix, float weights) SHZ_NOEXCEPT
Adds and accumulates a scaled 4x4 matrix into the given matrix.
void shz_mat4x4_scale_reverse(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Pre-multiplies and accumulates the given matrix onto the 3D scaling matrix with the given components.
void shz_mat4x4_swap_cols(shz_mat4x4_t *mat, size_t col1, size_t col2) SHZ_NOEXCEPT
Swaps the 4D column vectors located at col1 and col2 within mat.
void shz_mat4x4_init_translation(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Initializes the given matrix to a 3D translation matrix with the given coordinates.
void shz_mat4x4_apply_rotation_zyx(shz_mat4x4_t *mat, float zAngle, float yAngle, float xAngle) SHZ_NOEXCEPT
Rotates the given transform matrix about the Z axis, then the Y axis, then the X axis by the given an...
void shz_mat4x4_copy(shz_mat4x4_t *dst, const shz_mat4x4_t *src) SHZ_NOEXCEPT
Copies the given src 4x4 matrix into the given dst 4x4 matrix.
void shz_mat4x4_rotate_z(shz_mat4x4_t *mat, float radians) SHZ_NOEXCEPT
Multiplies and accumulates mat by a 3D rotation matrix about the Z axis.
void shz_mat4x4_apply_rotation_z(shz_mat4x4_t *mat, float zAngle) SHZ_NOEXCEPT
Multiplies and accumulates a rotation matrix by zAngle radians about the Z-axis onto the given matrix...
void shz_mat4x4_set_scale(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Assigns only the 3D scale-related elements of the given matrix to the given values.
void shz_mat4x4_apply_scale(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Multiplies and accumulates the scale-related elements of the given matrix by the given 3D components.
void shz_mat4x4_set_rotation_quat(shz_mat4x4_t *m, shz_quat_t q) SHZ_NOEXCEPT
Sets just the rotational component of the matrix to the orientation given by a quaternion,...
void shz_mat4x4_init_rotation_dir(shz_mat4x4_t *mat, float angle, float x, float y, float z) SHZ_NOEXCEPT
Initializes the given 4x4 matrix to contain a 3D rotation matrix of angle radians about the given dir...
void shz_mat4x4_apply_translation(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Adds the given 3D vector components to the translational values of the given matrix.
void shz_mat4x4_rotate_zyx(shz_mat4x4_t *mat, float zRadians, float yRadians, float xRadians) SHZ_NOEXCEPT
Multiplies and accumulates mat by 3D rotation matrices about the Z then Y then X axes.
void shz_mat4x4_mult_unaligned(shz_mat4x4_t *mat, const shz_mat4x4_t *lhs, const float rhs[16]) SHZ_NOEXCEPT
Multiplies two 4x4 matrices together, with the right handed matrix being unaligned,...
void shz_mat4x4_rotate_x(shz_mat4x4_t *mat, float radians) SHZ_NOEXCEPT
Multiplies and accumulates mat by a 3D rotation matrix about the X axis.
void shz_mat4x4_init_symmetric_skew(shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
Initializes the given matrix to be the symmetric skew of the given 3D vector components.
void shz_mat4x4_init_rotation_yxz(shz_mat4x4_t *mat, float yAngle, float xAngle, float zAngle) SHZ_NOEXCEPT
Initializes the given matrix to a 3D rotation matrix from the intrinsic rotation created by the given...
void shz_mat4x4_init_diagonal(shz_mat4x4_t *mat, float x, float y, float z, float w) SHZ_NOEXCEPT
Initializes the given matrix to a diagonal matrix with the given 4 values.
void shz_mat4x4_init_rotation_zyx(shz_mat4x4_t *mat, float zAngle, float yAngle, float xAngle) SHZ_NOEXCEPT
Initializes the given matrix to a 3D rotation matrix from the intrinsic rotation created by the given...
void shz_mat4x4_init_permutation_yzwx(shz_mat4x4_t *mat) SHZ_NOEXCEPT
Initializes the matrix to to a permutation matrix, which reorders the components of transformed vecto...
void shz_mat4x4_swap(shz_mat4x4_t *matA, shz_mat4x4_t *matB) SHZ_NOEXCEPT
Swaps the contents of the two given matrices, matA and matB.
shz_vec3_t shz_mat4x4_get_translation(const shz_mat4x4_t *mat) SHZ_NOEXCEPT
Returns the translational components from the 4th column as a 3D vector.
void shz_mat4x4_apply_rotation_x(shz_mat4x4_t *mat, float xAngle) SHZ_NOEXCEPT
Multiplies and accumulates a rotation matrix by xAngle radians about the X-axis onto the given matrix...
void shz_mat4x4_init_fill(shz_mat4x4_t *mat, float value) SHZ_NOEXCEPT
Initializes the given matrix with all elements assigned to the given value.
void shz_mat4x4_apply_unaligned(shz_mat4x4_t *dst, const float src[16]) SHZ_NOEXCEPT
Multiplies and accumulates the unaligned src 4x4 matrix onto the dst 4x4 matrix.
void shz_mat4x4_apply_ortho(shz_mat4x4_t *m, float left, float right, float bottom, float top, float znear, float zfar) SHZ_NOEXCEPT
Multiplies and accumulates the ortho matrix constructed from the given values onto the given matrix.
shz_vec4_t shz_mat4x4_row(const shz_mat4x4_t *mat, size_t row) SHZ_NOEXCEPT
Extracts the row index as a 4D row vector from the given matrix.
bool shz_mat4x4_equal(const shz_mat4x4_t *SHZ_RESTRICT mat1, const shz_mat4x4_t *mat2) SHZ_NOEXCEPT
Returns true if the two matrices are equal, based on either absolute or relative tolerance.
void shz_mat4x4_apply_rotation(shz_mat4x4_t *mat, float angle, float xAxis, float yAxis, float zAxis) SHZ_NOEXCEPT
Rotates the given transform matrix about the arbitrary axis given by a 3D direction vector and angle ...
void shz_mat4x4_inverse(const shz_mat4x4_t *SHZ_RESTRICT mtrx, shz_mat4x4_t *SHZ_RESTRICT out) SHZ_NOEXCEPT
Computes the inverse of a 4x4 matrix.
void shz_mat4x4_init_one(shz_mat4x4_t *mat) SHZ_NOEXCEPT
Initializes the given matrix with all 1s for its element values.
void shz_mat4x4_init_rotation_quat(shz_mat4x4_t *m, shz_quat_t q) SHZ_NOEXCEPT
Initializes the given matrix to a 3D rotation matrix with its orientation given by a quaternion.
void shz_mat4x4_inverse_block_triangular(const shz_mat4x4_t *mtx, shz_mat4x4_t *out) SHZ_NOEXCEPT
Computes the inverse of a 4x4 matrix in block-triangular form.
void shz_mat4x4_init_screen(shz_mat4x4_t *mat, float width, float height) SHZ_NOEXCEPT
Initializes the given matrix to the viewport matrix with the given dimenions.
vec4 row(size_t index) const noexcept
C++ wrapper for shz_mat4x4_row().
vec3 get_scale() const noexcept
Returns the scaling components from the inner 3x3 matrix of XMTRX, as a 3D vector.
vec4 col(size_t index) const noexcept
C++ wrapper for shz_mat4x4_col().
static constexpr size_t Rows
Number of rows.
friend bool operator==(const mat4x4 &lhs, const mat4x4 &rhs) noexcept
Overloaded equality operator, for comparing vectors.
static constexpr size_t Cols
Number of columns.
void blend(const shz_mat4x4_t &joint_matrix, float weight) noexcept
Adds and accumulates a scaled 4x4 matrix into the given matrix.
void scale_reverse(float x, float y, float z) noexcept
Pre-multiplies and accumulates the given matrix onto the 3D scaling matrix with the given components.
void translate_reverse(float x, float y, float z) noexcept
Pre-multiplies and accumulates the given matrix onto the 3D translation matrix with the given compone...
void translate_reverse(const shz::vec3 &pos) noexcept
Pre-multiplies and accumulates the given matrix onto the 3D translation matrix with the given positio...
void scale_reverse(const shz::vec3 &size) noexcept
Pre-multiplies and accumulates the given matrix onto the 3D scaling matrix with the given size vector...
C++ structure representing a quaternion.
Definition shz_quat.hpp:38
2D Vector type
3D Vector type
4D Vector type