1 /*---------------------------------------------------------------------------*
2 Project: Matrix Vector Library (Structure Version)
3 File: matVec.h
4
5 Copyright (C) Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 *---------------------------------------------------------------------------*/
14
15 /*---------------------------------------------------------------------------*
16 Matrix-Vector Library (Structure Version)
17 *---------------------------------------------------------------------------*/
18
19 #ifndef __MATVEC_H__
20 #define __MATVEC_H__
21
22 #include <cafe/mtx.h>
23 #include <cafe/mtx/mtxGeoTypes.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /// @addtogroup MAT
30 /// @{
31
32 /*---------------------------------------------------------------------------*
33 GENERAL MATRIX SECTION
34 *---------------------------------------------------------------------------*/
35
36 /// \brief Set a 3x4 matrix to the identity.
37 ///
38 /// \param m Matrix to be set.
39 ///
40 /// \par Usage
41 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
42 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
43 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
44 ///
45 /// \donotcall \threadsafe \devonly \enddonotcall
46 ///
MAT34Identity(Mat34 * m)47 static inline void MAT34Identity ( Mat34 *m )
48 { MTXIdentity ( (MtxPtr)(m->mtx) ); }
49
50 /// \brief Copies the contents of one 3x4 matrix into another
51 ///
52 /// \param src Source matrix for the copy.
53 /// \param dst Destination matrix for the copy.
54 ///
55 /// \par Usage
56 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
57 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
58 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
59 ///
60 /// \donotcall \threadsafe \devonly \enddonotcall
61 ///
MAT34Copy(const Mat34 * src,Mat34 * dst)62 static inline void MAT34Copy ( const Mat34 *src, Mat34 *dst )
63 { MTXCopy ( (MtxPtr)(src->mtx), (MtxPtr)(dst->mtx) ); }
64
65 /// \brief Concatenates two 3x4 matrices
66 ///
67 /// Order of operations is A x B = AB.
68 /// This function can handle the case when ab == a == b.
69 ///
70 /// \param a First matrix to concatenate
71 /// \param b Second matrix to concatenate
72 /// \param ab Resulting matrix from concatenate
73 ///
74 /// \par Usage
75 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
76 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
77 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
78 ///
79 /// \donotcall \threadsafe \devonly \enddonotcall
80 ///
MAT34Concat(const Mat34 * a,const Mat34 * b,Mat34 * ab)81 static inline void MAT34Concat ( const Mat34 *a, const Mat34 *b, Mat34 *ab )
82 { MTXConcat ( (MtxPtr)(a->mtx), (MtxPtr)(b->mtx), (MtxPtr)(ab->mtx) ); }
83
84 /// \brief Concatenates a 3x4 matrix to an array of 3x4 matrices.
85 /// The order of operations is A x B(array) = AB(array)
86 /// This routine is equivalent to:
87 ///
88 /// dstBase[i] = A x srcBase[i] for all i = 0 to count - 1
89 ///
90 /// \param a first matrix for concatenation
91 /// \param srcBase array base of second matrix for concatenation
92 /// \param dstBase array base of resulting matrix from concatenation
93 /// \param count number of matrices in srcBase and dstBase arrays
94 ///
95 /// \warning This routine cannot check for array overflow.
96 ///
97 /// \par Usage
98 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
99 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
100 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
101 ///
102 /// \donotcall \threadsafe \devonly \enddonotcall
103 ///
MAT34ConcatArray(const Mat34 * a,const Mat34 * srcBase,Mat34 * dstBase,u32 count)104 static inline void MAT34ConcatArray ( const Mat34 *a, const Mat34 *srcBase, Mat34 *dstBase, u32 count )
105 { MTXConcatArray ( (MtxPtr)(a->mtx), (Mtx *)(void *)(srcBase->mtx), (Mtx *)(&dstBase->mtx), count ); }
106
107 /// \brief Computes the transpose of a 3x4 matrix.
108 ///
109 /// \note It is safe for src == xPose
110 ///
111 /// \warning If the matrix is a 3x4 matrix, the fourth column (translation
112 /// component) is lost and becomes (0, 0, 0). This function is intended for
113 /// use in computing an inverse-transpose matrix to transform normals for
114 /// lighting. In this case, the loss of the translation component doesn't
115 /// matter.
116 ///
117 /// \param src Source matrix
118 /// \param xPose Destination (transposed) matrix
119 ///
120 /// \par Usage
121 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
122 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
123 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
124 ///
125 /// \donotcall \threadsafe \devonly \enddonotcall
126 ///
MAT34Transpose(const Mat34 * src,Mat34 * xPose)127 static inline void MAT34Transpose ( const Mat34 *src, Mat34 *xPose )
128 { MTXTranspose ( (MtxPtr)(src->mtx), (MtxPtr)(xPose->mtx) ); }
129
130 /// \brief Computes a fast inverse of a 3x4 matrix.
131 /// This algorithm works for matrices with a fourth row of (0, 0, 0, 1).
132 ///
133 /// For a matrix:
134 ///
135 /// M = | A C |
136 /// | 0 1 |
137 ///
138 /// Where A is the upper 3x3 submatrix and C is a 1x3 column vector:
139 ///
140 /// INV(M) = | inv(A) inv(A)*(-C) |
141 /// | 0 1 |
142 ///
143 /// \note It is safe for src == inv.
144 ///
145 /// \param src Source matrix
146 /// \param inv Destination (inverse) matrix
147 /// \return 0 if src is not invertible, 1 on success.
148 ///
149 /// \par Usage
150 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
151 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
152 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
153 ///
154 /// \donotcall \threadsafe \devonly \enddonotcall
155 ///
MAT34Inverse(const Mat34 * src,Mat34 * inv)156 static inline u32 MAT34Inverse ( const Mat34 *src, Mat34 *inv )
157 { return MTXInverse ( (MtxPtr)(src->mtx), (MtxPtr)(inv->mtx) ); }
158
159 /// \brief Computes a fast inverse-transpose of a 3x4 matrix.
160 ///
161 /// This algorithm works for matrices with a fourth row of (0, 0, 0, 1).
162 /// Commonly used for calculating normal transform matrices.
163 ///
164 /// This function is equivalent to the combination of two functions
165 /// \ref MTXInverse + \ref MTXTranspose
166 ///
167 /// \note It is safe to call this function if src == invX.
168 ///
169 /// \param src Source matrix
170 /// \param invX Destination (inverse-transpose) matrix.
171 /// \return 0 if src is not invertible, 1 on success.
172 ///
173 /// \par Usage
174 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
175 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
176 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
177 ///
178 /// \donotcall \threadsafe \devonly \enddonotcall
179 ///
MAT34InvXpose(const Mat34 * src,Mat34 * invX)180 static inline u32 MAT34InvXpose ( const Mat34 *src, Mat34 *invX )
181 { return MTXInvXpose ( (MtxPtr)(src->mtx), (MtxPtr)(invX->mtx) ); }
182
183 /*---------------------------------------------------------------------------*
184 MATRIX-VECTOR SECTION
185 *---------------------------------------------------------------------------*/
186
187 /// \brief Multiplies a vector by a 3x4 matrix
188 ///
189 /// dst = m x src
190 ///
191 /// \note It is safe for src == dst.
192 ///
193 /// \param m Matrix to multiply by
194 /// \param src Source vector of multiply
195 /// \param dst Resulting vector from multiply
196 ///
197 /// \par Usage
198 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
199 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
200 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
201 ///
202 /// \donotcall \threadsafe \devonly \enddonotcall
203 ///
MAT34MultVec(const Mat34 * m,const Vec * src,Vec * dst)204 static inline void MAT34MultVec ( const Mat34 *m, const Vec *src, Vec *dst )
205 { MTXMultVec ( (MtxPtr)(m->mtx), src, dst ); }
206
207 /// \brief Multiplies an array of vectors by a 3x4 matrix.
208 ///
209 /// \note It is safe for srcBase == dstBase.
210 ///
211 /// \warning This function cannot check for array overflow.
212 ///
213 /// \param m Matrix to multiply by
214 /// \param srcBase Source vector array
215 /// \param dstBase Resulting vector array
216 /// \param count Number of vectors in srcBase and dstBase arrays.
217 ///
218 ///
219 /// \par Usage
220 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
221 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
222 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
223 ///
224 /// \donotcall \threadsafe \devonly \enddonotcall
225 ///
MAT34MultVecArray(const Mat34 * m,const Vec * srcBase,Vec * dstBase,u32 count)226 static inline void MAT34MultVecArray ( const Mat34 *m, const Vec *srcBase, Vec *dstBase, u32 count )
227 { MTXMultVecArray ( (MtxPtr)(m->mtx), srcBase, dstBase, count ); }
228
229 /// \brief Multiply a vector by a 3x4 Scaling and Rotating matrix
230 /// \note It is assumed that the 4th column (translation) is 0.
231 ///
232 /// This is equivalent to:
233 ///
234 /// dst = m x src
235 ///
236 /// \note It is safe for src == dst.
237 ///
238 /// \param m Matrix to multiply by
239 /// \param src Source vector for multiply
240 /// \param dst Resulting vector from multiply
241 ///
242 /// \par Usage
243 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
244 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
245 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
246 ///
247 /// \donotcall \threadsafe \devonly \enddonotcall
248 ///
MAT34MultVecSR(const Mat34 * m,const Vec * src,Vec * dst)249 static inline void MAT34MultVecSR ( const Mat34 *m, const Vec *src, Vec *dst )
250 { MTXMultVecSR ( (MtxPtr)(m->mtx), src, dst ); }
251
252 /// \brief Multiply an array of vector by a 3x4 Scaling and Rotating matrix
253 /// \note It is assumed that the 4th column (translation) is 0.
254 ///
255 /// This is equivalent to:
256 ///
257 /// dstBase[i] = m x srcBase[i]
258 ///
259 /// \note It is safe for srcBase == dstBase.
260 ///
261 /// \warning This function cannot check for array overflow
262 ///
263 /// \param m Matrix to multiply by
264 /// \param srcBase Source vector array
265 /// \param dstBase Resulting vector array
266 /// \param count Number of vectors in srcBase and dstBase
267 ///
268 ///
269 /// \par Usage
270 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
271 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
272 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
273 ///
274 /// \donotcall \threadsafe \devonly \enddonotcall
275 ///
MAT34MultVecArraySR(const Mat34 * m,const Vec * srcBase,Vec * dstBase,u32 count)276 static inline void MAT34MultVecArraySR ( const Mat34 *m, const Vec *srcBase, Vec *dstBase, u32 count )
277 { MTXMultVecArraySR ( (MtxPtr)(m->mtx), srcBase, dstBase, count ); }
278
279 /*---------------------------------------------------------------------------*
280 MODEL MATRIX SECTION
281 *---------------------------------------------------------------------------*/
282
283 /// \brief Sets a rotation 3x4 matrix from a quaternion.
284 ///
285 /// \param m Matrix to be set.
286 /// \param q Pointer to Quaternion
287 ///
288 /// \par Usage
289 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
290 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
291 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
292 ///
293 /// \donotcall \threadsafe \devonly \enddonotcall
294 ///
MAT34Quat(Mat34 * m,const Quaternion * q)295 static inline void MAT34Quat ( Mat34 *m, const Quaternion *q )
296 { MTXQuat ( (MtxPtr)(m->mtx), q ); }
297
298 /// \brief Reflect a rotation 3x4 matrix with respect to a plane.
299 ///
300 /// \param m Matrix to be set.
301 /// \param p point on the plane
302 /// \param n normal of the plane
303 ///
304 /// \par Usage
305 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
306 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
307 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
308 ///
309 /// \donotcall \threadsafe \devonly \enddonotcall
310 ///
MAT34Reflect(Mat34 * m,const Vec * p,const Vec * n)311 static inline void MAT34Reflect ( Mat34 *m, const Vec *p, const Vec *n )
312 { MTXReflect ( (MtxPtr)(m->mtx), p, n ); }
313
314 /// \brief Sets a translation 3x4 matrix
315 ///
316 /// \param m Matrix to be set
317 /// \param xT x component of translation
318 /// \param yT y component of translation
319 /// \param zT z component of translation
320 ///
321 /// \par Usage
322 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
323 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
324 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
325 ///
326 /// \donotcall \threadsafe \devonly \enddonotcall
327 ///
MAT34Trans(Mat34 * m,f32 xT,f32 yT,f32 zT)328 static inline void MAT34Trans ( Mat34 *m, f32 xT, f32 yT, f32 zT )
329 { MTXTrans ( (MtxPtr)(m->mtx), xT, yT, zT ); }
330
331 /// \brief Apply a translation to a 3x4 matrix.
332 /// This function is equivalent to \ref MTXTrans + \ref MTXConcat.
333 ///
334 /// \note This is safe for the case where src == dst.
335 ///
336 /// \param src Matrix to multiply the translation by
337 /// \param dst Resulting matrix from concatenation
338 /// \param xT x component of translation
339 /// \param yT y component of translation
340 /// \param zT z component of translation
341 ///
342 /// \par Usage
343 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
344 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
345 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
346 ///
347 /// \donotcall \threadsafe \devonly \enddonotcall
348 ///
MAT34TransApply(const Mat34 * src,Mat34 * dst,f32 xT,f32 yT,f32 zT)349 static inline void MAT34TransApply ( const Mat34 *src, Mat34 *dst, f32 xT, f32 yT, f32 zT )
350 { MTXTransApply ( (MtxPtr)(src->mtx), (MtxPtr)(dst->mtx), xT, yT, zT ); }
351
352 /// \brief Sets a scale 3x4 matrix
353 ///
354 /// \param m Matrix to be set
355 /// \param xS x component of scale
356 /// \param yS y component of scale
357 /// \param zS z component of scale
358 ///
359 /// \par Usage
360 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
361 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
362 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
363 ///
364 /// \donotcall \threadsafe \devonly \enddonotcall
365 ///
MAT34Scale(Mat34 * m,f32 xS,f32 yS,f32 zS)366 static inline void MAT34Scale ( Mat34 *m, f32 xS, f32 yS, f32 zS )
367 { MTXScale ( (MtxPtr)(m->mtx), xS, yS, zS ); }
368
369 /// \brief Apply a scale to a 3x4 matrix.
370 /// This function is equivalent to \ref MTXScale + \ref MTXConcat.
371 ///
372 /// \note This is safe for the case where src == dst.
373 ///
374 /// \param src Matrix to multiply the scale by
375 /// \param dst Resulting matrix from concatenation
376 /// \param xS x component of scale
377 /// \param yS y component of scale
378 /// \param zS z component of scale
379 ///
380 /// \par Usage
381 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
382 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
383 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
384 ///
385 /// \donotcall \threadsafe \devonly \enddonotcall
386 ///
MAT34ScaleApply(const Mat34 * src,Mat34 * dst,f32 xS,f32 yS,f32 zS)387 static inline void MAT34ScaleApply ( const Mat34 *src, Mat34 *dst, f32 xS, f32 yS, f32 zS )
388 { MTXScaleApply ( (MtxPtr)(src->mtx), (MtxPtr)(dst->mtx), xS, yS, zS ); }
389
390
391 /// \brief Sets a rotation 3x4 matrix about one of the X, Y or Z axes.
392 ///
393 /// \note Counter clockwise rotation is positive.
394 ///
395 /// \param m Matrix to be set
396 /// \param axis Principal axis of rotation. Must be 'X', 'x', 'Y', 'y', 'Z', or 'z'.
397 /// \param rad Rotation angle in radians
398 ///
399 /// \par Usage
400 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
401 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
402 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
403 ///
404 /// \donotcall \threadsafe \devonly \enddonotcall
405 ///
MAT34RotRad(Mat34 * m,char axis,f32 rad)406 static inline void MAT34RotRad ( Mat34 *m, char axis, f32 rad )
407 { MTXRotRad ( (MtxPtr)(m->mtx), axis, rad ); }
408
409 /// \brief Sets a rotation 3x4 matrix about one of the X, Y, or Z axes from specified trig ratios.
410 ///
411 /// \note Counter clockwise rotation is positive.
412 ///
413 /// \param m Matrix to be set
414 /// \param axis Principal axis of rotation. Must be 'X', 'x', 'Y', 'y', 'Z', or 'z'.
415 /// \param sinA Sine of rotation angle
416 /// \param cosA Cosine of rotation angle
417 ///
418 /// \par Usage
419 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
420 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
421 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
422 ///
423 /// \donotcall \threadsafe \devonly \enddonotcall
424 ///
MAT34RotTrig(Mat34 * m,char axis,f32 sinA,f32 cosA)425 static inline void MAT34RotTrig ( Mat34 *m, char axis, f32 sinA, f32 cosA )
426 { MTXRotTrig ( (MtxPtr)(m->mtx), axis, sinA, cosA ); }
427
428 /// \brief Sets a rotation 3x4 matrix about an arbitrary axis.
429 ///
430 /// \note Counter clockwise rotation is positive.
431 ///
432 /// \param m Matrix to be set
433 /// \param axis Pointer to a vector containing the (x, y, z) axis components
434 /// \param rad Rotation angle in radians
435 ///
436 /// \par Usage
437 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
438 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
439 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
440 ///
441 /// \donotcall \threadsafe \devonly \enddonotcall
442 ///
MAT34RotAxisRad(Mat34 * m,const Vec * axis,f32 rad)443 static inline void MAT34RotAxisRad ( Mat34 *m, const Vec *axis, f32 rad )
444 { MTXRotAxisRad ( (MtxPtr)(m->mtx), axis, rad ); }
445
446 /// \brief Sets a rotation 3x4 matrix about one of the X, Y or Z axes.
447 ///
448 /// \note Counter clockwise rotation is positive.
449 ///
450 /// \param m Matrix to be set
451 /// \param axis Principal axis of rotation. Must be 'X', 'x', 'Y', 'y', 'Z', or 'z'.
452 /// \param deg Rotation angle in degrees
453 ///
454 /// \par Usage
455 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
456 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
457 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
458 ///
459 /// \donotcall \threadsafe \devonly \enddonotcall
460 ///
461 #define MAT34RotDeg( m, axis, deg ) \
462 MAT34RotRad( m, axis, MTXDegToRad(deg) )
463
464 /// \brief Sets a rotation 3x4 matrix about an arbitrary axis.
465 ///
466 /// \note Counter clockwise rotation is positive.
467 ///
468 /// \param m Matrix to be set
469 /// \param axis Pointer to a vector containing the (x, y, z) axis components
470 /// \param deg Rotation angle in degrees
471 ///
472 /// \par Usage
473 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
474 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
475 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
476 ///
477 /// \donotcall \threadsafe \devonly \enddonotcall
478 ///
479 #define MAT34RotAxisDeg( m, axis, deg ) \
480 MAT34RotAxisRad( m, axis, MTXDegToRad(deg) )
481
482 /*---------------------------------------------------------------------------*
483 VIEW MATRIX SECTION
484 *---------------------------------------------------------------------------*/
485
486 /// \brief Compute a 3x4 matrix to transform points to camera coordinates.
487 ///
488 /// \param m Matrix to be set
489 /// \param camPos Camera position
490 /// \param camUp Camera 'up' direction
491 /// \param target Camera aim point
492 ///
493 /// \par Usage
494 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
495 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
496 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
497 ///
498 /// \donotcall \threadsafe \devonly \enddonotcall
499 ///
MAT34LookAt(Mat34 * m,const Point3d * camPos,const Vec * camUp,const Point3d * target)500 static inline void MAT34LookAt ( Mat34 *m,
501 const Point3d *camPos,
502 const Vec *camUp,
503 const Point3d *target )
504 { MTXLookAt( (MtxPtr)(m->mtx), camPos, camUp, target ); }
505
506 /*---------------------------------------------------------------------------*
507 PROJECTION MATRIX SECTION
508 *---------------------------------------------------------------------------*/
509
510 /// \brief Compute a 4x4 perspective projection matrix from a specified view volume.
511 ///
512 /// \param m 4x4 Matrix to be set
513 /// \param t Top coordinate of the viewing volume at the near clipping plane
514 /// \param b Bottom coordinate of the viewing volume at the near clipping plane
515 /// \param l Left coordinate of the viewing volume at the near clipping plane
516 /// \param r Right coordinate of the viewing volume at the near clipping plane
517 /// \param n Positive distance from camera to the near clipping plane
518 /// \param f Positive distance from camera to the far clipping plane
519 ///
520 /// \par Usage
521 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
522 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
523 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
524 ///
525 /// \donotcall \threadsafe \devonly \enddonotcall
526 ///
MAT44Frustum(Mat44 * m,f32 t,f32 b,f32 l,f32 r,f32 n,f32 f)527 static inline void MAT44Frustum ( Mat44 *m, f32 t, f32 b, f32 l, f32 r, f32 n, f32 f )
528 { MTXFrustum ( (Mtx44Ptr)(m->mtx), t, b, l, r, n, f ); }
529
530 /// \brief Compute a 4x4 perspective projection matrix from the field of view and aspect ratio.
531 ///
532 /// \param m 4x4 Matrix to be set
533 /// \param fovY Total field of view in degrees in the YZ plane
534 /// \param aspect Ratio of view window width:height (X / Y)
535 /// \param n Positive distance from camera to the near clipping plane
536 /// \param f Positive distance from camera to the far clipping plane
537 ///
538 /// \par Usage
539 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
540 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
541 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
542 ///
543 /// \donotcall \threadsafe \devonly \enddonotcall
544 ///
MAT44Perspective(Mat44 * m,f32 fovY,f32 aspect,f32 n,f32 f)545 static inline void MAT44Perspective ( Mat44 *m, f32 fovY, f32 aspect, f32 n, f32 f )
546 { MTXPerspective ( (Mtx44Ptr)(m->mtx), fovY, aspect, n, f ); }
547
548 /// \brief Compute a 4x4 orthographic projection matrix.
549 ///
550 /// \param m 4x4 Matrix to be set
551 /// \param t Top coordinate of the parallel view volume.
552 /// \param b Bottom coordinate of the parallel view volume.
553 /// \param l Left coordinate of the parallel view volume.
554 /// \param r Right coordinate of the parallel view volume.
555 /// \param n Positive distance from camera to the near clipping plane
556 /// \param f Positive distance from camera to the far clipping plane
557 ///
558 /// \par Usage
559 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
560 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
561 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
562 ///
563 /// \donotcall \threadsafe \devonly \enddonotcall
564 ///
MAT44Ortho(Mat44 * m,f32 t,f32 b,f32 l,f32 r,f32 n,f32 f)565 static inline void MAT44Ortho ( Mat44 *m, f32 t, f32 b, f32 l, f32 r, f32 n, f32 f )
566 { MTXOrtho ( (Mtx44Ptr)(m->mtx), t, b, l, r, n, f ); }
567
568 /*---------------------------------------------------------------------------*
569 TEXTURE PROJECTION MATRIX SECTION
570 *---------------------------------------------------------------------------*/
571
572 /// \brief Compute a 3x4 perspective projection matrix for texture projection.
573 ///
574 /// \param m Matrix to be set
575 /// \param t Top coordinate of the viewing volume at the near clipping plane
576 /// \param b Bottom coordinate of the viewing volume at the near clipping plane
577 /// \param l Left coordinate of the viewing volume at the near clipping plane
578 /// \param r Right coordinate of the viewing volume at the near clipping plane
579 /// \param n Positive distance from camera to the near clipping plane
580 /// \param scaleS Scale in the S direction for projected coordinates (usually 0.5)
581 /// \param scaleT Scale in the T direction for projected coordinates (usually 0.5)
582 /// \param transS Translate in the S direction for projected coordinates (usually 0.5)
583 /// \param transT Translate in the T direction for projected coordinates (usually 0.5)
584 ///
585 /// \par Usage
586 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
587 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
588 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
589 ///
590 /// \donotcall \threadsafe \devonly \enddonotcall
591 ///
MAT34LightFrustum(Mat34 * m,f32 t,f32 b,f32 l,f32 r,f32 n,f32 scaleS,f32 scaleT,f32 transS,f32 transT)592 static inline void MAT34LightFrustum ( Mat34 *m, f32 t, f32 b, f32 l, f32 r, f32 n,
593 f32 scaleS, f32 scaleT, f32 transS,
594 f32 transT )
595 { MTXLightFrustum( (MtxPtr)(m->mtx), t, b, l, r, n, scaleS, scaleT, transS, transT ); }
596
597 /// \brief Compute a 3x4 perspective projection matrix from field of view and aspect ratio for texture projection.
598 ///
599 /// \param m Matrix to be set
600 /// \param fovY Total field of view in degrees in the YZ plane
601 /// \param aspect Ratio of view window width:height (X / Y)
602 /// \param scaleS Scale in the S direction for projected coordinates (usually 0.5)
603 /// \param scaleT Scale in the T direction for projected coordinates (usually 0.5)
604 /// \param transS Translate in the S direction for projected coordinates (usually 0.5)
605 /// \param transT Translate in the T direction for projected coordinates (usually 0.5)
606 ///
607 /// \par Usage
608 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
609 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
610 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
611 ///
612 /// \donotcall \threadsafe \devonly \enddonotcall
613 ///
MAT34LightPerspective(Mat34 * m,f32 fovY,f32 aspect,f32 scaleS,f32 scaleT,f32 transS,f32 transT)614 static inline void MAT34LightPerspective ( Mat34 *m, f32 fovY, f32 aspect, f32 scaleS,
615 f32 scaleT, f32 transS, f32 transT )
616 { MTXLightPerspective( (MtxPtr)(m->mtx), fovY, aspect, scaleS, scaleT, transS, transT ); }
617
618 /// \brief Compute a 3x4 orthographic projection matrix for texture projection.
619 ///
620 /// \param m Matrix to be set
621 /// \param t Top coordinate of the viewing volume at the near clipping plane
622 /// \param b Bottom coordinate of the viewing volume at the near clipping plane
623 /// \param l Left coordinate of the viewing volume at the near clipping plane
624 /// \param r Right coordinate of the viewing volume at the near clipping plane
625 /// \param scaleS Scale in the S direction for projected coordinates (usually 0.5)
626 /// \param scaleT Scale in the T direction for projected coordinates (usually 0.5)
627 /// \param transS Translate in the S direction for projected coordinates (usually 0.5)
628 /// \param transT Translate in the T direction for projected coordinates (usually 0.5)
629 ///
630 /// \par Usage
631 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
632 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
633 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
634 ///
635 /// \donotcall \threadsafe \devonly \enddonotcall
636 ///
MAT34LightOrtho(Mat34 * m,f32 t,f32 b,f32 l,f32 r,f32 scaleS,f32 scaleT,f32 transS,f32 transT)637 static inline void MAT34LightOrtho ( Mat34 *m, f32 t, f32 b, f32 l, f32 r, f32 scaleS,
638 f32 scaleT, f32 transS, f32 transT )
639 { MTXLightOrtho( (MtxPtr)(m->mtx), t, b, l, r, scaleS, scaleT, transS, transT ); }
640
641 /*---------------------------------------------------------------------------*
642 SPECIAL PURPOSE MATRIX SECTION
643 *---------------------------------------------------------------------------*/
644 /// \brief Creates a reordered (column-major) matrix from a row-major matrix.
645 /// This is useful for getting better performance for the MTXRO* functions.
646 ///
647 /// \warning It is not safe to have src == dst.
648 ///
649 /// \param src Source matrix
650 /// \param dest Destination matrix, note type is ROMtx.
651 ///
652 /// \par Usage
653 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
654 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
655 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
656 ///
657 /// \donotcall \threadsafe \devonly \enddonotcall
658 ///
PSMAT34Reorder(const Mat34 * src,Mat43 * dest)659 static inline void PSMAT34Reorder ( const Mat34 *src, Mat43 *dest )
660 { MTXReorder ( (MtxPtr)(src->mtx), (ROMtxPtr)(dest->mtx) ); }
661
662 /// \brief Multiplies an array of vectors by a reordered matrix.
663 ///
664 /// \note It is ok for source == destination.
665 /// \note Number of vertices transformed cannot be less than 2.
666 ///
667 /// \param m Reordered matrix
668 /// \param srcBase Start of source vector array
669 /// \param dstBase Start of the resulting vector array
670 /// \param count Number of vectors in srcBase and dstBase arrays. Count must be greater than 2.
671 ///
672 /// \par Usage
673 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
674 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
675 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
676 ///
677 /// \donotcall \threadsafe \devonly \enddonotcall
678 ///
PSMAT43MultVecArray(const Mat43 * m,const Vec * srcBase,Vec * dstBase,u32 count)679 static inline void PSMAT43MultVecArray ( const Mat43 *m, const Vec *srcBase, Vec *dstBase, u32 count )
680 { MTXROMultVecArray ( (ROMtxPtr)(m->mtx), srcBase, dstBase, count ); }
681
682
683 /*---------------------------------------------------------------------------*
684 MATRIX STACK SECTION
685 *---------------------------------------------------------------------------*/
686 /// \brief Initializes a matrix stack size and stack ptr from a previously allocated stack
687 /// This resets the stack pointer to NULL(empty) and updates the stack size.
688 ///
689 /// \note The stack (array) memory must have been previously allocated. Use \ref MTXAllocStack and \ref MTXFreeStack to create/destroy the stack.
690 ///
691 /// \param sPtr Pointer to \ref Mat34Stack structure to be initialized
692 /// \param numMat34 Number of matrices in the stack
693 ///
694 /// \par Usage
695 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
696 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
697 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
698 ///
699 /// \donotcall \threadsafe \devonly \enddonotcall
700 ///
MAT34InitStack(Mat34Stack * sPtr,u32 numMat34)701 static inline void MAT34InitStack ( Mat34Stack *sPtr, u32 numMat34 )
702 { MTXInitStack ( (MtxStackPtr)(void *)(sPtr), numMat34 ); }
703
704 /// \brief Copy a matrix to stack pointer + 1.
705 /// Increment the stack pointer.
706 ///
707 /// \param sPtr Pointer to Mat34Stack structure
708 /// \param m Matrix to copy into (stack pointer + 1) location
709 /// \return Returns the resulting stack pointer
710 ///
711 /// \par Usage
712 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
713 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
714 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
715 ///
716 /// \donotcall \threadsafe \devonly \enddonotcall
717 ///
MAT34Push(Mat34Stack * sPtr,const Mat34 * m)718 static inline Mat34 * MAT34Push ( Mat34Stack *sPtr, const Mat34 *m )
719 { return (Mat34 *)(void *) MTXPush ( (MtxStackPtr)(void *)(sPtr), (MtxPtr)(m->mtx) ); }
720
721 /// \brief Concatenate a matrix with the current top of the stack push
722 /// the resulting matrix onto the stack.
723 /// This is intended for use in building forward transformations, so
724 /// concatentation is post-order:
725 ///
726 /// (top of stack + 1) = (top of stack x m);
727 ///
728 /// \param sPtr Pointer to Mat34Stack structure
729 /// \param m Matrix to concatenate with stack pointer and push to (stack pointer + 1)
730 /// \return Returns the resulting stack pointer
731 ///
732 /// \par Usage
733 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
734 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
735 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
736 ///
737 /// \donotcall \threadsafe \devonly \enddonotcall
738 ///
MAT34PushFwd(Mat34Stack * sPtr,const Mat34 * m)739 static inline Mat34 * MAT34PushFwd ( Mat34Stack *sPtr, const Mat34 *m )
740 { return (Mat34 *)(void *) MTXPushFwd ( (MtxStackPtr)(void *)(sPtr), (MtxPtr)(m->mtx) ); }
741
742 /// \brief Concatenate the inverse of a matrix with the top of the stack
743 /// and push the resulting matrix onto the stack.
744 /// This is intended for building inverse transformations so concatenation
745 /// is pre-order:
746 ///
747 /// (top of stack + 1) = (m x top of stack);
748 ///
749 /// \note m is not modified by this function.
750 ///
751 /// \param sPtr Pointer to Mat34Stack structure
752 /// \param m Matrix to inverse-concatenate with stack pointer and push to (stack pointer + 1)
753 /// \return Returns the resulting stack pointer
754 ///
755 /// \par Usage
756 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
757 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
758 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
759 ///
760 /// \donotcall \threadsafe \devonly \enddonotcall
761 ///
MAT34PushInv(Mat34Stack * sPtr,const Mat34 * m)762 static inline Mat34 * MAT34PushInv ( Mat34Stack *sPtr, const Mat34 *m )
763 { return (Mat34 *)(void *) MTXPushInv ( (MtxStackPtr)(void *)(sPtr), (MtxPtr)(m->mtx) ); }
764
765 /// \brief Concatenate the inverse-transpose of a matrix with the top of the
766 /// stack and push the resulting matrix onto the stack.
767 /// This is intended for building inverse-transpose matrix for forward
768 /// transformations of normals, so concatenation is post-order:
769 ///
770 /// (top of stack + 1) = (top of stack x m);
771 ///
772 /// \param sPtr Pointer to Mat34Stack structure
773 /// \param m Matrix to inverse-concatenate with stack pointer and push to (stack pointer + 1)
774 /// \return Returns the resulting stack pointer
775 ///
776 /// \par Usage
777 /// \note m is not modified by this function.
778 ///
779 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
780 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
781 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
782 ///
783 /// \donotcall \threadsafe \devonly \enddonotcall
784 ///
MAT34PushInvXpose(Mat34Stack * sPtr,const Mat34 * m)785 static inline Mat34 * MAT34PushInvXpose ( Mat34Stack *sPtr, const Mat34 *m )
786 { return (Mat34 *)(void *) MTXPushInvXpose ( (MtxStackPtr)(void *)(sPtr), (MtxPtr)(m->mtx) ); }
787
788 /// \brief Decrement the stack pointer.
789 ///
790 /// \param sPtr Pointer to Mat34Stack structure
791 /// \return Returns the stack pointer.
792 ///
793 /// \par Usage
794 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
795 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
796 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
797 ///
798 /// \donotcall \threadsafe \devonly \enddonotcall
799 ///
MAT34Pop(Mat34Stack * sPtr)800 static inline Mat34 * MAT34Pop ( Mat34Stack *sPtr )
801 { return (Mat34 *)(void *) MTXPop ( (MtxStackPtr)(void *)(sPtr) ); }
802
803 /// \brief Return the stack pointer.
804 ///
805 /// \param sPtr Pointer to Mat34Stack structure
806 /// \return Returns the current stack pointer
807 ///
808 /// \par Usage
809 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
810 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
811 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
812 ///
813 /// \donotcall \threadsafe \devonly \enddonotcall
814 ///
MAT34GetStackPtr(const Mat34Stack * sPtr)815 static inline Mat34 * MAT34GetStackPtr ( const Mat34Stack *sPtr )
816 { return (Mat34 *)(void *) MTXGetStackPtr ( (MtxStackPtr)(void *)(sPtr) ); }
817
818 /// \brief Macro to create a matrix stack.
819 /// \note This allocates using MEMAllocFromDefaultHeap. This can be modified
820 /// by the user.
821 ///
822 /// \param sPtr Pointer to Mat34Stack structure
823 /// \param numMat34 Number of \ref Mtx structures to allocate for the stack.
824 ///
825 /// \par Usage
826 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
827 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
828 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
829 ///
830 /// \donotcall \notthreadsafe \userheap \devonly \enddonotcall
831 ///
832 #define MAT34AllocStack( sPtr, numMat34 ) ( ((Mat34Stack *)(sPtr))->stackBase = (Mat34 *)MEMAllocFromDefaultHeap( ( (numMat34) * sizeof(Mat34) ) ) )
833
834 /// \brief Macro to free a matrix stack.
835 /// \note This allocates using MEMFreeToDefaultHeap. This can be modified
836 /// by the user.
837 ///
838 /// \param sPtr Pointer to Mat34Stack structure
839 ///
840 /// \par Usage
841 /// - Add "#define MTX_USE_ASM" prior to including the mtx header to use PPC Assembly based version
842 /// - Add "#define MTX_USE_PS" prior to including the mtx header to use PPC Paired-Single instruction based version
843 /// - Add "#define MTX_USE_C" prior to including the mtx header to use C implementation (default). This is useful for debugging.
844 ///
845 /// \donotcall \notthreadsafe \userheap \devonly \enddonotcall
846 ///
847 #define MAT34FreeStack( sPtr ) ( MEMFreeToDefaultHeap( (void*)( ((Mat34Stack *)(sPtr))->stackBase ) ) )
848
849 /*---------------------------------------------------------------------------*/
850
851 /// @}
852
853 #ifdef __cplusplus
854 }
855 #endif
856
857 #endif // __MATVEC_H__
858
859 /*===========================================================================*/
860
861