1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - FX -
3 File: fx_mtx44.h
4
5 Copyright 2003-2008 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 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #ifndef NITRO_FX_MTX44_H_
19 #define NITRO_FX_MTX44_H_
20
21 #include <nitro/fx/fx.h>
22 #include <nitro/fx/fx_const.h>
23 #include <nitro/mi/memory.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 //----------------------------------------------------------------------------
30 // Type definition
31 //----------------------------------------------------------------------------
32
33 //----------------------------------------------------------------------------
34 // Declaration of function
35 //----------------------------------------------------------------------------
36
37 SDK_DECL_INLINE void MTX_Identity44(MtxFx44 *pDst);
38 SDK_DECL_INLINE void MTX_Copy44To33(const MtxFx44 *pSrc, MtxFx33 *pDst);
39 SDK_DECL_INLINE void MTX_Copy44To43(const MtxFx44 *pSrc, MtxFx43 *pDst);
40 SDK_DECL_INLINE void MTX_Transpose44(const MtxFx44 *pSrc, MtxFx44 *pDst);
41 void MTX_TransApply44(const MtxFx44 *pSrc, MtxFx44 *pDst, fx32 x, fx32 y, fx32 z);
42 SDK_DECL_INLINE void MTX_Scale44(MtxFx44 *pDst, fx32 x, fx32 y, fx32 z);
43 void MTX_ScaleApply44(const MtxFx44 *pSrc, MtxFx44 *pDst, fx32 x, fx32 y, fx32 z);
44 SDK_DECL_INLINE void MTX_RotX44(MtxFx44 *pDst, fx32 sinVal, fx32 cosVal);
45 SDK_DECL_INLINE void MTX_RotY44(MtxFx44 *pDst, fx32 sinVal, fx32 cosVal);
46 SDK_DECL_INLINE void MTX_RotZ44(MtxFx44 *pDst, fx32 sinVal, fx32 cosVal);
47 void MTX_RotAxis44(MtxFx44 *pDst, const VecFx32 *vec, fx32 sinVal, fx32 cosVal);
48 void MTX_Concat44(const MtxFx44 *a, const MtxFx44 *b, MtxFx44 *ab);
49 void MTX_FrustumW(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 *mtx);
50 void MTX_PerspectiveW(fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, fx32 scaleW, MtxFx44 *mtx);
51 void MTX_OrthoW(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 *mtx);
52
53 void MTX_Identity44_(register MtxFx44 *pDst);
54 void MTX_Copy44To33_(register const MtxFx44 *pSrc, register MtxFx33 *pDst);
55 void MTX_Copy44To43_(register const MtxFx44 *pSrc, register MtxFx43 *pDst);
56 void MTX_Transpose44_(register const MtxFx44 *pSrc, register MtxFx44 *pDst);
57 void MTX_Scale44_(register MtxFx44 *pDst, register fx32 x, register fx32 y, register fx32 z);
58 void MTX_RotX44_(register MtxFx44 *pDst, register fx32 sinVal, register fx32 cosVal);
59 void MTX_RotY44_(register MtxFx44 *pDst, register fx32 sinVal, register fx32 cosVal);
60 void MTX_RotZ44_(register MtxFx44 *pDst, register fx32 sinVal, register fx32 cosVal);
61
62
63
64 //----------------------------------------------------------------------------
65 // Implementation of inline function
66 //----------------------------------------------------------------------------
67
68 /*---------------------------------------------------------------------------*
69 Name: MTX_Identity44
70
71 Description: Sets a matrix to identity.
72
73 Arguments: pDst a pointer to a 4x4 matrix
74
75 Returns: none
76 *---------------------------------------------------------------------------*/
MTX_Identity44(MtxFx44 * pDst)77 SDK_INLINE void MTX_Identity44(MtxFx44 *pDst)
78 {
79 SDK_NULL_ASSERT(pDst);
80 MTX_Identity44_(pDst);
81 }
82
83 /*---------------------------------------------------------------------------*
84 Name: MTX_Copy44
85
86 Description: Copies a 4x4 matrix to a 4x4 matrix.
87
88 Arguments: pSrc a pointer to a 4x4 matrix
89 pDst a pointer to a 4x4 matrix
90
91 Returns: none
92 *---------------------------------------------------------------------------*/
MTX_Copy44(const MtxFx44 * pSrc,MtxFx44 * pDst)93 SDK_INLINE void MTX_Copy44(const MtxFx44 *pSrc, MtxFx44 *pDst)
94 {
95 SDK_NULL_ASSERT(pSrc);
96 SDK_NULL_ASSERT(pDst);
97
98 MI_Copy64B(pSrc, pDst);
99 }
100
101
102 /*---------------------------------------------------------------------------*
103 Name: MTX_Copy44To33
104
105 Description: Copies a 4x4 matrix to a 3x3 matrix.
106
107 Arguments: pSrc a pointer to a 4x4 matrix
108 pDst a pointer to a 3x3 matrix
109
110 Returns: none
111 *---------------------------------------------------------------------------*/
MTX_Copy44To33(const MtxFx44 * pSrc,MtxFx33 * pDst)112 SDK_INLINE void MTX_Copy44To33(const MtxFx44 *pSrc, MtxFx33 *pDst)
113 {
114 SDK_NULL_ASSERT(pSrc);
115 SDK_NULL_ASSERT(pDst);
116
117 MTX_Copy44To33_(pSrc, pDst);
118 }
119
120
121 /*---------------------------------------------------------------------------*
122 Name: MTX_Copy44To43
123
124 Description: Copies a 4x4 matrix to a 4x3 matrix.
125
126 Arguments: pSrc a pointer to a 4x4 matrix
127 pDst a pointer to a 4x3 matrix
128
129 Returns: none
130 *---------------------------------------------------------------------------*/
MTX_Copy44To43(const MtxFx44 * pSrc,MtxFx43 * pDst)131 SDK_INLINE void MTX_Copy44To43(const MtxFx44 *pSrc, MtxFx43 *pDst)
132 {
133 SDK_NULL_ASSERT(pSrc);
134 SDK_NULL_ASSERT(pDst);
135
136 MTX_Copy44To43_(pSrc, pDst);
137 }
138
139 /*---------------------------------------------------------------------------*
140 Name: MTX_Transpose44
141
142 Description: Computes the transpose of a 4x4 matrix.
143
144 Arguments: pSrc a pointer to a 4x4 matrix
145 pDst a pointer to a 4x4 matrix
146
147 Returns: none
148 *---------------------------------------------------------------------------*/
MTX_Transpose44(const MtxFx44 * pSrc,MtxFx44 * pDst)149 SDK_INLINE void MTX_Transpose44(const MtxFx44 *pSrc, MtxFx44 *pDst)
150 {
151 SDK_NULL_ASSERT(pSrc);
152 SDK_NULL_ASSERT(pDst);
153
154 MTX_Transpose44_(pSrc, pDst);
155 }
156
157 /*---------------------------------------------------------------------------*
158 Name: MTX_Scale44
159
160 Description: Sets a scaling matrix.
161
162 Arguments: pDst a pointer to a 4x4 matrix
163 x x scale factor
164 y y scale factor
165 z z scale factor
166
167 Returns: none
168 *---------------------------------------------------------------------------*/
MTX_Scale44(MtxFx44 * pDst,fx32 x,fx32 y,fx32 z)169 SDK_INLINE void MTX_Scale44(MtxFx44 *pDst, fx32 x, fx32 y, fx32 z)
170 {
171 SDK_NULL_ASSERT(pDst);
172 MTX_Scale44_(pDst, x, y, z);
173 }
174
175 /*---------------------------------------------------------------------------*
176 Name: MTX_RotX44
177
178 Description: Sets a rotation matrix about the X axis.
179
180 Arguments: pDst a pointer to a 4x4 matrix
181 sinVal sine of an angle of rotation
182 cosVal cosine of an angle of rotation
183
184 Returns: none
185 *---------------------------------------------------------------------------*/
MTX_RotX44(MtxFx44 * pDst,fx32 sinVal,fx32 cosVal)186 SDK_INLINE void MTX_RotX44(MtxFx44 *pDst, fx32 sinVal, fx32 cosVal)
187 {
188 SDK_NULL_ASSERT(pDst);
189 MTX_RotX44_(pDst, sinVal, cosVal);
190 }
191
192
193 /*---------------------------------------------------------------------------*
194 Name: MTX_RotY44
195
196 Description: Sets a rotation matrix about the Y axis.
197
198 Arguments: pDst a pointer to a 4x4 matrix
199 sinVal sine of an angle of rotation
200 cosVal cosine of an angle of rotation
201
202 Returns: none
203 *---------------------------------------------------------------------------*/
MTX_RotY44(MtxFx44 * pDst,fx32 sinVal,fx32 cosVal)204 SDK_INLINE void MTX_RotY44(MtxFx44 *pDst, fx32 sinVal, fx32 cosVal)
205 {
206 SDK_NULL_ASSERT(pDst);
207 MTX_RotY44_(pDst, sinVal, cosVal);
208 }
209
210
211 /*---------------------------------------------------------------------------*
212 Name: MTX_RotZ44
213
214 Description: Sets a rotation matrix about the Z axis.
215
216 Arguments: pDst a pointer to a 4x4 matrix
217 sinVal sine of an angle of rotation
218 cosVal cosine of an angle of rotation
219
220 Returns: none
221 *---------------------------------------------------------------------------*/
MTX_RotZ44(MtxFx44 * pDst,fx32 sinVal,fx32 cosVal)222 SDK_INLINE void MTX_RotZ44(MtxFx44 *pDst, fx32 sinVal, fx32 cosVal)
223 {
224 SDK_NULL_ASSERT(pDst);
225 MTX_RotZ44_(pDst, sinVal, cosVal);
226 }
227
228
229 /*---------------------------------------------------------------------------*
230 Name: MTX_Frustum
231
232 Description: Computes a 4x4 perspective projection matrix from a specified
233 view volume.
234
235 Arguments: t top coordinate of view volume at the near clipping plane
236 b bottom coordinate of view volume at the near clipping plane
237 l left coordinate of view volume at near clipping plane
238 r right coordinate of view volume at near clipping plane
239 n positive distance from camera to near clipping plane
240 f positive distance from camera to far clipping plane
241 mtx 4x4 matrix to be set
242
243 Returns: none
244 *---------------------------------------------------------------------------*/
MTX_Frustum(fx32 t,fx32 b,fx32 l,fx32 r,fx32 n,fx32 f,MtxFx44 * mtx)245 SDK_INLINE void MTX_Frustum(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, MtxFx44 *mtx)
246 {
247 MTX_FrustumW(t, b, l, r, n, f, FX32_ONE, mtx);
248 }
249
250
251 /*---------------------------------------------------------------------------*
252 Name: MTX_Perspective
253
254 Description: Computes a 4x4 perspective projection matrix from field of
255 view and aspect ratio.
256
257 Arguments: fovySin sine value of fovy
258 fovyCos cosine value of fovy
259 aspect ratio of view window width:height (X / Y)
260 n positive distance from camera to near clipping plane
261 f positive distance from camera to far clipping plane
262 mtx 4x4 matrix to be set
263
264 Returns: none
265 *---------------------------------------------------------------------------*/
266 SDK_INLINE
MTX_Perspective(fx32 fovySin,fx32 fovyCos,fx32 aspect,fx32 n,fx32 f,MtxFx44 * mtx)267 void MTX_Perspective(fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, MtxFx44 *mtx)
268 {
269 MTX_PerspectiveW(fovySin, fovyCos, aspect, n, f, FX32_ONE, mtx);
270 }
271
272
273 /*---------------------------------------------------------------------------*
274 Name: MTX_Ortho
275
276 Description: Computes a 4x4 orthographic projection matrix.
277
278 Arguments: t top coordinate of parallel view volume
279 b bottom coordinate of parallel view volume
280 l left coordinate of parallel view volume
281 r right coordinate of parallel view volume
282 n positive distance from camera to near clipping plane
283 f positive distance from camera to far clipping plane
284 mtx 4x4 matrix to be set if not NULL
285
286 Returns: none
287 *---------------------------------------------------------------------------*/
MTX_Ortho(fx32 t,fx32 b,fx32 l,fx32 r,fx32 n,fx32 f,MtxFx44 * mtx)288 SDK_INLINE void MTX_Ortho(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, MtxFx44 *mtx)
289 {
290 MTX_OrthoW(t, b, l, r, n, f, FX32_ONE, mtx);
291 }
292
293
294 #ifdef __cplusplus
295 }/* extern "C" */
296 #endif
297
298 #endif
299