SH4ZAM! 0.9.1
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz_xmtrx.h
Go to the documentation of this file.
1/*! \file
2 * \brief Active Matrix API.
3 * \ingroup xmtrx
4 *
5 * This file provides an API built around manipulating and performing
6 * calculations using the SH4's "current" 4x4 matrix, which is held within
7 * a secondary back-bank of 16 single-precision floating-point registers.
8 *
9 * \todo
10 * - shz_xmtrx_xxx_fft()
11 * - shz_xmtrx_invert() (within XMTRX)
12 * - shz_xmtrx_position()
13 * - shz_xmtrx_size()
14 * - shz_xmtrx_angles()
15 * - shz_xmtrx_init_rotation_quat() (within XMTRX)
16 * - shz_xmtrx_apply_store_4x4()
17 *
18 * \author 2025, 2026 Falco Girgis
19 * \author 2025 Twada
20 * \author 2026 TapamN
21 *
22 * \copyright MIT License
23 */
24
25#ifndef SHZ_XMTRX_H
26#define SHZ_XMTRX_H
27
28#include "shz_vector.h"
29#include "shz_quat.h"
30
31/*! \defgroup xmtrx XMTRX
32 \brief API for managing the SH4's "active matrix."
33
34 `XMTRX` is the name given to identify the 16 FP registers contained
35 within the back-bank of the SH4's FPU. These 16 registers combine
36 to represent the SH4's 4x4 "active matrix," which can be subsequently
37 transformed against using the `FTRV` instruction (shz_xmtrx_trans_vec4()).
38
39 For maximum FP performance on the SH4, strategic usage of `XMTRX` to batch
40 transform operations together without having reload FP registers, is key.
41
42 Typically, for one-off operations, the in-memory API for \ref matrix is
43 what should be used; however, when operations can be batched, using `XMTRX`
44 to hold your matrix within registers is going to give the best performance.
45
46 Examples of such scenarios are:
47 - Applying multiple operations to a source matrix before storing the result.
48 - Transforming batches of vectors against a single matrix.
49
50 \note
51 Unless TLS has been disabled, the XMTRX API is thread-safe, with each thread
52 getting its own unique copy of XMTRX.
53
54 \sa matrix
55 */
56
57SHZ_DECLS_BEGIN
58
59/*! \cond Forward Declarations */
60SHZ_DECLARE_STRUCT_ALIGNED(shz_mat2x2, shz_mat2x2_t, 8);
62SHZ_DECLARE_STRUCT (shz_mat3x3, shz_mat3x3_t);
63SHZ_DECLARE_STRUCT (shz_mat4x3, shz_mat4x3_t);
64SHZ_DECLARE_STRUCT (shz_mat3x4, shz_mat3x4_t);
65/*! \endcond */
66
67//! Registers comprising XMTRX, in the FPU back-bank.
68typedef enum shz_xmtrx_reg {
69 SHZ_XMTRX_XF0, //!< FP register `xf0`.
70 SHZ_XMTRX_XF1, //!< FP register `xf1`.
71 SHZ_XMTRX_XF2, //!< FP register `xf2`.
72 SHZ_XMTRX_XF3, //!< FP register `xf3`.
73 SHZ_XMTRX_XF4, //!< FP register `xf4`.
74 SHZ_XMTRX_XF5, //!< FP register `xf5`.
75 SHZ_XMTRX_XF6, //!< FP register `xf6`.
76 SHZ_XMTRX_XF7, //!< FP register `xf7`.
77 SHZ_XMTRX_XF8, //!< FP register `xf8`.
78 SHZ_XMTRX_XF9, //!< FP register `xf9`.
79 SHZ_XMTRX_XF10, //!< FP register `xf10`.
80 SHZ_XMTRX_XF11, //!< FP register `xf11`.
81 SHZ_XMTRX_XF12, //!< FP register `xf12`.
82 SHZ_XMTRX_XF13, //!< FP register `xf13`.
83 SHZ_XMTRX_XF14, //!< FP register `xf14`.
84 SHZ_XMTRX_XF15 //!< FP register `xf15`.
85} shz_xmtrx_reg_t, shz_xmtrx_reg;
86
87/*! \name Accessors
88 \brief Setting and retrieving individual XMTRX register values.
89 @{
90*/
91
92//! Returns the floating-point value held within the given XMTRX register.
93SHZ_INLINE float shz_xmtrx_read(shz_xmtrx_reg_t xf) SHZ_NOEXCEPT;
94
95//! Sets the floating-point value held within the given XMTRX register to \p value.
96SHZ_INLINE void shz_xmtrx_write(shz_xmtrx_reg_t xf, float value) SHZ_NOEXCEPT;
97
98//! Returns the values at the the given row \p index, as a 4D vector.
99SHZ_INLINE shz_vec4_t shz_xmtrx_read_row(unsigned int index) SHZ_NOEXCEPT;
100
101//! Returns the values at the given column \p index, as a 4D vector.
102SHZ_INLINE shz_vec4_t shz_xmtrx_read_col(unsigned int index) SHZ_NOEXCEPT;
103
104//! Sets the values at the given row \p index to the given 4D vector.
105SHZ_INLINE void shz_xmtrx_write_row(unsigned int index, shz_vec4_t vector) SHZ_NOEXCEPT;
106
107//! Sets the values at the given column \p index to the given 4D vector.
108SHZ_INLINE void shz_xmtrx_write_col(unsigned int index, shz_vec4_t vector) SHZ_NOEXCEPT;
109
110//! Swaps the values of the rows with the given indices.
111SHZ_INLINE void shz_xmtrx_swap_rows(unsigned int index1, unsigned int index2) SHZ_NOEXCEPT;
112
113//! Swaps the values of the columns with the given indices.
114SHZ_INLINE void shz_xmtrx_swap_cols(unsigned int index1, unsigned int index2) SHZ_NOEXCEPT;
115
116//! @}
117
118/*! \name Loading
119 \brief Routines for loading XMTRX contents from memory.
120 @{
121*/
122
123//! Loads the given 4x4 matrix as XMTRX.
124SHZ_INLINE void shz_xmtrx_load_4x4(const shz_mat4x4_t* matrix) SHZ_NOEXCEPT;
125
126//! Loads the given 4x4 matrix as XMTRX, with the 4th column for translation being loaded as the first column.
127SHZ_INLINE void shz_xmtrx_load_wxyz_4x4(const shz_mat4x4_t* matrix) SHZ_NOEXCEPT;
128
129//! Loads the given array of unaligned 16 float values as the 4x4 XMTRX matrix.
130SHZ_INLINE void shz_xmtrx_load_unaligned_4x4(const float matrix[16]) SHZ_NOEXCEPT;
131
132//! Sets XMTRX equal to the 4x4 matrix created from the 4 given 4D column vectors.
133SHZ_INLINE void shz_xmtrx_load_cols_4x4(const shz_vec4_t* c1,
134 const shz_vec4_t* c2,
135 const shz_vec4_t* c3,
136 const shz_vec4_t* c4) SHZ_NOEXCEPT;
137
138//! Sets XMTRX equal to the 4x4 matrix created from the 4 given 4D row vectors.
139SHZ_INLINE void shz_xmtrx_load_rows_4x4(const shz_vec4_t* r1,
140 const shz_vec4_t* r2,
141 const shz_vec4_t* r3,
142 const shz_vec4_t* r4) SHZ_NOEXCEPT;
143
144//! Loads XMTRX with the transpose of the given 4x4 matrix.
145SHZ_INLINE void shz_xmtrx_load_transpose_4x4(const shz_mat4x4_t* matrix) SHZ_NOEXCEPT;
146
147//! Loads XMTRX with the transpose of the 4x4 matrix created from the given unaligned array of 16 floats.
148SHZ_INLINE void shz_xmtrx_load_transpose_unaligned_4x4(const float matrix[16]) SHZ_NOEXCEPT;
149
150//! Loads the given 3x4 matrix into XMTRX, initializing its remaining elements to identity.
151SHZ_INLINE void shz_xmtrx_load_3x4(const shz_mat3x4_t* matrix) SHZ_NOEXCEPT;
152
153//! Loads XMTRX with the transpose of the given 3x4 matrix, initializing the bottom row to identity.
154SHZ_INLINE void shz_xmtrx_load_transpose_3x4(const shz_mat3x4_t* matrix) SHZ_NOEXCEPT;
155
156/*! Loads the 3x4 matrix formed from the given 3 4D column vectors into XMTRX.
157
158 All remaining elements are initialized to identity matrix values.
159
160 \sa shz_xmtrx_load_rows_3x4()
161*/
162SHZ_INLINE void shz_xmtrx_load_cols_4x3(const shz_vec4_t* c1,
163 const shz_vec4_t* c2,
164 const shz_vec4_t* c3) SHZ_NOEXCEPT;
165
166/*! Loads the 3x4 matrix formed from the given 3 4D row vectors into XMTRX.
167
168 All remaining elements are initialized to identity matrix values.
169
170 \sa shz_xmtrx_load_cols_3x4()
171*/
172SHZ_INLINE void shz_xmtrx_load_rows_3x4(const shz_vec4_t* r1,
173 const shz_vec4_t* r2,
174 const shz_vec4_t* r3) SHZ_NOEXCEPT;
175
176/*! Loads the 3x4 matrix formed from the given 4 3D column vectors into XMTRX.
177
178 All remaining elements are initialized to identity matrix values.
179
180 \sa shz_xmtrx_load_rows_3x4()
181*/
182SHZ_INLINE void shz_xmtrx_load_cols_3x4(const shz_vec3_t* c1,
183 const shz_vec3_t* c2,
184 const shz_vec3_t* c3,
185 const shz_vec3_t* c4) SHZ_NOEXCEPT;
186
187//! Loads the given 3x3 matrix into XMTRX, initalizing its remaining elements to identity.
188SHZ_INLINE void shz_xmtrx_load_3x3(const shz_mat3x3_t* matrix) SHZ_NOEXCEPT;
189
190//! Loads the transpose of the given 3x3 matrix into XMTRX, initializing its remaining elements to identity.
191SHZ_INLINE void shz_xmtrx_load_transpose_3x3(const shz_mat3x3_t* matrix) SHZ_NOEXCEPT;
192
193//! Loads the given 2x2 matrix into XMTRX, initializing its remaining elements to identity.
194SHZ_INLINE void shz_xmtrx_load_2x2(const shz_mat2x2_t* matrix) SHZ_NOEXCEPT;
195
196//! @}
197
198/*! \name Storing
199 \brief Routines for saving XMTRX contents to memory.
200 @{
201*/
202
203//! Stores the current values held within XMTRX into the given 4x4 matrix.
204SHZ_INLINE void shz_xmtrx_store_4x4(shz_mat4x4_t* matrix) SHZ_NOEXCEPT;
205
206//! Stores the current values held within XMTRX into the given unaligned 16-float array.
207SHZ_INLINE void shz_xmtrx_store_unaligned_4x4(float matrix[16]) SHZ_NOEXCEPT;
208
209//! Stores the transpose of the current values held within XMTRX into the given 4x4 matrix.
210SHZ_INLINE void shz_xmtrx_store_transpose_4x4(shz_mat4x4_t* matrix) SHZ_NOEXCEPT;
211
212//! Stores the transpose of the the current values held within XMTRX into the given 16-element float array.
213SHZ_INLINE void shz_xmtrx_store_transpose_unaligned_4x4(float matrix[16]) SHZ_NOEXCEPT;
214
215//! Stores the top-left 3x4 values currently held within XMTRX into the given matrix.
216SHZ_INLINE void shz_xmtrx_store_3x4(shz_mat3x4_t* matrix) SHZ_NOEXCEPT;
217
218//! Stores the transpose of the top-left 3x4 values currently held within XMTRX into the given matrix.
219SHZ_INLINE void shz_xmtrx_store_transpose_3x4(shz_mat3x4_t* matrix) SHZ_NOEXCEPT;
220
221//! Stores the top-left 3x3 values currently held within XMTRX into the given matrix.
222SHZ_INLINE void shz_xmtrx_store_3x3(shz_mat3x3_t* matrix) SHZ_NOEXCEPT;
223
224//! Stores the transpose of the top-left 3x3 values currently held within XMTRX into the given matrix.
225SHZ_INLINE void shz_xmtrx_store_transpose_3x3(shz_mat3x3_t* matrix) SHZ_NOEXCEPT;
226
227//! Stores the top-left 2x2 values currently held within XMTRX into the given matrix.
228SHZ_INLINE void shz_xmtrx_store_2x2(shz_mat2x2_t* matrix) SHZ_NOEXCEPT;
229
230//! @}
231
232/*! \name Initialization
233 \brief Routines used to initialize the entirety of XMTRX.
234 @{
235*/
236
237//! Initializes XMTRX to the 4x4 identity matrix.
238SHZ_INLINE void shz_xmtrx_init_identity(void) SHZ_NOEXCEPT;
239
240/*! Safely initializes XMTRX to be a 4D identity matrix.
241
242 \deprecated
243 shz_xmtrx_init_identity() is already safe now by default. This routine
244 simply calls directly into it and should not be used.
245
246 \sa shz_xmtrx_init_identity()
247*/
248SHZ_DEPRECATED("Operation is always safe now. Use default version.")
249SHZ_INLINE void shz_xmtrx_init_identity_safe(void) SHZ_NOEXCEPT;
250
251//! Initializes XMTRX to contain the value of 0.0f for each element.
252SHZ_INLINE void shz_xmtrx_init_zero(void) SHZ_NOEXCEPT;
253
254//! Initializes XMTRX to contain the value of 1.0f for each element.
255SHZ_INLINE void shz_xmtrx_init_one(void) SHZ_NOEXCEPT;
256
257//! Initializes XMTRX to contain the given \p value for each element.
258SHZ_INLINE void shz_xmtrx_init_fill(float value) SHZ_NOEXCEPT;
259
260//! Initializes XMTRX to be a 3D translation matrix to the given coordinates.
261SHZ_INLINE void shz_xmtrx_init_translation(float x, float y, float z) SHZ_NOEXCEPT;
262
263//! Initializes XMTRX to be a 3D scale matrix with the given dimensions.
264SHZ_INLINE void shz_xmtrx_init_scale(float x, float y, float z) SHZ_NOEXCEPT;
265
266//! Initializes XMTRX to be a 3D rotation matrix by \p x radians about the X axis.
267SHZ_INLINE void shz_xmtrx_init_rotation_x(float x) SHZ_NOEXCEPT;
268
269//! Initializes XMTRX to be a 3D rotation matrix by \p y radians about the Y axis.
270SHZ_INLINE void shz_xmtrx_init_rotation_y(float y) SHZ_NOEXCEPT;
271
272//! Initializes XMTRX to be a 3D rotation matrix by \p z radians about the Z axis.
273SHZ_INLINE void shz_xmtrx_init_rotation_z(float z) SHZ_NOEXCEPT;
274
275/*! Initializes XMTRX to be a 3D X-Y-Z rotation matrix, with the corresponding angles given in radians.
276
277 \note
278 The given angles are represented as Tait-Bryan angles, representing an extrinsic rotation.
279
280 \sa shz_xmtrx_init_rotation_zyx(), shz_xmtrx_init_rotation_yxz()
281*/
282SHZ_INLINE void shz_xmtrx_init_rotation_xyz(float xAngle, float yAngle, float zAngle) SHZ_NOEXCEPT;
283
284/*! Initializes XMTRX to be a 3D Z-Y-X rotation matrix, with the corresponding angles given in radians.
285
286 \note
287 The given angles are represented as Tait-Bryan angles, representing an extrinsic rotation.
288
289 \sa shz_xmtrx_init_rotation_xyz(), shz_xmtrx_init_rotation_yxz()
290*/
291SHZ_INLINE void shz_xmtrx_init_rotation_zyx(float zAngle, float yAngle, float xAngle) SHZ_NOEXCEPT;
292
293/*! Initializes XMTRX to be a 3D Z-X-Y rotation matrix, with the corresponding angles given in radians.
294
295 \note
296 The given angles are represented as Tait-Bryan angles, representing an extrinsic rotation.
297
298 \sa shz_xmtrx_init_rotation_zyx(), shz_xmtrx_init_rotation_yxz()
299*/
300SHZ_INLINE void shz_xmtrx_init_rotation_zxy(float zAngle, float xAngle, float yAngle) SHZ_NOEXCEPT;
301
302/*! Initializes XMTRX to be a 3D Y-X-Z rotation matrix, with the corresponding angles given in radians.
303
304 \note
305 The given angles are represented as Tait-Bryan angles, representing an extrinsic rotation.
306
307 \sa shz_xmtrx_init_rotation_yxz(), shz_xmtrx_init_rotation_xyz()
308*/
309SHZ_INLINE void shz_xmtrx_init_rotation_yxz(float yAngle, float xAngle, float zAngle) SHZ_NOEXCEPT;
310
311/*! Initializes XMTRX to a 3D rotation matrix of \p angle radians about the vector with the given components.
312
313 \note This routine works similarly to glRotatef() applied to an identitiy matrix. The given
314 axis will automatically be normalized internally.
315
316 \sa shz_xmtrx_init_rotation_dir()
317*/
318SHZ_INLINE void shz_xmtrx_init_rotation(float angle, float xAxis, float yAxis, float zAxis) SHZ_NOEXCEPT;
319
320/*! Initializes XMTRX to contain a 3D rotation matrix of \p angle radians about the given \p axis.
321
322 This is a faster version of shz_xmtrx_init_rotation() or glRotatef() which requires being passed a unit
323 vector for the rotation axis.
324
325 \warning The vector components representing the axis of rotation must be prenormalized!
326
327 \sa shz_xmtrx_init_rotation()
328*/
329SHZ_INLINE void shz_xmtrx_init_rotation_dir(float angle, float x, float y, float z) SHZ_NOEXCEPT;
330
331//! Initializes XMTRX to be a diagonal matrix with the given diagonal values.
332SHZ_INLINE void shz_xmtrx_init_diagonal(float x, float y, float z, float w) SHZ_NOEXCEPT;
333
334//! Initializes XMTRX to be an upper triangular matrix with the given column values.
335SHZ_INLINE void shz_xmtrx_init_upper_triangular(float col1, shz_vec2_t col2, shz_vec3_t col3, shz_vec4_t col4) SHZ_NOEXCEPT;
336
337//! Initializes XMTRX to be a lower triangular matrix with the given column values.
338SHZ_INLINE void shz_xmtrx_init_lower_triangular(shz_vec4_t col1, shz_vec3_t col2, shz_vec2_t col3, float col4) SHZ_NOEXCEPT;
339
340//! Initializes XMTRX to be the 3D symmetric skew matrix formed from the given vector components.
341SHZ_INLINE void shz_xmtrx_init_symmetric_skew(float x, float y, float z) SHZ_NOEXCEPT;
342
343//! Initializes XMTRX to the 4D matrix resulting from taking the outer product of the two 4D vectors.
344SHZ_INLINE void shz_xmtrx_init_outer_product(shz_vec4_t x, shz_vec4_t y) SHZ_NOEXCEPT;
345
346//! Initializes XMTRX to a permutation matrix, which reorders the components of transformed vectors to be in WXYZ order.
347SHZ_INLINE void shz_xmtrx_init_permutation_wxyz(void) SHZ_NOEXCEPT;
348
349//! Initializes XMTRX to a permutation matrix, which reorders the components of transformed vectors to be in YZWX order.
350SHZ_INLINE void shz_xmtrx_init_permutation_yzwx(void) SHZ_NOEXCEPT;
351
352//! Initializes XMTRX to a permutation matrix, which reorders the components of transformed vectors to be in WZYX order.
353SHZ_INLINE void shz_xmtrx_init_permutation_wzyx(void) SHZ_NOEXCEPT;
354
355/*! Initializes XMTRX to the viewport matrix with the given dimensions.
356
357 fr[n + 0] | fr[n + 4] | fr[n + 8] | fr[n + 12]
358 -----------|-----------|-----------|-----------
359 w*0.5f | 0.0f | 0.0f | w*0.5f
360 0.0f | -h*0.5f | 0.0f | h*0.5f
361 0.0f | 0.0f | 1.0f | 0.0f
362 0.0f | 0.0f | 0.0f | 1.0f
363*/
364SHZ_INLINE void shz_xmtrx_init_screen(float width, float height) SHZ_NOEXCEPT;
365
366/*! Initializes XMTRX to a "lookAt" view matrix, equivalent to gluLookAt().
367
368 \warning This routine clobbers any previous XMTRX contents.
369*/
370SHZ_INLINE void shz_xmtrx_init_lookat(shz_vec3_t eye, shz_vec3_t center, shz_vec3_t up) SHZ_NOEXCEPT;
371
372/*! Initializes XMTRX to an orthographic projection matrix, equivalent to glOrtho().
373
374 \warning This routine clobbers any previous XMTRX contents.
375*/
376SHZ_INLINE void shz_xmtrx_init_ortho(float left, float right, float bottom, float top, float znear, float zfar) SHZ_NOEXCEPT;
377
378/*! Initializes XMTRX to a frustum projection matrix, equivalent to glFrustum().
379
380 \warning This routine clobbers any previous XMTRX contents.
381*/
382SHZ_INLINE void shz_xmtrx_init_frustum(float left, float right, float bottom, float top, float znear, float zfar) SHZ_NOEXCEPT;
383
384/*! Initializes XMTRX to a perspective projection matrix.
385
386 \warning This routine clobbers any previous XMTRX contents.
387*/
388SHZ_INLINE void shz_xmtrx_init_perspective(float fov, float aspect, float znear) SHZ_NOEXCEPT;
389
390/*! Initializes XMTRX to a 3D rotation matrix with its orientation given by a quaternion.
391
392 \warning This routine clobbers any previous XMTRX contents.
393 \warning This routine is out-of-line.
394*/
395void shz_xmtrx_init_rotation_quat(shz_quat_t q) SHZ_NOEXCEPT;
396
397//! @}
398
399/*! \name Apply Operation
400 \brief Updates only relevant values of XMTRX based on the given transform.
401 @{
402*/
403
404//! Multiplies and accumulates the given 4x4 matrix onto XMTRX.
405SHZ_INLINE void shz_xmtrx_apply_4x4(const shz_mat4x4_t* matrix) SHZ_NOEXCEPT;
406
407//! Multiplies and accumulates the given 16-entry float array as a 4x4 matrix onto XMTRX.
408SHZ_INLINE void shz_xmtrx_apply_unaligned_4x4(const float matrix[16]) SHZ_NOEXCEPT;
409
410//! Multiplies and accumulates the transpose of the given 4x4 matrix onto XMTRX.
411SHZ_INLINE void shz_xmtrx_apply_transpose_4x4(const shz_mat4x4_t* matrix) SHZ_NOEXCEPT;
412
413//! Multiplies and accumulates the transpose of the given 16-entry float array as a 4x4 matrix onto XMTRX.
414SHZ_INLINE void shz_xmtrx_apply_transpose_unaligned_4x4(const float matrix[16]) SHZ_NOEXCEPT;
415
416//! Multiplies and accumulates XMTRX onto \p matrix, storing the result as XMTRX.
417SHZ_INLINE void shz_xmtrx_apply_reverse_4x4(const shz_mat4x4_t* matrix) SHZ_NOEXCEPT;
418
419//! Multiplies and accumulates XMTRX onto the given float array as a 4x4 matrix, storing the result as XMTRX.
420SHZ_INLINE void shz_xmtrx_apply_reverse_unaligned_4x4(const float matrix[16]) SHZ_NOEXCEPT;
421
422//! Multiplies and accumulates XMTRX onto the transpose of \p matrix, storing the result as XMTRX.
423SHZ_INLINE void shz_xmtrx_apply_reverse_transpose_4x4(const shz_mat4x4_t* matrix) SHZ_NOEXCEPT;
424
425//! Multiplies and accumulates XMTRX onto the transpose of the given float array as a 4x4 matrix, storing the result as XMTRX.
426SHZ_INLINE void shz_xmtrx_apply_reverse_transpose_unaligned_4x4(const float matrix[16]) SHZ_NOEXCEPT;
427
428//! Multiplies and accumulates the given 3x4 matrix onto XMTRX, not modifying other elements.
429SHZ_INLINE void shz_xmtrx_apply_3x4(const shz_mat3x4_t* matrix) SHZ_NOEXCEPT;
430
431//! Multiplies and accumulates the transpose of the given 3x4 matrix onto XMTRX, not modifying other elements.
432SHZ_INLINE void shz_xmtrx_apply_transpose_3x4(const shz_mat3x4_t* matrix) SHZ_NOEXCEPT;
433
434//! Multiplies and accumulates XMTRX onto \p matrix, storing the result as XMTRX.
435SHZ_INLINE void shz_xmtrx_apply_reverse_3x4(const shz_mat3x4_t* mat) SHZ_NOEXCEPT;
436
437//! Multiplies and accumulates XMTRX onto the transpose of \p matrix, storing the result as XMTRX.
438SHZ_INLINE void shz_xmtrx_apply_reverse_transpose_3x4(const shz_mat3x4_t* mat) SHZ_NOEXCEPT;
439
440//! Multiplies and accumulates the given 3x3 matrix onto XMTRX, not modifying other elements.
441SHZ_INLINE void shz_xmtrx_apply_3x3(const shz_mat3x3_t* matrix) SHZ_NOEXCEPT;
442
443//! Multiplies and accumulates the transpose of the given 3x3 matrix onto XMTRX, not modifying other elements.
444SHZ_INLINE void shz_xmtrx_apply_transpose_3x3(const shz_mat3x3_t* matrix) SHZ_NOEXCEPT;
445
446//! Multiplies and accumulates the given 2x2 matrix onto XMTRX, not modifying other elements.
447SHZ_INLINE void shz_xmtrx_apply_2x2(const shz_mat2x2_t* matrix) SHZ_NOEXCEPT;
448
449//! Adds the values of the given 3 components to the 3D translation components of XMTRX.
450SHZ_INLINE void shz_xmtrx_apply_translation(float x, float y, float z) SHZ_NOEXCEPT;
451
452//! Multiplies the values of the inner 3x3 matrix by the given 3D scaling terms.
453SHZ_INLINE void shz_xmtrx_apply_scale(float x, float y, float z) SHZ_NOEXCEPT;
454
455//! Transforms the values of the inner 3x3 matrix by a rotation matrix of \p x radians about the X axis.
456SHZ_INLINE void shz_xmtrx_apply_rotation_x(float x) SHZ_NOEXCEPT;
457
458//! Transforms the values of the inner 3x3 matrix by a rotation matrix of \p y radians about the Y axis.
459SHZ_INLINE void shz_xmtrx_apply_rotation_y(float y) SHZ_NOEXCEPT;
460
461//! Transforms the values of the inner 3x3 matrix by a rotation matrix of \p z radians about the Z axis.
462SHZ_INLINE void shz_xmtrx_apply_rotation_z(float z) SHZ_NOEXCEPT;
463
464/*! Multiplies and accumulates XMTRX by a 3D X-Y-Z rotation matrix, with the corresponding angles given in radians.
465
466 The transform is applied to the inner 3x3 values within XMTRX, preserving the translational components.
467
468 \note
469 The given angles are represented as Tait-Bryan angles, representing an extrinsic rotation.
470
471 \sa shz_xmtrx_apply_rotation_zyx(), shz_xmtrx_apply_rotation_yxz()
472*/
473SHZ_INLINE void shz_xmtrx_apply_rotation_xyz(float xAngle, float yAngle, float zAngle) SHZ_NOEXCEPT;
474
475/*! Multiplies and accumulates XMTRX by a 3D Z-Y-X rotation matrix, with the corresponding angles given in radians.
476
477 The transform is applied to the inner 3x3 values within XMTRX, preserving the translational components.
478
479 \note
480 The given angles are represented as Tait-Bryan angles, representing an extrinsic rotation.
481
482 \sa shz_xmtrx_apply_rotation_xyz(), shz_xmtrx_apply_rotation_yxz()
483*/
484SHZ_INLINE void shz_xmtrx_apply_rotation_zyx(float zAngle, float yAngle, float xAngle) SHZ_NOEXCEPT;
485
486/*! Multiplies and accumulates XMTRX by a 3D Z-X-Y rotation matrix, with the corresponding angles given in radians.
487
488 The transform is applied to the inner 3x3 values within XMTRX, preserving the translational components.
489
490 \note
491 The given angles are represented as Tait-Bryan angles, representing an extrinsic rotation.
492
493 \sa shz_xmtrx_apply_rotation_zyx(), shz_xmtrx_apply_rotation_yxz()
494*/
495SHZ_INLINE void shz_xmtrx_apply_rotation_zxy(float zAngle, float xAngle, float yAngle) SHZ_NOEXCEPT;
496
497/*! Multiplies and accumulates XMTRX by a 3D Y-X-Z rotation matrix, with the corresponding angles given in radians.
498
499 The transform is applied to the inner 3x3 values within XMTRX, preserving the translational components.
500
501 \note
502 The given angles are represented as Tait-Bryan angles, representing an extrinsic rotation.
503
504 \sa shz_xmtrx_apply_rotation_xyz(), shz_xmtrx_apply_rotation_zyx()
505*/
506SHZ_INLINE void shz_xmtrx_apply_rotation_yxz(float yAngle, float xAngle, float zAngle) SHZ_NOEXCEPT;
507
508//! Transforms the values of the inner 3x3 matrix by a rotation matrix of \p angle radians about the axis with the given components.
509SHZ_INLINE void shz_xmtrx_apply_rotation(float angle, float x, float y, float z) SHZ_NOEXCEPT;
510
511//! Transforms the values of the inner 3x3 matrix by the rotation matrix represented by the given quaternion.
512SHZ_INLINE void shz_xmtrx_apply_rotation_quat(shz_quat_t quat) SHZ_NOEXCEPT;
513
514//! Applies the 3D "lookAt" matrix constructed with the given vector components onto XMTRX. Equivalent to gluLookAt().
515SHZ_INLINE void shz_xmtrx_apply_lookat(shz_vec3_t eye, shz_vec3_t center, shz_vec3_t up) SHZ_NOEXCEPT;
516
517//! Applies a 2D orthographic projection matrix onto XMTRX, equivalent to glOrtho().
518SHZ_INLINE void shz_xmtrx_apply_ortho(float left, float right, float bottom, float top, float znear, float zfar) SHZ_NOEXCEPT;
519
520//! Applies a frustum projection matrix onto XMTRX, equivalent to glFrustum().
521SHZ_INLINE void shz_xmtrx_apply_frustum(float left, float right, float bottom, float top, float znear, float zfar) SHZ_NOEXCEPT;
522
523/*! Multiplies and accumulates the perspective matrix constructed from the given values onto XMTRX.
524
525 fr[n + 0] | fr[n + 4] | fr[n + 8] | fr[n + 12]
526 -----------|-----------|-----------|-----------
527 cot(f)/a | 0.0f | 0.0f | 0.0f
528 0.0f | cot(f) | 0.0f | 0.0f
529 0.0f | 0.0f | 0.0f | nz
530 0.0f | 0.0f | -1.0f | 0.0f
531*/
532SHZ_INLINE void shz_xmtrx_apply_perspective(float fov, float aspect, float znear) SHZ_NOEXCEPT;
533
534/*! Multiplies and accumulates the viewport matrix created with the given components.
535
536 fr[n + 0] | fr[n + 4] | fr[n + 8] | fr[n + 12]
537 -----------|-----------|-----------|-----------
538 w*0.5f | 0.0f | 0.0f | w*0.5f
539 0.0f | -h*0.5f | 0.0f | h*0.5f
540 0.0f | 0.0f | 1.0f | 0.0f
541 0.0f | 0.0f | 0.0f | 1.0f
542*/
543SHZ_INLINE void shz_xmtrx_apply_screen(float width, float height) SHZ_NOEXCEPT;
544
545//! Multiplies and accumulates the 3D symmetric skew matrix with the given components onto XMTRX.
546SHZ_INLINE void shz_xmtrx_apply_symmetric_skew(float x, float y, float z) SHZ_NOEXCEPT;
547
548//! Multiplies and accumulates a permutation matrix, which reorders the components of transformed vectors to be in WXYZ order.
549SHZ_INLINE void shz_xmtrx_apply_permutation_wxyz(void) SHZ_NOEXCEPT;
550
551//! Multiplies and accumulates a permutation matrix, which reorders the components of transformed vectors to be in YZWX order.
552SHZ_INLINE void shz_xmtrx_apply_permutation_yzwx(void) SHZ_NOEXCEPT;
553
554//! Multiplies and accumulates a permutation matrix, which reorders the components of transformed vectors to be in WZYX order.
555SHZ_INLINE void shz_xmtrx_apply_permutation_wzyx(void) SHZ_NOEXCEPT;
556
557//! Multiplies and accumulatse the XMTRX matrix by itself, squaring it.
558SHZ_INLINE void shz_xmtrx_apply_self(void) SHZ_NOEXCEPT;
559
560//! @}
561
562/*! \name GL Transformations
563 \brief OpenGL-style 4x4 matrix transforms.
564 @{
565*/
566
567//! Multiplies and accumulates XMTRX by a 3D translation matrix with the given components (glTranslatef() equivalent).
568SHZ_INLINE void shz_xmtrx_translate(float x, float y, float z) SHZ_NOEXCEPT;
569
570//! Multiplies and accumulates XMTRX by a 3D scaling matrix with the given components (glScalef() equivalent).
571SHZ_INLINE void shz_xmtrx_scale(float x, float y, float z) SHZ_NOEXCEPT;
572
573//! Multiplies and accumulates XMTRX by a 3D rotation matrix about the X axis.
574SHZ_INLINE void shz_xmtrx_rotate_x(float radians) SHZ_NOEXCEPT;
575
576//! Multiplies and accumulates XMTRX by a 3D rotation matrix about the Y axis.
577SHZ_INLINE void shz_xmtrx_rotate_y(float radians) SHZ_NOEXCEPT;
578
579//! Multiplies and accumulates XMTRX by a 3D rotation matrix about the Z axis.
580SHZ_INLINE void shz_xmtrx_rotate_z(float radians) SHZ_NOEXCEPT;
581
582//! Multiplies and accumulates XMTRX by 3D rotation matrices about the X then Y then Z axes.
583SHZ_INLINE void shz_xmtrx_rotate_xyz(float xRadians, float yRadians, float zRadians) SHZ_NOEXCEPT;
584
585//! Multiplies and accumulates XMTRX by 3D rotation matrices about the Z then Y then X axes.
586SHZ_INLINE void shz_xmtrx_rotate_zyx(float zRadians, float yRadians, float xRadians) SHZ_NOEXCEPT;
587
588//! Multiplies and accumulates XMTRX by 3D rotation matrices about the Z then X then Y axes.
589SHZ_INLINE void shz_xmtrx_rotate_zxy(float zRadians, float xRadians, float yRadians) SHZ_NOEXCEPT;
590
591//! Multiplies and accumulates XMTRX by 3D rotation matrices about the Y then X then Z axes.
592SHZ_INLINE void shz_xmtrx_rotate_yxz(float yRadians, float xRadians, float zRadians) SHZ_NOEXCEPT;
593
594//! Multiplies and accumulates XMTRX by the 3D rotation matrix formed by the given axis and angle (glRotatef equivalent).
595SHZ_INLINE void shz_xmtrx_rotate(float radians, float xAxis, float yAxis, float zAxis) SHZ_NOEXCEPT;
596
597//!@}
598
599/*! \name Reverse GL Transformations
600 \brief Pre-multiplication variants of OpenGL-style 4x4 matrix transforms.
601 @{
602*/
603
604//! Pre-multiplies and accumulates XMTRX onto the 3D translation matrix with the given components.
605SHZ_INLINE void shz_xmtrx_translate_reverse(float x, float y, float z) SHZ_NOEXCEPT;
606
607//! Pre-multiplies and accumulates XMTRX onto the 3D scaling matrix with the given components.
608SHZ_INLINE void shz_xmtrx_scale_reverse(float x, float y, float z) SHZ_NOEXCEPT;
609
610//!@}
611
612/*! \name Compound Operations
613 \brief Multiple operations combined into one pipelined transaction.
614 @{
615*/
616
617/*! Loads XMTRX with the result of applying \p matrix2 onto \p matrix1.
618
619 This operation is equivalent to:
620 shz_xmtrx_load_4x4(matrix1);
621 shz_xmtrx_apply_4x4(matrix2);
622
623 However, it has been optimized and pipelined for performing the load
624 and multiply in parallel.
625
626 \sa shz_xmtrx_load_4x4(), shz_xmtrx_apply_4x4(), shz_xmtrx_load_apply_store_4x4()
627*/
628SHZ_INLINE void shz_xmtrx_load_apply_4x4(const shz_mat4x4_t* matrix1,
629 const shz_mat4x4_t* matrix2) SHZ_NOEXCEPT;
630
631/*! Loads XMTRX with the result of applying unaligned \p matrix2 onto \p matrix1.
632
633 This routine is equivalent to shz_xmtrx_load_apply_4x4(), except that the two
634 operand matrices do not require 8-byte alignment and can simply be 16-element
635 single-precision float arrays.
636
637 \sa shz_xmtrx_load_apply_4x4()
638*/
639SHZ_INLINE void shz_xmtrx_load_apply_unaligned_4x4(const float matrix1[16],
640 const float matrix2[16]) SHZ_NOEXCEPT;
641
642/*! Multiplies XMTRX by the matrix, \p in, storing the result within the matrix, \p out.
643
644 This routine is roughly equivalent to:
645 shz_xmtrx_apply_4x4(in);
646 shz_xmtrx_store_4x4(out);
647
648 However, it has been optimized and pipelined for performing the multiply and store in parallel.
649
650 \note
651 This is useful for when you want to multiply a batch of matrices by the same matrix, held within XMTRX.
652
653 \warning
654 The result of the multiplication is not stored within XMTRX, despite it getting clobbered.
655
656 \sa shz_xmtrx_apply_4x4(), shz_xmtrx_store_4x4(), shz_xmtrx_apply_store_unaligned_4x4()
657*/
658 SHZ_INLINE void shz_xmtrx_apply_store_4x4(shz_mat4x4_t* out,
659 const shz_mat4x4_t* in) SHZ_NOEXCEPT;
660
661/*! Multiplies XMTRX by the unaligned matrix, \p in, storing the result within the unaligned matrix, \p out.
662
663 This routine is roughly equivalent to:
664 shz_xmtrx_apply_unaligned_4x4(in);
665 shz_xmtrx_store_unaligned_4x4(out);
666
667 However, it has been optimized and pipelined for performing the multiply and store in parallel.
668
669 \note
670 This is useful for when you want to multiply a batch of matrices by the same matrix, held within XMTRX.
671
672 \warning
673 The result of the multiplication is not stored within XMTRX, despite it getting clobbered.
674
675 \sa shz_xmtrx_apply_unaligned_4x4(), shz_xmtrx_store_unaligned_4x4(), shz_xmtrx_apply_store_4x4()
676*/
677 SHZ_INLINE void shz_xmtrx_apply_store_unaligned_4x4(float out[16],
678 const float in[16]) SHZ_NOEXCEPT;
679
680/*! Loads XMTRX with the 4x4 result of applying \p matrix2 onto \p matrix1, storing the result.
681
682 This operation is equivalent to:
683 shz_xmtrx_load_4x4(matrix1);
684 shz_xmtrx_apply_4x4(matrix2);
685 shz_xmtrx_store_4x4(out);
686
687 However, it has been optimized and pipelined for performing the loads, multiplies, and
688 stores in parallel.
689
690 \sa shz_xmtrx_load_apply(), shz_xmtrx_load_apply_store_unaligned_4x4()
691*/
692SHZ_INLINE void shz_xmtrx_load_apply_store_4x4(shz_mat4x4_t* out,
693 const shz_mat4x4_t* matrix1,
694 const shz_mat4x4_t* matrix2) SHZ_NOEXCEPT;
695
696/*! Loads XMTRX with the result of applying unaligned \p matrix2 onto unaligned \p matrix1, storing the result.
697
698 This routine is equivalent to shz_xmtrx_load_apply_store_4x4(), except that the three
699 operand matrices do not require 8-byte alignment and can simply be 16-element
700 single-precision float arrays.
701
702 \sa shz_xmtrx_load_apply_store_4x4()
703*/
704SHZ_INLINE void shz_xmtrx_load_apply_store_unaligned_4x4(float out[16],
705 const float matrix1[16],
706 const float matrix2[16]) SHZ_NOEXCEPT;
707
708/*! Loads XMTRX with the result of applying \p matrix2 onto \p matrix1.
709
710 This operation is equivalent to:
711 shz_xmtrx_load_3x4(matrix1);
712 shz_xmtrx_apply_3x4(matrix2);
713
714 However, it has been optimized and pipelined for performing the load
715 and multiply in parallel.
716
717 \sa shz_xmtrx_load_3x4(), shz_xmtrx_apply_3x4(), shz_xmtrx_load_apply_store_3x4()
718*/
719SHZ_INLINE void shz_xmtrx_load_apply_3x4(const shz_mat3x4_t* matrix1,
720 const shz_mat3x4_t* matrix2) SHZ_NOEXCEPT;
721
722/*! Loads XMTRX with the 3x4 result of applying \p matrix2 onto \p matrix1, storing the result.
723
724 This operation is equivalent to:
725 shz_xmtrx_load_3x4(matrix1);
726 shz_xmtrx_apply_3x4(matrix2);
727 shz_xmtrx_store_3x4(out);
728
729 However, it has been optimized and pipelined for performing the loads, multiplies,
730 and stores in parallel.
731
732 \note
733 The resulting matrix does not get stored within XMTRX, despite it getting clobbered.
734
735 \sa shz_xmtrx_load_3x4(), shz_xmtrx_apply_3x4(), shz_xmtrx_store_3x4()
736*/
737SHZ_INLINE void shz_xmtrx_load_apply_store_3x4(shz_mat3x4_t* out,
738 const shz_mat3x4_t* matrix1,
739 const shz_mat3x4_t* matrix2) SHZ_NOEXCEPT;
740
741/*! Loads XMTRX with the 3x3 result of applying \p matrix2 onto \p matrix1, storing the result.
742
743 This operation is equivalent to:
744 shz_xmtrx_load_3x3(matrix1);
745 shz_xmtrx_apply_3x3(matrix2);
746 shz_xmtrx_store_3x3(out);
747
748 However, it has been optimized and pipelined for performing the loads, multiplies,
749 and stores in parallel.
750
751 \note
752 The resulting matrix does not get stored within XMTRX, despite it getting clobbered.
753
754 \sa shz_xmtrx_load_3x3(), shz_xmtrx_apply_3x3(), shz_xmtrx_store_3x3()
755*/
756SHZ_INLINE void shz_xmtrx_load_apply_store_3x3(shz_mat3x3_t* out,
757 const shz_mat3x3_t* matrix1,
758 const shz_mat3x3_t* matrix2) SHZ_NOEXCEPT;
759
760//! @}
761
762/*! \name Transformations
763 \brief Transforming vectors and points against XMTRX.
764 @{
765*/
766
767//! Returns the 4D vector that is the result of transforming \p vec by XMTRX.
768SHZ_INLINE shz_vec4_t shz_xmtrx_transform_vec4(shz_vec4_t vec) SHZ_NOEXCEPT;
769
770//! Returns the 3D vector that is the result of transforming \p vec by XMTRX.
771SHZ_INLINE shz_vec3_t shz_xmtrx_transform_vec3(shz_vec3_t vec) SHZ_NOEXCEPT;
772
773//! Returns the 2D vector that is the result of transforming \p vec by XMTRX.
774SHZ_INLINE shz_vec2_t shz_xmtrx_transform_vec2(shz_vec2_t vec) SHZ_NOEXCEPT;
775
776//! Returns the 2D point that is the result of transforming \p pt by XMTRX.
777SHZ_INLINE shz_vec2_t shz_xmtrx_transform_point2(shz_vec2_t pt) SHZ_NOEXCEPT;
778
779//! Returns the 3D point that is the result of transforming \p pt by XMTRX.
780SHZ_INLINE shz_vec3_t shz_xmtrx_transform_point3(shz_vec3_t pt) SHZ_NOEXCEPT;
781
782//! @}
783
784/*! \name Setters
785 \brief Sets the values of related XMTRX components.
786 @{
787*/
788
789//! Sets only the translational components of XMTRX to the given values.
790SHZ_INLINE void shz_xmtrx_set_translation(float x, float y, float z) SHZ_NOEXCEPT;
791
792//! Sets only the inner 3x3 submatrix of XMTRX to be a scaling matrix.
793SHZ_INLINE void shz_xmtrx_set_scale(float x, float y, float z) SHZ_NOEXCEPT;
794
795//! @}
796
797/*! \name Getters
798 \brief Gets the values of related XMTRX components.
799 @{
800*/
801
802//! Returns the translational components from the last column of XMTRX, as a 3D vector.
803SHZ_INLINE shz_vec3_t shz_xmtrx_get_translation(void) SHZ_NOEXCEPT;
804
805/*! Returns the scaling components from the inner 3x3 matrix of XMTRX, as a 3D vector.
806
807 \warning This routine assumes XMTRX is a standard TRS-style transform matrix,
808 without shearing or reflection.
809*/
810SHZ_INLINE shz_vec3_t shz_xmtrx_get_scale(void) SHZ_NOEXCEPT;
811
812//! @}
813
814/*! \name Component-Wise Matrix Operations
815 \brief Operations applying each component of a matrix onto XMTRX.
816 @{
817*/
818
819//! Adds each element within \p mat to each element within XMTRX, storing the result in XMTRX.
820SHZ_INLINE void shz_xmtrx_add_4x4(const shz_mat4x4_t* mat) SHZ_NOEXCEPT;
821
822//! Subtracts each element within \p mat from each element within XMTRX, storing the result in XMTRX.
823SHZ_INLINE void shz_xmtrx_sub_4x4(const shz_mat4x4_t* mat) SHZ_NOEXCEPT;
824
825//! @}
826
827/*! \name Miscellaneous
828 \brief Random operations and conversions on XMTRX.
829 @{
830*/
831
832//! Transposes the elements within XMTRX, in-place.
833SHZ_INLINE void shz_xmtrx_transpose(void) SHZ_NOEXCEPT;
834
835//! Negates each element held within XMTRX.
836SHZ_INLINE void shz_xmtrx_negate(void) SHZ_NOEXCEPT;
837
838//! Takes the absolute value of each element held within XMTRX.
839SHZ_INLINE void shz_xmtrx_abs(void) SHZ_NOEXCEPT;
840
841//! Constructs a quaternion from the 3D rotation matrix within XMTRX.
842shz_quat_t shz_xmtrx_to_quat(void) SHZ_NOEXCEPT;
843
844//! Returns the determinant of XMTRX.
845float shz_xmtrx_determinant(void) SHZ_NOEXCEPT;
846
847/*! Inverts XMTRX in-place.
848
849 Stores XMTRX to memory, computes the inverse via shz_mat4x4_inverse(),
850 and reloads the result.
851
852 \warning This routine is out-of-line.
853*/
854void shz_xmtrx_invert(void) SHZ_NOEXCEPT;
855
856/*! Adds and accumulates a scaled 4x4 matrix onto XMTRX.
857
858 Each component of \p joint_matrix will be multiplied by \p weight, with the result
859 being added to the existing value of that component of XMTRX.
860
861 This is useful for accumulating weighted joint matrices onto an initially
862 zeroed-out XMTRX. This allows for in-place construction of a skin matrix, which can
863 then be directly used to transform the vertices of a mesh against for animation.
864
865 \sa shz_xmtrx_init_zero()
866*/
867SHZ_INLINE void shz_xmtrx_blend(const shz_mat4x4_t* joint_matrix, float weight) SHZ_NOEXCEPT;
868
869//! @}
870
871#include "inline/shz_xmtrx.inl.h"
872
873SHZ_DECLS_END
874
875#endif // SHZ_XMTRX_H
#define SHZ_DECLARE_STRUCT(n, t)
Macro which forward declares a struct and its typedef.
Definition shz_cdefs.h:130
#define SHZ_DECLARE_STRUCT_ALIGNED(n, t, a)
Macro which forward declares a manually aligned struct and its typedef.
Definition shz_cdefs.h:132
void shz_xmtrx_init_diagonal(float x, float y, float z, float w) noexcept
Initializes XMTRX to be a diagonal matrix with the given diagonal values.
void shz_xmtrx_apply_rotation_z(float z) noexcept
Transforms the values of the inner 3x3 matrix by a rotation matrix of z radians about the Z axis.
void shz_xmtrx_apply_transpose_3x3(const shz_mat3x3_t *matrix) noexcept
Multiplies and accumulates the transpose of the given 3x3 matrix onto XMTRX, not modifying other elem...
void shz_xmtrx_load_transpose_3x3(const shz_mat3x3_t *matrix) noexcept
Loads the transpose of the given 3x3 matrix into XMTRX, initializing its remaining elements to identi...
void shz_xmtrx_apply_reverse_3x4(const shz_mat3x4_t *mat) noexcept
Multiplies and accumulates XMTRX onto matrix, storing the result as XMTRX.
void shz_xmtrx_init_upper_triangular(float col1, shz_vec2_t col2, shz_vec3_t col3, shz_vec4_t col4) noexcept
Initializes XMTRX to be an upper triangular matrix with the given column values.
shz_vec4_t shz_xmtrx_read_col(unsigned int index) noexcept
Returns the values at the given column index, as a 4D vector.
shz_quat_t shz_xmtrx_to_quat(void) noexcept
Constructs a quaternion from the 3D rotation matrix within XMTRX.
void shz_xmtrx_load_apply_store_unaligned_4x4(float out[16], const float matrix1[16], const float matrix2[16]) noexcept
Loads XMTRX with the result of applying unaligned matrix2 onto unaligned matrix1, storing the result.
void shz_xmtrx_invert(void) noexcept
Inverts XMTRX in-place.
void shz_xmtrx_init_rotation_zyx(float zAngle, float yAngle, float xAngle) noexcept
Initializes XMTRX to be a 3D Z-Y-X rotation matrix, with the corresponding angles given in radians.
void shz_xmtrx_store_3x4(shz_mat3x4_t *matrix) noexcept
Stores the top-left 3x4 values currently held within XMTRX into the given matrix.
void shz_xmtrx_store_unaligned_4x4(float matrix[16]) noexcept
Stores the current values held within XMTRX into the given unaligned 16-float array.
void shz_xmtrx_init_identity(void) noexcept
Initializes XMTRX to the 4x4 identity matrix.
void shz_xmtrx_load_apply_store_3x3(shz_mat3x3_t *out, const shz_mat3x3_t *matrix1, const shz_mat3x3_t *matrix2) noexcept
Loads XMTRX with the 3x3 result of applying matrix2 onto matrix1, storing the result.
void shz_xmtrx_apply_rotation_quat(shz_quat_t quat) noexcept
Transforms the values of the inner 3x3 matrix by the rotation matrix represented by the given quatern...
void shz_xmtrx_blend(const shz_mat4x4_t *joint_matrix, float weight) noexcept
Adds and accumulates a scaled 4x4 matrix onto XMTRX.
void shz_xmtrx_load_transpose_3x4(const shz_mat3x4_t *matrix) noexcept
Loads XMTRX with the transpose of the given 3x4 matrix, initializing the bottom row to identity.
void shz_xmtrx_load_unaligned_4x4(const float matrix[16]) noexcept
Loads the given array of unaligned 16 float values as the 4x4 XMTRX matrix.
void shz_xmtrx_set_scale(float x, float y, float z) noexcept
Sets only the inner 3x3 submatrix of XMTRX to be a scaling matrix.
void shz_xmtrx_rotate_x(float radians) noexcept
Multiplies and accumulates XMTRX by a 3D rotation matrix about the X axis.
void shz_xmtrx_load_cols_3x4(const shz_vec3_t *c1, const shz_vec3_t *c2, const shz_vec3_t *c3, const shz_vec3_t *c4) noexcept
Loads the 3x4 matrix formed from the given 4 3D column vectors into XMTRX.
void shz_xmtrx_set_translation(float x, float y, float z) noexcept
Sets only the translational components of XMTRX to the given values.
void shz_xmtrx_scale_reverse(float x, float y, float z) noexcept
Pre-multiplies and accumulates XMTRX onto the 3D scaling matrix with the given components.
void shz_xmtrx_store_transpose_3x3(shz_mat3x3_t *matrix) noexcept
Stores the transpose of the top-left 3x3 values currently held within XMTRX into the given matrix.
void shz_xmtrx_translate_reverse(float x, float y, float z) noexcept
Pre-multiplies and accumulates XMTRX onto the 3D translation matrix with the given components.
void shz_xmtrx_swap_cols(unsigned int index1, unsigned int index2) noexcept
Swaps the values of the columns with the given indices.
void shz_xmtrx_write_col(unsigned int index, shz_vec4_t vector) noexcept
Sets the values at the given column index to the given 4D vector.
void shz_xmtrx_apply_ortho(float left, float right, float bottom, float top, float znear, float zfar) noexcept
Applies a 2D orthographic projection matrix onto XMTRX, equivalent to glOrtho().
void shz_xmtrx_apply_transpose_4x4(const shz_mat4x4_t *matrix) noexcept
Multiplies and accumulates the transpose of the given 4x4 matrix onto XMTRX.
void shz_xmtrx_rotate_z(float radians) noexcept
Multiplies and accumulates XMTRX by a 3D rotation matrix about the Z axis.
void shz_xmtrx_load_apply_store_3x4(shz_mat3x4_t *out, const shz_mat3x4_t *matrix1, const shz_mat3x4_t *matrix2) noexcept
Loads XMTRX with the 3x4 result of applying matrix2 onto matrix1, storing the result.
void shz_xmtrx_negate(void) noexcept
Negates each element held within XMTRX.
void shz_xmtrx_load_apply_4x4(const shz_mat4x4_t *matrix1, const shz_mat4x4_t *matrix2) noexcept
Loads XMTRX with the result of applying matrix2 onto matrix1.
void shz_xmtrx_rotate_zyx(float zRadians, float yRadians, float xRadians) noexcept
Multiplies and accumulates XMTRX by 3D rotation matrices about the Z then Y then X axes.
void shz_xmtrx_load_apply_unaligned_4x4(const float matrix1[16], const float matrix2[16]) noexcept
Loads XMTRX with the result of applying unaligned matrix2 onto matrix1.
void shz_xmtrx_rotate(float radians, float xAxis, float yAxis, float zAxis) noexcept
Multiplies and accumulates XMTRX by the 3D rotation matrix formed by the given axis and angle (glRota...
void shz_xmtrx_apply_reverse_transpose_3x4(const shz_mat3x4_t *mat) noexcept
Multiplies and accumulates XMTRX onto the transpose of matrix, storing the result as XMTRX.
void shz_xmtrx_init_zero(void) noexcept
Initializes XMTRX to contain the value of 0.0f for each element.
void shz_xmtrx_init_lower_triangular(shz_vec4_t col1, shz_vec3_t col2, shz_vec2_t col3, float col4) noexcept
Initializes XMTRX to be a lower triangular matrix with the given column values.
void shz_xmtrx_init_one(void) noexcept
Initializes XMTRX to contain the value of 1.0f for each element.
void shz_xmtrx_init_fill(float value) noexcept
Initializes XMTRX to contain the given value for each element.
void shz_xmtrx_add_4x4(const shz_mat4x4_t *mat) noexcept
Adds each element within mat to each element within XMTRX, storing the result in XMTRX.
void shz_xmtrx_rotate_xyz(float xRadians, float yRadians, float zRadians) noexcept
Multiplies and accumulates XMTRX by 3D rotation matrices about the X then Y then Z axes.
void shz_xmtrx_init_rotation_z(float z) noexcept
Initializes XMTRX to be a 3D rotation matrix by z radians about the Z axis.
shz_xmtrx_reg
Registers comprising XMTRX, in the FPU back-bank.
Definition shz_xmtrx.h:68
@ SHZ_XMTRX_XF8
FP register xf8.
Definition shz_xmtrx.h:77
@ SHZ_XMTRX_XF9
FP register xf9.
Definition shz_xmtrx.h:78
@ SHZ_XMTRX_XF12
FP register xf12.
Definition shz_xmtrx.h:81
@ SHZ_XMTRX_XF11
FP register xf11.
Definition shz_xmtrx.h:80
@ SHZ_XMTRX_XF14
FP register xf14.
Definition shz_xmtrx.h:83
@ SHZ_XMTRX_XF3
FP register xf3.
Definition shz_xmtrx.h:72
@ SHZ_XMTRX_XF6
FP register xf6.
Definition shz_xmtrx.h:75
@ SHZ_XMTRX_XF4
FP register xf4.
Definition shz_xmtrx.h:73
@ SHZ_XMTRX_XF13
FP register xf13.
Definition shz_xmtrx.h:82
@ SHZ_XMTRX_XF10
FP register xf10.
Definition shz_xmtrx.h:79
@ SHZ_XMTRX_XF2
FP register xf2.
Definition shz_xmtrx.h:71
@ SHZ_XMTRX_XF0
FP register xf0.
Definition shz_xmtrx.h:69
@ SHZ_XMTRX_XF5
FP register xf5.
Definition shz_xmtrx.h:74
@ SHZ_XMTRX_XF7
FP register xf7.
Definition shz_xmtrx.h:76
@ SHZ_XMTRX_XF15
FP register xf15.
Definition shz_xmtrx.h:84
@ SHZ_XMTRX_XF1
FP register xf1.
Definition shz_xmtrx.h:70
void shz_xmtrx_rotate_zxy(float zRadians, float xRadians, float yRadians) noexcept
Multiplies and accumulates XMTRX by 3D rotation matrices about the Z then X then Y axes.
void shz_xmtrx_apply_frustum(float left, float right, float bottom, float top, float znear, float zfar) noexcept
Applies a frustum projection matrix onto XMTRX, equivalent to glFrustum().
void shz_xmtrx_apply_unaligned_4x4(const float matrix[16]) noexcept
Multiplies and accumulates the given 16-entry float array as a 4x4 matrix onto XMTRX.
void shz_xmtrx_load_transpose_unaligned_4x4(const float matrix[16]) noexcept
Loads XMTRX with the transpose of the 4x4 matrix created from the given unaligned array of 16 floats.
void shz_xmtrx_load_wxyz_4x4(const shz_mat4x4_t *matrix) noexcept
Loads the given 4x4 matrix as XMTRX, with the 4th column for translation being loaded as the first co...
void shz_xmtrx_apply_store_unaligned_4x4(float out[16], const float in[16]) noexcept
Multiplies XMTRX by the unaligned matrix, in, storing the result within the unaligned matrix,...
void shz_xmtrx_load_cols_4x4(const shz_vec4_t *c1, const shz_vec4_t *c2, const shz_vec4_t *c3, const shz_vec4_t *c4) noexcept
Sets XMTRX equal to the 4x4 matrix created from the 4 given 4D column vectors.
void shz_xmtrx_apply_symmetric_skew(float x, float y, float z) noexcept
Multiplies and accumulates the 3D symmetric skew matrix with the given components onto XMTRX.
void shz_xmtrx_init_rotation_y(float y) noexcept
Initializes XMTRX to be a 3D rotation matrix by y radians about the Y axis.
void shz_xmtrx_apply_reverse_unaligned_4x4(const float matrix[16]) noexcept
Multiplies and accumulates XMTRX onto the given float array as a 4x4 matrix, storing the result as XM...
void shz_xmtrx_load_2x2(const shz_mat2x2_t *matrix) noexcept
Loads the given 2x2 matrix into XMTRX, initializing its remaining elements to identity.
void shz_xmtrx_init_rotation_quat(shz_quat_t q) noexcept
Initializes XMTRX to a 3D rotation matrix with its orientation given by a quaternion.
shz_vec4_t shz_xmtrx_read_row(unsigned int index) noexcept
Returns the values at the the given row index, as a 4D vector.
void shz_xmtrx_init_ortho(float left, float right, float bottom, float top, float znear, float zfar) noexcept
Initializes XMTRX to an orthographic projection matrix, equivalent to glOrtho().
void shz_xmtrx_rotate_y(float radians) noexcept
Multiplies and accumulates XMTRX by a 3D rotation matrix about the Y axis.
void shz_xmtrx_apply_rotation_xyz(float xAngle, float yAngle, float zAngle) noexcept
Multiplies and accumulates XMTRX by a 3D X-Y-Z rotation matrix, with the corresponding angles given i...
void shz_xmtrx_store_transpose_3x4(shz_mat3x4_t *matrix) noexcept
Stores the transpose of the top-left 3x4 values currently held within XMTRX into the given matrix.
shz_vec3_t shz_xmtrx_get_translation(void) noexcept
Returns the translational components from the last column of XMTRX, as a 3D vector.
void shz_xmtrx_apply_permutation_wzyx(void) noexcept
Multiplies and accumulates a permutation matrix, which reorders the components of transformed vectors...
void shz_xmtrx_apply_reverse_4x4(const shz_mat4x4_t *matrix) noexcept
Multiplies and accumulates XMTRX onto matrix, storing the result as XMTRX.
void shz_xmtrx_store_4x4(shz_mat4x4_t *matrix) noexcept
Stores the current values held within XMTRX into the given 4x4 matrix.
void shz_xmtrx_init_rotation_zxy(float zAngle, float xAngle, float yAngle) noexcept
Initializes XMTRX to be a 3D Z-X-Y rotation matrix, with the corresponding angles given in radians.
void shz_xmtrx_apply_2x2(const shz_mat2x2_t *matrix) noexcept
Multiplies and accumulates the given 2x2 matrix onto XMTRX, not modifying other elements.
void shz_xmtrx_apply_3x3(const shz_mat3x3_t *matrix) noexcept
Multiplies and accumulates the given 3x3 matrix onto XMTRX, not modifying other elements.
void shz_xmtrx_init_rotation_yxz(float yAngle, float xAngle, float zAngle) noexcept
Initializes XMTRX to be a 3D Y-X-Z rotation matrix, with the corresponding angles given in radians.
void shz_xmtrx_apply_perspective(float fov, float aspect, float znear) noexcept
Multiplies and accumulates the perspective matrix constructed from the given values onto XMTRX.
void shz_xmtrx_swap_rows(unsigned int index1, unsigned int index2) noexcept
Swaps the values of the rows with the given indices.
void shz_xmtrx_apply_rotation_yxz(float yAngle, float xAngle, float zAngle) noexcept
Multiplies and accumulates XMTRX by a 3D Y-X-Z rotation matrix, with the corresponding angles given i...
void shz_xmtrx_apply_rotation_y(float y) noexcept
Transforms the values of the inner 3x3 matrix by a rotation matrix of y radians about the Y axis.
void shz_xmtrx_init_scale(float x, float y, float z) noexcept
Initializes XMTRX to be a 3D scale matrix with the given dimensions.
void shz_xmtrx_apply_store_4x4(shz_mat4x4_t *out, const shz_mat4x4_t *in) noexcept
Multiplies XMTRX by the matrix, in, storing the result within the matrix, out.
void shz_xmtrx_apply_4x4(const shz_mat4x4_t *matrix) noexcept
Multiplies and accumulates the given 4x4 matrix onto XMTRX.
void shz_xmtrx_load_3x3(const shz_mat3x3_t *matrix) noexcept
Loads the given 3x3 matrix into XMTRX, initalizing its remaining elements to identity.
shz_vec3_t shz_xmtrx_get_scale(void) noexcept
Returns the scaling components from the inner 3x3 matrix of XMTRX, as a 3D vector.
void shz_xmtrx_apply_reverse_transpose_4x4(const shz_mat4x4_t *matrix) noexcept
Multiplies and accumulates XMTRX onto the transpose of matrix, storing the result as XMTRX.
shz_vec3_t shz_xmtrx_transform_vec3(shz_vec3_t vec) noexcept
Returns the 3D vector that is the result of transforming vec by XMTRX.
void shz_xmtrx_load_rows_3x4(const shz_vec4_t *r1, const shz_vec4_t *r2, const shz_vec4_t *r3) noexcept
Loads the 3x4 matrix formed from the given 3 4D row vectors into XMTRX.
void shz_xmtrx_init_rotation_xyz(float xAngle, float yAngle, float zAngle) noexcept
Initializes XMTRX to be a 3D X-Y-Z rotation matrix, with the corresponding angles given in radians.
shz_vec3_t shz_xmtrx_transform_point3(shz_vec3_t pt) noexcept
Returns the 3D point that is the result of transforming pt by XMTRX.
void shz_xmtrx_apply_rotation_zyx(float zAngle, float yAngle, float xAngle) noexcept
Multiplies and accumulates XMTRX by a 3D Z-Y-X rotation matrix, with the corresponding angles given i...
void shz_xmtrx_init_symmetric_skew(float x, float y, float z) noexcept
Initializes XMTRX to be the 3D symmetric skew matrix formed from the given vector components.
void shz_xmtrx_store_transpose_4x4(shz_mat4x4_t *matrix) noexcept
Stores the transpose of the current values held within XMTRX into the given 4x4 matrix.
void shz_xmtrx_apply_self(void) noexcept
Multiplies and accumulatse the XMTRX matrix by itself, squaring it.
float shz_xmtrx_determinant(void) noexcept
Returns the determinant of XMTRX.
void shz_xmtrx_apply_rotation(float angle, float x, float y, float z) noexcept
Transforms the values of the inner 3x3 matrix by a rotation matrix of angle radians about the axis wi...
shz_vec2_t shz_xmtrx_transform_point2(shz_vec2_t pt) noexcept
Returns the 2D point that is the result of transforming pt by XMTRX.
void shz_xmtrx_store_transpose_unaligned_4x4(float matrix[16]) noexcept
Stores the transpose of the the current values held within XMTRX into the given 16-element float arra...
void shz_xmtrx_apply_transpose_unaligned_4x4(const float matrix[16]) noexcept
Multiplies and accumulates the transpose of the given 16-entry float array as a 4x4 matrix onto XMTRX...
void shz_xmtrx_init_screen(float width, float height) noexcept
Initializes XMTRX to the viewport matrix with the given dimensions.
shz_vec4_t shz_xmtrx_transform_vec4(shz_vec4_t vec) noexcept
Returns the 4D vector that is the result of transforming vec by XMTRX.
void shz_xmtrx_transpose(void) noexcept
Transposes the elements within XMTRX, in-place.
shz_vec2_t shz_xmtrx_transform_vec2(shz_vec2_t vec) noexcept
Returns the 2D vector that is the result of transforming vec by XMTRX.
void shz_xmtrx_apply_3x4(const shz_mat3x4_t *matrix) noexcept
Multiplies and accumulates the given 3x4 matrix onto XMTRX, not modifying other elements.
void shz_xmtrx_init_rotation_x(float x) noexcept
Initializes XMTRX to be a 3D rotation matrix by x radians about the X axis.
void shz_xmtrx_init_permutation_yzwx(void) noexcept
Initializes XMTRX to a permutation matrix, which reorders the components of transformed vectors to be...
void shz_xmtrx_load_4x4(const shz_mat4x4_t *matrix) noexcept
Loads the given 4x4 matrix as XMTRX.
void shz_xmtrx_scale(float x, float y, float z) noexcept
Multiplies and accumulates XMTRX by a 3D scaling matrix with the given components (glScalef() equival...
void shz_xmtrx_init_perspective(float fov, float aspect, float znear) noexcept
Initializes XMTRX to a perspective projection matrix.
void shz_xmtrx_apply_permutation_yzwx(void) noexcept
Multiplies and accumulates a permutation matrix, which reorders the components of transformed vectors...
void shz_xmtrx_apply_scale(float x, float y, float z) noexcept
Multiplies the values of the inner 3x3 matrix by the given 3D scaling terms.
void shz_xmtrx_init_lookat(shz_vec3_t eye, shz_vec3_t center, shz_vec3_t up) noexcept
Initializes XMTRX to a "lookAt" view matrix, equivalent to gluLookAt().
void shz_xmtrx_load_apply_store_4x4(shz_mat4x4_t *out, const shz_mat4x4_t *matrix1, const shz_mat4x4_t *matrix2) noexcept
Loads XMTRX with the 4x4 result of applying matrix2 onto matrix1, storing the result.
void shz_xmtrx_apply_permutation_wxyz(void) noexcept
Multiplies and accumulates a permutation matrix, which reorders the components of transformed vectors...
void shz_xmtrx_translate(float x, float y, float z) noexcept
Multiplies and accumulates XMTRX by a 3D translation matrix with the given components (glTranslatef()...
void shz_xmtrx_apply_rotation_zxy(float zAngle, float xAngle, float yAngle) noexcept
Multiplies and accumulates XMTRX by a 3D Z-X-Y rotation matrix, with the corresponding angles given i...
float shz_xmtrx_read(shz_xmtrx_reg_t xf) noexcept
Returns the floating-point value held within the given XMTRX register.
void shz_xmtrx_load_transpose_4x4(const shz_mat4x4_t *matrix) noexcept
Loads XMTRX with the transpose of the given 4x4 matrix.
void shz_xmtrx_init_translation(float x, float y, float z) noexcept
Initializes XMTRX to be a 3D translation matrix to the given coordinates.
void shz_xmtrx_sub_4x4(const shz_mat4x4_t *mat) noexcept
Subtracts each element within mat from each element within XMTRX, storing the result in XMTRX.
void shz_xmtrx_init_permutation_wxyz(void) noexcept
Initializes XMTRX to a permutation matrix, which reorders the components of transformed vectors to be...
void shz_xmtrx_apply_lookat(shz_vec3_t eye, shz_vec3_t center, shz_vec3_t up) noexcept
Applies the 3D "lookAt" matrix constructed with the given vector components onto XMTRX....
void shz_xmtrx_init_outer_product(shz_vec4_t x, shz_vec4_t y) noexcept
Initializes XMTRX to the 4D matrix resulting from taking the outer product of the two 4D vectors.
void shz_xmtrx_apply_reverse_transpose_unaligned_4x4(const float matrix[16]) noexcept
Multiplies and accumulates XMTRX onto the transpose of the given float array as a 4x4 matrix,...
void shz_xmtrx_load_3x4(const shz_mat3x4_t *matrix) noexcept
Loads the given 3x4 matrix into XMTRX, initializing its remaining elements to identity.
void shz_xmtrx_init_permutation_wzyx(void) noexcept
Initializes XMTRX to a permutation matrix, which reorders the components of transformed vectors to be...
void shz_xmtrx_load_cols_4x3(const shz_vec4_t *c1, const shz_vec4_t *c2, const shz_vec4_t *c3) noexcept
Loads the 3x4 matrix formed from the given 3 4D column vectors into XMTRX.
void shz_xmtrx_store_3x3(shz_mat3x3_t *matrix) noexcept
Stores the top-left 3x3 values currently held within XMTRX into the given matrix.
void shz_xmtrx_apply_screen(float width, float height) noexcept
Multiplies and accumulates the viewport matrix created with the given components.
void shz_xmtrx_load_apply_3x4(const shz_mat3x4_t *matrix1, const shz_mat3x4_t *matrix2) noexcept
Loads XMTRX with the result of applying matrix2 onto matrix1.
void shz_xmtrx_apply_translation(float x, float y, float z) noexcept
Adds the values of the given 3 components to the 3D translation components of XMTRX.
void shz_xmtrx_rotate_yxz(float yRadians, float xRadians, float zRadians) noexcept
Multiplies and accumulates XMTRX by 3D rotation matrices about the Y then X then Z axes.
void shz_xmtrx_abs(void) noexcept
Takes the absolute value of each element held within XMTRX.
void shz_xmtrx_store_2x2(shz_mat2x2_t *matrix) noexcept
Stores the top-left 2x2 values currently held within XMTRX into the given matrix.
void shz_xmtrx_apply_rotation_x(float x) noexcept
Transforms the values of the inner 3x3 matrix by a rotation matrix of x radians about the X axis.
void shz_xmtrx_write_row(unsigned int index, shz_vec4_t vector) noexcept
Sets the values at the given row index to the given 4D vector.
void shz_xmtrx_init_rotation(float angle, float xAxis, float yAxis, float zAxis) noexcept
Initializes XMTRX to a 3D rotation matrix of angle radians about the vector with the given components...
void shz_xmtrx_init_rotation_dir(float angle, float x, float y, float z) noexcept
Initializes XMTRX to contain a 3D rotation matrix of angle radians about the given axis.
void shz_xmtrx_write(shz_xmtrx_reg_t xf, float value) noexcept
Sets the floating-point value held within the given XMTRX register to value.
void shz_xmtrx_load_rows_4x4(const shz_vec4_t *r1, const shz_vec4_t *r2, const shz_vec4_t *r3, const shz_vec4_t *r4) noexcept
Sets XMTRX equal to the 4x4 matrix created from the 4 given 4D row vectors.
void shz_xmtrx_apply_transpose_3x4(const shz_mat3x4_t *matrix) noexcept
Multiplies and accumulates the transpose of the given 3x4 matrix onto XMTRX, not modifying other elem...
void shz_xmtrx_init_frustum(float left, float right, float bottom, float top, float znear, float zfar) noexcept
Initializes XMTRX to a frustum projection matrix, equivalent to glFrustum().
Structure representing a 4x4 column-major matrix.
Definition shz_matrix.h:65