1 /*---------------------------------------------------------------------------*
2 Project: Dolphin/Revolution gx demo
3 File: tf-pn-mtx.c
4
5 Copyright 1998-2006 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 #include <demo.h>
15 #include <math.h>
16
17 /*---------------------------------------------------------------------------*
18 Forward references
19 *---------------------------------------------------------------------------*/
20
21 void main ( void );
22
23 static void CameraInit ( void );
24 static void DrawInit ( void );
25 static void VertexLightInit ( void );
26 static void DrawTick ( void );
27
28 static void AnimTick ( void );
29
30 /*---------------------------------------------------------------------------*
31 Global variables
32 *---------------------------------------------------------------------------*/
33 Mtx v;
34 u32 rot;
35
36 /*---------------------------------------------------------------------------*
37 Application main loop
38 *---------------------------------------------------------------------------*/
main(void)39 void main ( void )
40 {
41 DEMOInit(NULL);
42
43 DrawInit(); // Define my vertex formats and set array pointers.
44
45 DEMOPadRead(); // Read the joystick for this frame
46
47 // While the quit button is not pressed
48 while(!(DEMOPadGetButton(0) & PAD_BUTTON_MENU))
49 {
50 DEMOPadRead(); // Read the joystick for this frame
51
52 // Do animation based on input
53 AnimTick();
54 DEMOBeforeRender();
55
56 DrawTick(); // Draw the model.
57
58 DEMODoneRender();
59 }
60
61 OSHalt("End of test");
62 }
63
64 /*---------------------------------------------------------------------------*
65 Functions
66 *---------------------------------------------------------------------------*/
67
68
69 /*---------------------------------------------------------------------------*
70 Name: CameraInit
71
72 Description: Initialize the projection matrix and load into hardware.
73
74 Arguments: v view matrix to be passed to ViewInit
75 cameraLocScale scale for the camera's distance from the
76 object - to be passed to ViewInit
77
78 Returns: none
79 *---------------------------------------------------------------------------*/
CameraInit(void)80 static void CameraInit ( void )
81 {
82 Mtx44 p;
83 Vec camPt = {0.0F, 0.0F, 650.0F};
84 Vec up = {0.0F, 1.0F, 0.0F};
85 Vec origin = {0.0F, 0.0F, 0.0F};
86
87 MTXFrustum(p, 240, -240, -320, 320, 500, 2000);
88
89 GXSetProjection(p, GX_PERSPECTIVE);
90
91 MTXLookAt(v, &camPt, &up, &origin);
92 }
93
94 /*---------------------------------------------------------------------------*
95 Name: DrawInit
96
97 Description: Calls the correct initialization function for the current
98 model.
99
100 Arguments: none
101
102 Returns: none
103 *---------------------------------------------------------------------------*/
DrawInit(void)104 static void DrawInit( void )
105 {
106 CameraInit(); // Initialize the camera.
107 VertexLightInit();
108 }
109
110 /*---------------------------------------------------------------------------*/
VertexLightInit(void)111 static void VertexLightInit ( void )
112 {
113 GXLightObj MyLight;
114 GXColor color = {255, 255, 255, 255};
115
116 GXInitLightPos(&MyLight, 0.0F, 0.0F, 0.0F);
117 GXInitLightColor(&MyLight, color);
118 GXLoadLightObjImm(&MyLight, GX_LIGHT0);
119
120 GXSetChanMatColor(GX_COLOR0, color);
121
122 GXSetChanCtrl( GX_COLOR0,
123 GX_TRUE, // enable channel
124 GX_SRC_REG, // amb source
125 GX_SRC_REG, // mat source
126 GX_LIGHT0, // light mask
127 GX_DF_CLAMP,// diffuse function
128 GX_AF_NONE);
129
130 GXSetNumChans(1);
131 GXSetNumTexGens( 0 );
132 GXSetTevOp( GX_TEVSTAGE0, GX_PASSCLR );
133 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
134 }
135
136 /*---------------------------------------------------------------------------*
137 Name: DrawTick
138
139 Description: Draw the current model once.
140
141 Arguments: v view matrix
142 m model matrix
143
144 Returns: none
145 *---------------------------------------------------------------------------*/
DrawTick(void)146 static void DrawTick( void )
147 {
148 Mtx rx, ry, rz, s, mv, t;
149
150
151 MTXScale(s, 70, 70, 70);
152 MTXRotDeg(rx, 'X', (float)rot);
153 MTXRotDeg(ry, 'Y', (float)rot);
154 MTXRotDeg(rz, 'Z', (float)rot);
155
156 MTXTrans(t, -240, 150, 0);
157 MTXConcat(rx, s, mv);
158 MTXConcat(t, mv, mv);
159 MTXConcat(v, mv, mv);
160 GXLoadPosMtxImm(mv, GX_PNMTX0);
161 MTXInverse(mv, mv);
162 MTXTranspose(mv, mv);
163 GXLoadNrmMtxImm(mv, GX_PNMTX0);
164
165 MTXTrans(t, -80, 150, 0);
166 MTXConcat(ry, s, mv);
167 MTXConcat(t, mv, mv);
168 MTXConcat(v, mv, mv);
169 GXLoadPosMtxImm(mv, GX_PNMTX1);
170 MTXInverse(mv, mv);
171 MTXTranspose(mv, mv);
172 GXLoadNrmMtxImm(mv, GX_PNMTX1);
173
174 MTXTrans(t, 80, 150, 0);
175 MTXConcat(rz, s, mv);
176 MTXConcat(t, mv, mv);
177 MTXConcat(v, mv, mv);
178 GXLoadPosMtxImm(mv, GX_PNMTX2);
179 MTXInverse(mv, mv);
180 MTXTranspose(mv, mv);
181 GXLoadNrmMtxImm(mv, GX_PNMTX2);
182
183 MTXTrans(t, 240, 150, 0);
184 MTXConcat(rx, s, mv);
185 MTXConcat(ry, mv, mv);
186 MTXConcat(t, mv, mv);
187 MTXConcat(v, mv, mv);
188 GXLoadPosMtxImm(mv, GX_PNMTX3);
189 MTXInverse(mv, mv);
190 MTXTranspose(mv, mv);
191 GXLoadNrmMtxImm(mv, GX_PNMTX3);
192
193 MTXTrans(t, -240, -150, 0);
194 MTXConcat(rx, s, mv);
195 MTXConcat(rz, mv, mv);
196 MTXConcat(t, mv, mv);
197 MTXConcat(v, mv, mv);
198 GXLoadPosMtxImm(mv, GX_PNMTX4);
199 MTXInverse(mv, mv);
200 MTXTranspose(mv, mv);
201 GXLoadNrmMtxImm(mv, GX_PNMTX4);
202
203 MTXTrans(t, -80, -150, 0);
204 MTXConcat(ry, s, mv);
205 MTXConcat(rz, mv, mv);
206 MTXConcat(t, mv, mv);
207 MTXConcat(v, mv, mv);
208 GXLoadPosMtxImm(mv, GX_PNMTX5);
209 MTXInverse(mv, mv);
210 MTXTranspose(mv, mv);
211 GXLoadNrmMtxImm(mv, GX_PNMTX5);
212
213 MTXTrans(t, 80, -150, 0);
214 MTXConcat(rz, s, mv);
215 MTXConcat(ry, mv, mv);
216 MTXConcat(t, mv, mv);
217 MTXConcat(v, mv, mv);
218 GXLoadPosMtxImm(mv, GX_PNMTX6);
219 MTXInverse(mv, mv);
220 MTXTranspose(mv, mv);
221 GXLoadNrmMtxImm(mv, GX_PNMTX6);
222
223 MTXTrans(t, 240, -150, 0);
224 MTXConcat(rz, s, mv);
225 MTXConcat(rx, mv, mv);
226 MTXConcat(t, mv, mv);
227 MTXConcat(v, mv, mv);
228 GXLoadPosMtxImm(mv, GX_PNMTX7);
229 MTXInverse(mv, mv);
230 MTXTranspose(mv, mv);
231 GXLoadNrmMtxImm(mv, GX_PNMTX7);
232
233 MTXTrans(t, -80, 0, 0);
234 MTXConcat(rz, s, mv);
235 MTXConcat(rx, mv, mv);
236 MTXConcat(ry, mv, mv);
237 MTXConcat(t, mv, mv);
238 MTXConcat(v, mv, mv);
239 GXLoadPosMtxImm(mv, GX_PNMTX8);
240 MTXInverse(mv, mv);
241 MTXTranspose(mv, mv);
242 GXLoadNrmMtxImm(mv, GX_PNMTX8);
243
244 MTXTrans(t, 80, 0, 0);
245 MTXConcat(rx, s, mv);
246 MTXConcat(ry, mv, mv);
247 MTXConcat(rz, mv, mv);
248 MTXConcat(t, mv, mv);
249 MTXConcat(v, mv, mv);
250 GXLoadPosMtxImm(mv, GX_PNMTX9);
251 MTXInverse(mv, mv);
252 MTXTranspose(mv, mv);
253 GXLoadNrmMtxImm(mv, GX_PNMTX9);
254
255 GXSetCurrentMtx(GX_PNMTX0);
256 GXDrawCube();
257
258 GXSetCurrentMtx(GX_PNMTX1);
259 GXDrawCube();
260
261 GXSetCurrentMtx(GX_PNMTX2);
262 GXDrawCube();
263
264 GXSetCurrentMtx(GX_PNMTX3);
265 GXDrawCube();
266
267 GXSetCurrentMtx(GX_PNMTX4);
268 GXDrawCube();
269
270 GXSetCurrentMtx(GX_PNMTX5);
271 GXDrawCube();
272
273 GXSetCurrentMtx(GX_PNMTX6);
274 GXDrawCube();
275
276 GXSetCurrentMtx(GX_PNMTX7);
277 GXDrawCube();
278
279 GXSetCurrentMtx(GX_PNMTX8);
280 GXDrawCube();
281
282 GXSetCurrentMtx(GX_PNMTX9);
283 GXDrawCube();
284
285 }
286
287 /*---------------------------------------------------------------------------*
288 Name: AnimTick
289
290 Description: Animates the camera and object based on the joystick's
291 state.
292
293 Arguments: none
294
295 Returns: none
296 *---------------------------------------------------------------------------*/
AnimTick(void)297 static void AnimTick ( void )
298 {
299 rot ++;
300 if(rot > 719)
301 rot = 0;
302 }
303
304 /*---------------------------------------------------------------------------*/
305
306
307