1 /*---------------------------------------------------------------------------*
2 Project: Dolphin/Revolution gx demo
3 File: geo-fmtPrim.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
16 void DrawQuadCube( void );
17 void DrawTriCube( void );
18 void DrawPointCube( void );
19 void DrawLineCube( void );
20 void DrawLineStripCube( void );
21 void DrawTriStripCube( void );
22 void DrawTriFanCube( void );
23
24
25 static void SendVertex ( u16 posIndex, u16 normalIndex, u16 colorIndex, u16 texCoordIndex );
26
27 /*---------------------------------------------------------------------------*
28 Global variables
29 *---------------------------------------------------------------------------*/
30 extern Mtx v;
31
32 extern float FloatVert[];
33 extern s16 Vert16[];
34 extern s8 Vert8[];
35
36 extern float FloatNorm[];
37 extern s16 Norm16[];
38 extern s8 Norm8[];
39
40 extern u8 ColorRGBA8[];
41 extern u8 ColorRGBA6[];
42 extern u8 ColorRGBA4[];
43 extern u8 ColorRGBX8[];
44 extern u8 ColorRGB8[];
45 extern u8 ColorRGB565[];
46
47 extern float FloatTex[];
48 extern u16 Tex16[];
49 extern u8 Tex8[];
50
51 extern u32 rot;
52
53 extern u8 ColorControl;
54 extern u8 NormalControl;
55 extern u8 TexCoordControl;
56 extern u8 PositionControl;
57
58
59 /*---------------------------------------------------------------------------*
60 Name: DrawQuadCube
61
62 Description: Draws the cube as Quads
63
64 Arguments: none
65
66 Returns: none
67 *---------------------------------------------------------------------------*/
DrawQuadCube(void)68 void DrawQuadCube( void )
69 {
70 Mtx mv, r1, r2, t;
71
72 MTXTrans(t, 0, -200, 0);
73 MTXRotDeg(r1, 'X', (float)rot);
74 MTXRotDeg(r2, 'y', (float)rot/2.0F);
75
76 MTXConcat(r2, r1, mv);
77 MTXConcat(t, mv, mv);
78 MTXConcat(v, mv, mv);
79 GXLoadPosMtxImm(mv, GX_PNMTX0);
80 MTXInverse(mv, mv);
81 MTXTranspose(mv, mv);
82 GXLoadNrmMtxImm(mv, GX_PNMTX0);
83
84 GXBegin(GX_QUADS, GX_VTXFMT0, 4*6);
85
86 SendVertex(0, 0, 1, 0);
87 SendVertex(1, 0, 2, 1);
88 SendVertex(2, 0, 3, 2);
89 SendVertex(3, 0, 4, 3);
90
91 SendVertex(4, 1, 0, 0);
92 SendVertex(5, 1, 0, 1);
93 SendVertex(6, 1, 0, 2);
94 SendVertex(7, 1, 0, 3);
95
96 SendVertex(2, 2, 0, 0);
97 SendVertex(6, 2, 0, 1);
98 SendVertex(5, 2, 0, 2);
99 SendVertex(3, 2, 0, 3);
100
101 SendVertex(1, 3, 0, 0);
102 SendVertex(0, 3, 0, 1);
103 SendVertex(4, 3, 0, 2);
104 SendVertex(7, 3, 0, 3);
105
106 SendVertex(5, 4, 0, 0);
107 SendVertex(4, 4, 0, 1);
108 SendVertex(0, 4, 0, 2);
109 SendVertex(3, 4, 0, 3);
110
111 SendVertex(6, 5, 0, 0);
112 SendVertex(2, 5, 0, 1);
113 SendVertex(1, 5, 0, 2);
114 SendVertex(7, 5, 0, 3);
115
116 GXEnd();
117 }
118
119 /*---------------------------------------------------------------------------*
120 Name: DrawTriCube
121
122 Description: Draws the cube as Triangles
123
124 Arguments: none
125
126 Returns: none
127 *---------------------------------------------------------------------------*/
DrawTriCube(void)128 void DrawTriCube( void )
129 {
130 Mtx mv, r1, r2, t;
131
132 MTXTrans(t, -250, 0, 0);
133 MTXRotDeg(r1, 'X', (float)rot);
134 MTXRotDeg(r2, 'y', (float)rot/2.0F);
135
136 MTXConcat(r2, r1, mv);
137 MTXConcat(t, mv, mv);
138 MTXConcat(v, mv, mv);
139 GXLoadPosMtxImm(mv, GX_PNMTX0);
140 MTXInverse(mv, mv);
141 MTXTranspose(mv, mv);
142 GXLoadNrmMtxImm(mv, GX_PNMTX0);
143
144
145 GXBegin(GX_TRIANGLES, GX_VTXFMT0, 6*6);
146
147 SendVertex(0, 0, 1, 0);
148 SendVertex(1, 0, 2, 1);
149 SendVertex(2, 0, 3, 2);
150 SendVertex(2, 0, 3, 2);
151 SendVertex(3, 0, 4, 3);
152 SendVertex(0, 0, 1, 0);
153
154 SendVertex(4, 1, 0, 0);
155 SendVertex(5, 1, 0, 1);
156 SendVertex(6, 1, 0, 2);
157 SendVertex(6, 1, 0, 2);
158 SendVertex(7, 1, 0, 3);
159 SendVertex(4, 1, 0, 0);
160
161 SendVertex(2, 2, 0, 0);
162 SendVertex(6, 2, 0, 1);
163 SendVertex(5, 2, 0, 2);
164 SendVertex(5, 2, 0, 2);
165 SendVertex(3, 2, 0, 3);
166 SendVertex(2, 2, 0, 0);
167
168 SendVertex(1, 3, 0, 0);
169 SendVertex(0, 3, 0, 1);
170 SendVertex(4, 3, 0, 2);
171 SendVertex(4, 3, 0, 2);
172 SendVertex(7, 3, 0, 3);
173 SendVertex(1, 3, 0, 0);
174
175 SendVertex(5, 4, 0, 0);
176 SendVertex(4, 4, 0, 1);
177 SendVertex(0, 4, 0, 2);
178 SendVertex(0, 4, 0, 2);
179 SendVertex(3, 4, 0, 3);
180 SendVertex(5, 4, 0, 0);
181
182 SendVertex(6, 5, 0, 0);
183 SendVertex(2, 5, 0, 1);
184 SendVertex(1, 5, 0, 2);
185 SendVertex(1, 5, 0, 2);
186 SendVertex(7, 5, 0, 3);
187 SendVertex(6, 5, 0, 0);
188
189 GXEnd();
190 }
191
192 /*---------------------------------------------------------------------------*
193 Name: DrawPointCube
194
195 Description: Draws the cube as Triangles
196
197 Arguments: none
198
199 Returns: none
200 *---------------------------------------------------------------------------*/
DrawPointCube(void)201 void DrawPointCube( void )
202 {
203 Mtx mv, r1, r2, t;
204
205 MTXTrans(t, -250, 200, 0);
206 MTXRotDeg(r1, 'X', (float)rot);
207 MTXRotDeg(r2, 'y', (float)rot/2.0F);
208
209 MTXConcat(r2, r1, mv);
210 MTXConcat(t, mv, mv);
211 MTXConcat(v, mv, mv);
212 GXLoadPosMtxImm(mv, GX_PNMTX0);
213 MTXInverse(mv, mv);
214 MTXTranspose(mv, mv);
215 GXLoadNrmMtxImm(mv, GX_PNMTX0);
216
217
218 GXBegin(GX_POINTS, GX_VTXFMT0, 8);
219
220 SendVertex(0, 0, 1, 0);
221 SendVertex(1, 0, 2, 1);
222 SendVertex(2, 0, 3, 2);
223 SendVertex(3, 0, 4, 3);
224 SendVertex(4, 1, 0, 0);
225 SendVertex(5, 1, 0, 1);
226 SendVertex(6, 1, 0, 2);
227 SendVertex(7, 1, 0, 3);
228
229 GXEnd();
230 }
231
232 /*---------------------------------------------------------------------------*
233 Name: DrawLineCube
234
235 Description: Draws the cube as Triangles
236
237 Arguments: none
238
239 Returns: none
240 *---------------------------------------------------------------------------*/
DrawLineCube(void)241 void DrawLineCube( void )
242 {
243 Mtx mv, r1, r2, t;
244
245 MTXTrans(t, 0, 200, 0);
246 MTXRotDeg(r1, 'X', (float)rot);
247 MTXRotDeg(r2, 'y', (float)rot/2.0F);
248
249 MTXConcat(r2, r1, mv);
250 MTXConcat(t, mv, mv);
251 MTXConcat(v, mv, mv);
252 GXLoadPosMtxImm(mv, GX_PNMTX0);
253 MTXInverse(mv, mv);
254 MTXTranspose(mv, mv);
255 GXLoadNrmMtxImm(mv, GX_PNMTX0);
256
257
258 GXBegin(GX_LINES, GX_VTXFMT0, 24);
259
260 SendVertex(0, 0, 1, 0);
261 SendVertex(1, 0, 2, 1);
262
263 SendVertex(1, 0, 2, 1);
264 SendVertex(2, 0, 3, 2);
265
266 SendVertex(2, 0, 3, 2);
267 SendVertex(3, 0, 4, 3);
268
269 SendVertex(3, 0, 4, 3);
270 SendVertex(0, 0, 1, 0);
271
272 SendVertex(4, 1, 0, 0);
273 SendVertex(5, 1, 0, 1);
274
275 SendVertex(5, 1, 0, 1);
276 SendVertex(6, 1, 0, 2);
277
278 SendVertex(6, 1, 0, 2);
279 SendVertex(7, 1, 0, 3);
280
281 SendVertex(7, 1, 0, 3);
282 SendVertex(4, 1, 0, 0);
283
284 SendVertex(0, 0, 0, 0);
285 SendVertex(4, 1, 0, 0);
286
287 SendVertex(1, 0, 0, 1);
288 SendVertex(7, 1, 0, 3);
289
290 SendVertex(2, 0, 0, 2);
291 SendVertex(6, 1, 0, 2);
292
293 SendVertex(3, 0, 0, 3);
294 SendVertex(5, 1, 0, 1);
295
296 GXEnd();
297 }
298
299 /*---------------------------------------------------------------------------*
300 Name: DrawLineStripCube
301
302 Description: Draws the cube as Triangles
303
304 Arguments: none
305
306 Returns: none
307 *---------------------------------------------------------------------------*/
DrawLineStripCube(void)308 void DrawLineStripCube( void )
309 {
310 Mtx mv, r1, r2, t;
311
312 MTXTrans(t, 250, 200, 0);
313 MTXRotDeg(r1, 'X', (float)rot);
314 MTXRotDeg(r2, 'y', (float)rot/2.0F);
315
316 MTXConcat(r2, r1, mv);
317 MTXConcat(t, mv, mv);
318 MTXConcat(v, mv, mv);
319 GXLoadPosMtxImm(mv, GX_PNMTX0);
320 MTXInverse(mv, mv);
321 MTXTranspose(mv, mv);
322 GXLoadNrmMtxImm(mv, GX_PNMTX0);
323
324 GXBegin(GX_LINESTRIP, GX_VTXFMT0, 10);
325
326 SendVertex(0, 0, 1, 0);
327 SendVertex(1, 0, 2, 1);
328 SendVertex(2, 0, 3, 2);
329 SendVertex(3, 0, 4, 3);
330 SendVertex(0, 0, 0, 0);
331 SendVertex(4, 1, 0, 0);
332 SendVertex(5, 1, 0, 1);
333 SendVertex(6, 1, 0, 2);
334 SendVertex(7, 1, 0, 3);
335 SendVertex(4, 1, 0, 0);
336
337 GXEnd();
338
339 GXBegin(GX_LINESTRIP, GX_VTXFMT0, 2);
340
341 SendVertex(3, 0, 0, 3);
342 SendVertex(5, 1, 0, 1);
343
344 GXEnd();
345
346 GXBegin(GX_LINESTRIP, GX_VTXFMT0, 2);
347
348 SendVertex(1, 0, 0, 1);
349 SendVertex(7, 1, 0, 3);
350
351 GXEnd();
352
353 GXBegin(GX_LINESTRIP, GX_VTXFMT0, 2);
354
355 SendVertex(2, 0, 0, 2);
356 SendVertex(6, 1, 0, 2);
357
358 GXEnd();
359 }
360
361 /*---------------------------------------------------------------------------*
362 Name: DrawTriStripCube
363
364 Description: Draws the cube as Triangles
365
366 Arguments: none
367
368 Returns: none
369 *---------------------------------------------------------------------------*/
DrawTriStripCube(void)370 void DrawTriStripCube( void )
371 {
372 Mtx mv, r1, r2, t;
373
374 MTXTrans(t, 0, 0, 0);
375 MTXRotDeg(r1, 'X', (float)rot);
376 MTXRotDeg(r2, 'y', (float)rot/2.0F);
377
378 MTXConcat(r2, r1, mv);
379 MTXConcat(t, mv, mv);
380 MTXConcat(v, mv, mv);
381 GXLoadPosMtxImm(mv, GX_PNMTX0);
382 MTXInverse(mv, mv);
383 MTXTranspose(mv, mv);
384 GXLoadNrmMtxImm(mv, GX_PNMTX0);
385
386 GXBegin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
387
388 SendVertex(1, 0, 1, 1);
389 SendVertex(2, 0, 2, 2);
390 SendVertex(0, 0, 3, 0);
391 SendVertex(3, 0, 4, 3);
392
393 GXEnd();
394
395 GXBegin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
396
397 SendVertex(5, 1, 0, 1);
398 SendVertex(6, 1, 0, 2);
399 SendVertex(4, 1, 0, 0);
400 SendVertex(7, 1, 0, 3);
401
402 GXEnd();
403
404 GXBegin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
405
406 SendVertex(6, 2, 0, 1);
407 SendVertex(5, 2, 0, 2);
408 SendVertex(2, 2, 0, 0);
409 SendVertex(3, 2, 0, 3);
410
411 GXEnd();
412
413 GXBegin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
414
415 SendVertex(0, 3, 0, 1);
416 SendVertex(4, 3, 0, 2);
417 SendVertex(1, 3, 0, 0);
418 SendVertex(7, 3, 0, 3);
419
420 GXEnd();
421
422 GXBegin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
423
424 SendVertex(4, 4, 0, 1);
425 SendVertex(0, 4, 0, 2);
426 SendVertex(5, 4, 0, 0);
427 SendVertex(3, 4, 0, 3);
428
429 GXEnd();
430
431 GXBegin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
432
433 SendVertex(2, 5, 0, 1);
434 SendVertex(1, 5, 0, 2);
435 SendVertex(6, 5, 0, 0);
436 SendVertex(7, 5, 0, 3);
437
438 GXEnd();
439 }
440
441 /*---------------------------------------------------------------------------*
442 Name: DrawTriFanCube
443
444 Description: Draws the cube as Triangles
445
446 Arguments: none
447
448 Returns: none
449 *---------------------------------------------------------------------------*/
DrawTriFanCube(void)450 void DrawTriFanCube( void )
451 {
452 Mtx mv, r1, r2, t;
453
454 MTXTrans(t, 250, 0, 0);
455 MTXRotDeg(r1, 'X', (float)rot);
456 MTXRotDeg(r2, 'y', (float)rot/2.0F);
457
458 MTXConcat(r2, r1, mv);
459 MTXConcat(t, mv, mv);
460 MTXConcat(v, mv, mv);
461 GXLoadPosMtxImm(mv, GX_PNMTX0);
462 MTXInverse(mv, mv);
463 MTXTranspose(mv, mv);
464 GXLoadNrmMtxImm(mv, GX_PNMTX0);
465
466 GXBegin(GX_TRIANGLEFAN, GX_VTXFMT0, 4);
467
468 SendVertex(0, 0, 1, 0);
469 SendVertex(1, 0, 2, 1);
470 SendVertex(2, 0, 3, 2);
471 SendVertex(3, 0, 4, 3);
472
473 GXEnd();
474
475 GXBegin(GX_TRIANGLEFAN, GX_VTXFMT0, 4);
476
477 SendVertex(4, 1, 0, 0);
478 SendVertex(5, 1, 0, 1);
479 SendVertex(6, 1, 0, 2);
480 SendVertex(7, 1, 0, 3);
481
482 GXEnd();
483
484 GXBegin(GX_TRIANGLEFAN, GX_VTXFMT0, 4);
485
486 SendVertex(2, 2, 0, 0);
487 SendVertex(6, 2, 0, 1);
488 SendVertex(5, 2, 0, 2);
489 SendVertex(3, 2, 0, 3);
490
491 GXEnd();
492
493 GXBegin(GX_TRIANGLEFAN, GX_VTXFMT0, 4);
494
495 SendVertex(1, 3, 0, 0);
496 SendVertex(0, 3, 0, 1);
497 SendVertex(4, 3, 0, 2);
498 SendVertex(7, 3, 0, 3);
499
500 GXEnd();
501
502 GXBegin(GX_TRIANGLEFAN, GX_VTXFMT0, 4);
503
504 SendVertex(5, 4, 0, 0);
505 SendVertex(4, 4, 0, 1);
506 SendVertex(0, 4, 0, 2);
507 SendVertex(3, 4, 0, 3);
508
509 GXEnd();
510
511 GXBegin(GX_TRIANGLEFAN, GX_VTXFMT0, 4);
512
513 SendVertex(6, 5, 0, 0);
514 SendVertex(2, 5, 0, 1);
515 SendVertex(1, 5, 0, 2);
516 SendVertex(7, 5, 0, 3);
517
518 GXEnd();
519 }
520
521 /*---------------------------------------------------------------------------*/
SendVertex(u16 posIndex,u16 normalIndex,u16 colorIndex,u16 texCoordIndex)522 static void SendVertex ( u16 posIndex, u16 normalIndex, u16 colorIndex, u16 texCoordIndex )
523 {
524 //position section
525 switch(PositionControl)
526 {
527 case 0:
528 case 1:
529 case 2:
530 GXPosition1x16(posIndex);
531 break;
532 case 3:
533 case 4:
534 case 5:
535 GXPosition1x8((u8)posIndex);
536 break;
537 case 6:
538 GXPosition3f32(FloatVert[(posIndex * 3)], FloatVert[(posIndex * 3) + 1], FloatVert[(posIndex * 3) + 2]);
539 break;
540 case 7:
541 GXPosition3s16(Vert16[(posIndex * 3)], Vert16[(posIndex * 3) + 1], Vert16[(posIndex * 3) + 2]);
542 break;
543 case 8:
544 GXPosition3s8(Vert8[(posIndex * 3)], Vert8[(posIndex * 3) + 1], Vert8[(posIndex * 3) + 2]);
545 break;
546 }
547
548 //normal section
549 switch(NormalControl)
550 {
551 case 0:
552 break;
553 case 1:
554 case 2:
555 case 3:
556 GXNormal1x16(normalIndex);
557 break;
558 case 4:
559 case 5:
560 case 6:
561 GXNormal1x8((u8)normalIndex);
562 break;
563 case 7:
564 GXNormal3f32(FloatNorm[(normalIndex * 3)], FloatNorm[(normalIndex * 3) + 1], FloatNorm[(normalIndex * 3) + 2]);
565 break;
566 case 8:
567 GXNormal3s16(Norm16[(normalIndex * 3)], Norm16[(normalIndex * 3) + 1], Norm16[(normalIndex * 3) + 2]);
568 break;
569 case 9:
570 GXNormal3s8(Norm8[(normalIndex * 3)], Norm8[(normalIndex * 3) + 1], Norm8[(normalIndex * 3) + 2]);
571 break;
572 }
573
574 //color section
575 switch(ColorControl)
576 {
577 case 0:
578 break;
579 case 1:
580 case 2:
581 case 3:
582 case 4:
583 case 5:
584 case 6:
585 GXColor1x16(colorIndex);
586 break;
587 case 7:
588 case 8:
589 case 9:
590 case 10:
591 case 11:
592 case 12:
593 GXColor1x8((u8)colorIndex);
594 break;
595 case 13:
596 GXColor4u8(ColorRGBA8[(colorIndex * 4)], ColorRGBA8[(colorIndex * 4) + 1],
597 ColorRGBA8[(colorIndex * 4) + 2], ColorRGBA8[(colorIndex * 4) + 3]);
598 break;
599 case 14:
600 GXColor1u32(((u32 *)ColorRGBA8)[colorIndex]);
601 break;
602 case 15:
603 GXColor3u8(ColorRGBA6[(colorIndex * 3)], ColorRGBA6[(colorIndex * 3) + 1],
604 ColorRGBA6[(colorIndex * 3) + 2]);
605 break;
606 case 16:
607 GXColor1u16(((u16 *)ColorRGBA4)[colorIndex]);
608 break;
609 case 17:
610 GXColor4u8(ColorRGBX8[(colorIndex * 4)], ColorRGBX8[(colorIndex * 4) + 1],
611 ColorRGBX8[(colorIndex * 4) + 2], ColorRGBX8[(colorIndex * 4) + 3]);
612 break;
613 case 18:
614 GXColor1u32(((u32 *)ColorRGBX8)[colorIndex]);
615 break;
616 case 19:
617 GXColor3u8(ColorRGB8[(colorIndex * 3)], ColorRGB8[(colorIndex * 3) + 1],
618 ColorRGB8[(colorIndex * 3) + 2]);
619 break;
620 case 20:
621 GXColor1u16(((u16 *)ColorRGB565)[colorIndex]);
622 break;
623 }
624
625 //texCoord section
626 switch(TexCoordControl)
627 {
628 case 0:
629 break;
630 case 1:
631 case 2:
632 case 3:
633 GXTexCoord1x16(texCoordIndex);
634 break;
635 case 4:
636 case 5:
637 case 6:
638 GXTexCoord1x8((u8)texCoordIndex);
639 break;
640 case 7:
641 GXTexCoord2f32(FloatTex[(texCoordIndex * 2)], FloatTex[(texCoordIndex * 2) + 1]);
642 break;
643 case 8:
644 GXTexCoord2u16(Tex16[(texCoordIndex * 2)], Tex16[(texCoordIndex * 2) + 1]);
645 break;
646 case 9:
647 GXTexCoord2u8(Tex8[(texCoordIndex * 2)], Tex8[(texCoordIndex * 2) + 1]);
648 break;
649 }
650
651 }
652