1 /*---------------------------------------------------------------------------*
2   Project:  Dolphin/Revolution gx demo
3   File:     tev-multi.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     tev-multi
15         multiple TEV stages and ordering test
16  *---------------------------------------------------------------------------*/
17 
18 
19 /*---------------------------------------------------------------------------*
20    Header files
21  *---------------------------------------------------------------------------*/
22 #include <math.h>
23 #include <demo.h>
24 
25 /*---------------------------------------------------------------------------*
26    Macro definitions
27  *---------------------------------------------------------------------------*/
28 #define TEX_WIDTH       64
29 #define TEX_HEIGHT      64
30 
31 #define NUM_TEVSTAGES   8
32 #define NUM_TEXCOORDS   8
33 #define NUM_TEXMAPS     8
34 #define NUM_CHANNELS    2
35 #define NUM_TEVMODES    5
36 #define NUM_COLORS      9
37 #define NUM_CTRLS       4
38 
39 #define CTRL_TM         0  // TEXMAP
40 #define CTRL_TC         1  // TEXCOORD
41 #define CTRL_CH         2  // CHANNEL
42 #define CTRL_MD         3  // TEVMODE
43 
44 // for display location
45 #define ALI_ROW(y)      (y * 96 + 64)
46 #define ALI_COL(x)      (x * 68 + 48)
47 
48 #define PI              3.14159265F
49 
50 /*---------------------------------------------------------------------------*
51    Structure definitions
52  *---------------------------------------------------------------------------*/
53 // for tev ordering and operation control
54 typedef u8 MyTevCtrlObj[NUM_CTRLS][NUM_TEVSTAGES];
55 
56 // for entire scene control
57 typedef struct
58 {
59     u32           curX;
60     u32           curY;
61     GXTexObj      texture[NUM_TEXMAPS];
62     Mtx           texgen[NUM_TEXCOORDS];
63     u8            color[NUM_CHANNELS];
64     MyTevCtrlObj  tev;
65     u32           counter;
66     u16           screenWd;
67     u16           screenHt;
68 } MySceneCtrlObj;
69 
70 /*---------------------------------------------------------------------------*
71    Forward references
72  *---------------------------------------------------------------------------*/
73 void        main               ( void );
74 static void DrawInit           ( MySceneCtrlObj* sc );
75 static void DrawTick           ( MySceneCtrlObj* sc );
76 static void AnimTick           ( MySceneCtrlObj* sc );
77 static void DrawQuad           ( void );
78 static void DrawLines          ( void );
79 static void DrawTexMapPanels   ( MyTevCtrlObj tevc );
80 static void DrawTexCoordPanels ( MyTevCtrlObj tevc );
81 static void DrawColorChanPanels( MyTevCtrlObj tevc );
82 static void DrawResultPanels   ( MyTevCtrlObj tevc );
83 static void DrawCaption        ( MySceneCtrlObj* sc );
84 static void AnimTexMtx         ( Mtx* tg, u32 cnt );
85 static void PrintIntro         ( void );
86 
87 /*---------------------------------------------------------------------------*
88    Model Data
89  *---------------------------------------------------------------------------*/
90 static s16 ModelVertices[8] ATTRIBUTE_ALIGN(32) =
91 {
92     // Used for drawing quads
93      0,  0, 64,  0,
94     64, 64,  0, 64,
95 };
96 
97 static s8 QuadTexCoords[2*4] ATTRIBUTE_ALIGN(32) =
98 {
99       0,   0,
100       1,   0,
101       1,   1,
102       0,   1
103 };
104 
105 /*---------------------------------------------------------------------------*
106    Constant color data for each channel
107  *---------------------------------------------------------------------------*/
108 static GXColor ColorTbl[NUM_COLORS] =
109 {
110     { 255, 255,   0, 255 }, // Yellow
111     {   0, 255, 255, 255 }, // Cyan
112     { 255,   0, 255, 255 }, // Magenta
113     { 255,   0,   0, 255 }, // Red
114     {   0, 255,   0, 255 }, // Green
115     {   0,   0, 255, 255 }, // Blue
116     {   0,   0,   0, 255 }, // Black
117     { 128, 128, 128, 255 }, // Gray
118     { 255, 255, 255, 255 }  // White
119 };
120 
121 /*---------------------------------------------------------------------------*
122    Other data tables
123  *---------------------------------------------------------------------------*/
124 static GXTevStageID StageIDTbl[NUM_TEVSTAGES] =
125 {
126     GX_TEVSTAGE0, GX_TEVSTAGE1, GX_TEVSTAGE2, GX_TEVSTAGE3,
127     GX_TEVSTAGE4, GX_TEVSTAGE5, GX_TEVSTAGE6, GX_TEVSTAGE7
128 };
129 
130 static GXTexCoordID CoordIDTbl[NUM_TEXCOORDS] =
131 {
132     GX_TEXCOORD0, GX_TEXCOORD1, GX_TEXCOORD2, GX_TEXCOORD3,
133     GX_TEXCOORD4, GX_TEXCOORD5, GX_TEXCOORD6, GX_TEXCOORD7
134 };
135 
136 static GXTexMtx MtxIDTbl[NUM_TEXCOORDS] =
137 {
138     GX_TEXMTX0, GX_TEXMTX1, GX_TEXMTX2, GX_TEXMTX3,
139     GX_TEXMTX4, GX_TEXMTX5, GX_TEXMTX6, GX_TEXMTX7
140 };
141 
142 static GXTexMapID MapIDTbl[NUM_TEXMAPS] =
143 {
144     GX_TEXMAP0, GX_TEXMAP1, GX_TEXMAP2, GX_TEXMAP3,
145     GX_TEXMAP4, GX_TEXMAP5, GX_TEXMAP6, GX_TEXMAP7
146 };
147 
148 static GXChannelID ChannelIDTbl[NUM_CHANNELS] =
149 {
150     GX_COLOR0A0, GX_COLOR1A1
151 };
152 
153 static GXTevMode TevModeTbl[NUM_TEVMODES] =
154 {
155     GX_PASSCLR, GX_REPLACE, GX_DECAL, GX_MODULATE, GX_BLEND
156 };
157 
158 // Max numbers of each control parameter
159 static u8 MaxTbl[NUM_CTRLS] =
160 {
161     NUM_TEXMAPS, NUM_TEXCOORDS, NUM_CHANNELS, NUM_TEVMODES
162 };
163 
164 /*---------------------------------------------------------------------------*
165    Strings data for captions
166  *---------------------------------------------------------------------------*/
167 static char* TevModeStr[NUM_TEVMODES] =
168 {
169     "PASSCLR", "REPLACE", "DECAL", "MODUL.", "BLEND"
170 };
171 
172 /*---------------------------------------------------------------------------*
173    Global variables
174  *---------------------------------------------------------------------------*/
175 static MySceneCtrlObj   SceneCtrl;        // scene control parameters
176 static TPLPalettePtr    MyTplObj = NULL;  // texture palette
177 
178 /*---------------------------------------------------------------------------*
179    Application main loop
180  *---------------------------------------------------------------------------*/
main(void)181 void main ( void )
182 {
183     DEMOInit(NULL);  // Init the OS, game pad, graphics and video.
184 
185     DrawInit(&SceneCtrl); // Initialize vertex formats, array pointers
186                           // and default scene settings.
187 
188     PrintIntro();    // Print demo directions
189 
190     while(!(DEMOPadGetButton(0) & PAD_BUTTON_MENU))
191     {
192         DEMOBeforeRender();
193         DrawTick(&SceneCtrl);    // Draw the model.
194         DEMODoneRender();
195         DEMOPadRead();           // Read controller
196         AnimTick(&SceneCtrl);    // Do animation
197     }
198 
199     OSHalt("End of demo");
200 }
201 
202 /*---------------------------------------------------------------------------*
203    Functions
204  *---------------------------------------------------------------------------*/
205 /*---------------------------------------------------------------------------*
206     Name:           DrawInit
207 
208     Description:    Initializes the vertex attribute format and sets up
209                     the array pointer for the indexed data.
210                     This function also initializes scene control parameters.
211 
212     Arguments:      sc : pointer to the structure of scene control parameters
213 
214     Returns:        none
215  *---------------------------------------------------------------------------*/
DrawInit(MySceneCtrlObj * sc)216 static void DrawInit( MySceneCtrlObj* sc )
217 {
218     TPLDescriptorPtr  tdp;
219     GXRenderModeObj*  rmode;
220     u32               i, n;
221 
222     // Vertex Attribute (VTXFMT0 is used by DEMOPuts library)
223     GXSetVtxAttrFmt(GX_VTXFMT1, GX_VA_POS, GX_POS_XY, GX_S16, 0);
224     GXSetVtxAttrFmt(GX_VTXFMT1, GX_VA_TEX0, GX_TEX_ST, GX_S8, 0);
225 
226     // Array pointers
227     GXSetArray(GX_VA_POS,  ModelVertices, 2 * sizeof(s16));
228     GXSetArray(GX_VA_TEX0, QuadTexCoords, 2 * sizeof(s8));
229 
230     // Get Screen Information defined in DEMOInit()
231     // This test is supposing height=480 (or near.)
232     rmode = DEMOGetRenderModeObj();
233     sc->screenWd = rmode->fbWidth;   // Screen Width
234     sc->screenHt = rmode->efbHeight; // Screen Height
235 
236     // Load TPL file and initialize texture objects
237     TPLGetPalette(&MyTplObj, "gxTests/tev-02.tpl");
238     n = MyTplObj->numDescriptors;
239     for ( i = 0 ; i < NUM_TEXMAPS ; ++i )
240     {
241         tdp = TPLGet(MyTplObj, i % n);
242 
243         GXInitTexObj(
244             &sc->texture[i],
245             tdp->textureHeader->data,
246             tdp->textureHeader->width,
247             tdp->textureHeader->height,
248             (GXTexFmt)tdp->textureHeader->format,
249             tdp->textureHeader->wrapS, // s
250             tdp->textureHeader->wrapT, // t
251             GX_FALSE ); // Mipmap
252 
253         GXInitTexObjLOD(
254             &sc->texture[i],
255             GX_LINEAR,
256             GX_LINEAR,
257             tdp->textureHeader->minLOD,
258             tdp->textureHeader->maxLOD,
259             tdp->textureHeader->LODBias,
260             GX_FALSE,
261             tdp->textureHeader->edgeLODEnable,
262             GX_ANISO_1 );
263     }
264     // Color channel
265     for ( i = 0 ; i < NUM_CHANNELS ; ++i )
266     {
267          GXSetChanCtrl(
268             ChannelIDTbl[i],
269             GX_DISABLE,    // Lighting off
270             GX_SRC_REG,    // Ambient source (N/A)
271             GX_SRC_REG,    // Material (Vertex color) source
272             GX_LIGHT_NULL, // Light mask (N/A)
273             GX_DF_NONE,    // Diffuse function (N/A)
274             GX_AF_NONE );  // Attenuation (N/A)
275     }
276 
277 
278     // Default scene control parameter settings
279 
280     // initialize all texgen matrices
281     for ( i = 0 ; i < NUM_TEXCOORDS ; ++i )
282     {
283         MTXIdentity(sc->texgen[i]);
284     }
285 
286     // color number for each channel
287     for ( i = 0 ; i < NUM_CHANNELS ; ++i )
288     {
289         sc->color[i] = (u8)i;
290     }
291 
292     // cursor
293     sc->curX = sc->curY = 0;
294 
295     // counter for animation
296     sc->counter = 0;
297 
298     // initialize all ordering and operation settings
299     for ( i = 0 ; i < NUM_TEVSTAGES ; ++i )
300     {
301         sc->tev[CTRL_TM][i] = (u8)i;                  // TEXMAP
302         sc->tev[CTRL_TC][i] = (u8)i;                  // TEXCOORD
303         sc->tev[CTRL_CH][i] = (u8)(i % NUM_CHANNELS); // CHANNEL
304         sc->tev[CTRL_MD][i] = 2;                      // MODE(OP) = DECAL
305     }
306 }
307 
308 /*---------------------------------------------------------------------------*
309     Name:           DrawTick
310 
311     Description:    Draw the model by using given scene parameters
312 
313     Arguments:      sc : pointer to the structure of scene control parameters
314 
315     Returns:        none
316  *---------------------------------------------------------------------------*/
DrawTick(MySceneCtrlObj * sc)317 static void DrawTick( MySceneCtrlObj* sc )
318 {
319     u32  i;
320 
321     // set projection to match screen space coordinate system
322     DEMOSetupScrnSpc(sc->screenWd, sc->screenHt, 100.0F);
323 
324     // set up Z mode (which actually doesn't matter)
325     GXSetZMode(GX_ENABLE, GX_ALWAYS, GX_ENABLE);
326 
327     // draw lines
328     DrawLines();
329 
330     // set up texcoord generators
331     for ( i = 0 ; i < NUM_TEXCOORDS ; ++i )
332     {
333         GXLoadTexMtxImm(sc->texgen[i], MtxIDTbl[i], GX_MTX2x4);
334         GXSetTexCoordGen(CoordIDTbl[i], GX_TG_MTX2x4, GX_TG_TEX0, MtxIDTbl[i]);
335     }
336 
337     // set up texmaps
338     for ( i = 0 ; i < NUM_TEXMAPS ; ++i )
339     {
340         GXLoadTexObj(&sc->texture[i], MapIDTbl[i]);
341     }
342 
343     // set up color channels
344     for ( i = 0 ; i < NUM_CHANNELS ; ++i )
345     {
346         GXSetChanMatColor(ChannelIDTbl[i], ColorTbl[sc->color[i]]);
347     }
348 
349     // draw first row (texmap panels)
350     DrawTexMapPanels(sc->tev);
351 
352     // draw second row (texcoord panels)
353     DrawTexCoordPanels(sc->tev);
354 
355     // draw third row (color channel panels)
356     DrawColorChanPanels(sc->tev);
357 
358     // draw final row (TEV combined result)
359     DrawResultPanels(sc->tev);
360 
361     // Captions
362     DrawCaption(sc);
363 }
364 
365 /*---------------------------------------------------------------------------*
366     Name:           AnimTick
367 
368     Description:    Changes scene parameters according to the pad status.
369 
370     Arguments:      sc : pointer to the structure of scene control parameters
371 
372     Returns:        none
373  *---------------------------------------------------------------------------*/
AnimTick(MySceneCtrlObj * sc)374 static void AnimTick( MySceneCtrlObj* sc )
375 {
376     u16  button, down, dirs;
377 
378     // Texgen matrices animation
379     AnimTexMtx(sc->texgen, sc->counter);
380 
381     // PAD
382     down   = DEMOPadGetButtonDown(0);
383     button = DEMOPadGetButton(0);
384     dirs   = DEMOPadGetDirsNew(0);
385 
386     // move cursor
387     if ( dirs & DEMO_STICK_RIGHT )
388     {
389         sc->curX += 1;
390     }
391     if ( dirs & DEMO_STICK_LEFT )
392     {
393         sc->curX += NUM_TEVSTAGES - 1;
394     }
395     if ( dirs & DEMO_STICK_DOWN )
396     {
397         sc->curY += 1;
398     }
399     if ( dirs & DEMO_STICK_UP )
400     {
401         sc->curY += 3;
402     }
403     sc->curX %= NUM_TEVSTAGES;
404     sc->curY %= 4;
405 
406     // change parameter
407     if ( down & PAD_BUTTON_X )
408     {
409         sc->tev[sc->curY][sc->curX] += 1;
410         sc->tev[sc->curY][sc->curX] %= MaxTbl[sc->curY];
411     }
412     if ( down & PAD_BUTTON_Y )
413     {
414         sc->tev[sc->curY][sc->curX] += MaxTbl[sc->curY] - 1;
415         sc->tev[sc->curY][sc->curX] %= MaxTbl[sc->curY];
416     }
417 
418     // select constant color for a channel
419     if ( ( down & PAD_BUTTON_B ) && sc->curY == CTRL_CH )
420     {
421         u8  ch = sc->tev[CTRL_CH][sc->curX];
422 
423         sc->color[ch] += 1;
424         sc->color[ch] %= NUM_COLORS;
425     }
426 
427     // freeze animation
428     if (!(button & PAD_BUTTON_A))
429     {
430         ++sc->counter;
431     }
432 }
433 
434 /*---------------------------------------------------------------------------*
435     Name:           DrawQuad
436 
437     Description:    Draw a textured quad.
438 
439     Arguments:      none
440 
441     Returns:        none
442  *---------------------------------------------------------------------------*/
DrawQuad(void)443 static void DrawQuad( void )
444 {
445     u8   i;
446 
447     // set vertex descriptor
448     GXClearVtxDesc();
449     GXSetVtxDesc(GX_VA_POS, GX_INDEX8);
450     GXSetVtxDesc(GX_VA_TEX0, GX_INDEX8);
451 
452     // draw the quad
453     GXBegin(GX_QUADS, GX_VTXFMT1, 4);
454         for ( i = 0 ; i < 4 ; ++i )
455         {
456             GXPosition1x8(i);
457             GXTexCoord1x8(i);
458         }
459     GXEnd();
460 }
461 
462 /*---------------------------------------------------------------------------*
463     Name:           DrawLines
464 
465     Description:    Draw lines
466 
467     Arguments:      none
468 
469     Returns:        none
470  *---------------------------------------------------------------------------*/
DrawLines(void)471 static void DrawLines( void )
472 {
473     GXColor lineColor = { 192, 192, 192, 0 };
474     u8   i;
475     Mtx  mv;
476 
477     MTXIdentity(mv);
478     GXLoadPosMtxImm(mv, GX_PNMTX0);
479 
480     // TEV settings
481     GXSetNumTevStages(1);
482     GXSetNumTexGens(0);
483     GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
484     GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
485 
486     GXSetNumChans(1);
487     GXSetChanMatColor(GX_COLOR0A0, lineColor);
488 
489     // set vertex descriptor
490     GXClearVtxDesc();
491     GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
492 
493     // draw lines
494     GXBegin(GX_LINES, GX_VTXFMT1, NUM_TEVSTAGES * 6);
495         for ( i = 0 ; i < NUM_TEVSTAGES ; ++i )
496         {
497             GXPosition2s16((s16)(ALI_COL(i)+32), ALI_ROW(0));
498             GXPosition2s16((s16)(ALI_COL(i)+32), ALI_ROW(3));
499 
500             GXPosition2s16((s16)(ALI_COL(i)+64), (s16)(ALI_ROW(3)+30));
501             GXPosition2s16((s16)(ALI_COL(i)+67), (s16)(ALI_ROW(3)+32));
502 
503             GXPosition2s16((s16)(ALI_COL(i)+64), (s16)(ALI_ROW(3)+34));
504             GXPosition2s16((s16)(ALI_COL(i)+67), (s16)(ALI_ROW(3)+32));
505         }
506     GXEnd();
507 }
508 
509 /*---------------------------------------------------------------------------*
510     Name:           DrawTexMapPanels
511 
512     Description:    Draw quads for the first row (TEXMAP)
513 
514     Arguments:      tevc : pointer for tev control status object
515 
516     Returns:        none
517  *---------------------------------------------------------------------------*/
DrawTexMapPanels(MyTevCtrlObj tevc)518 static void DrawTexMapPanels( MyTevCtrlObj tevc )
519 {
520     Mtx  mt;
521     u32  x;
522 
523     GXSetNumTevStages(1);
524     GXSetNumChans(0);
525     GXSetNumTexGens(1);
526     GXSetTevOp(GX_TEVSTAGE0, GX_REPLACE);
527 
528     for ( x = 0 ; x < NUM_TEVSTAGES ; ++x )
529     {
530         // Code for actual HW
531         GXSetTevOrder(
532             GX_TEVSTAGE0,
533             GX_TEXCOORD0,    // always identity
534             MapIDTbl[tevc[CTRL_TM][x]],
535             GX_COLOR_NULL );
536 
537         MTXTrans(mt, (f32)ALI_COL(x), (f32)ALI_ROW(0), 0);
538         GXLoadPosMtxImm(mt, GX_PNMTX0);
539         DrawQuad();
540     }
541 }
542 
543 /*---------------------------------------------------------------------------*
544     Name:           DrawTexCoordPanels
545 
546     Description:    Draw quads for the second row (TEXCOORD)
547 
548     Arguments:      tevc : pointer for tev control status object
549 
550     Returns:        none
551  *---------------------------------------------------------------------------*/
DrawTexCoordPanels(MyTevCtrlObj tevc)552 static void DrawTexCoordPanels( MyTevCtrlObj tevc )
553 {
554     Mtx  mt;
555     u32  x;
556 
557     GXSetNumTevStages(1);
558     GXSetNumChans(0);
559     GXSetNumTexGens(NUM_TEXCOORDS);
560     GXSetTevOp(GX_TEVSTAGE0, GX_REPLACE);
561 
562     for ( x = 0 ; x < NUM_TEVSTAGES ; ++x )
563     {
564         GXSetTevOrder(
565             GX_TEVSTAGE0,
566             CoordIDTbl[tevc[CTRL_TC][x]],
567             MapIDTbl[tevc[CTRL_TM][x]],
568             GX_COLOR_NULL );
569 
570         MTXTrans(mt, (f32)ALI_COL(x), (f32)ALI_ROW(1), 0);
571         GXLoadPosMtxImm(mt, GX_PNMTX0);
572         DrawQuad();
573     }
574 }
575 
576 /*---------------------------------------------------------------------------*
577     Name:           DrawColorChanPanels
578 
579     Description:    Draw quads for the third row (COLOR CHANNEL)
580 
581     Arguments:      tevc : pointer for tev control status object
582 
583     Returns:        none
584  *---------------------------------------------------------------------------*/
DrawColorChanPanels(MyTevCtrlObj tevc)585 static void DrawColorChanPanels( MyTevCtrlObj tevc )
586 {
587     Mtx  mt;
588     u32  x;
589 
590     GXSetNumTevStages(1);
591     GXSetNumChans(NUM_CHANNELS);
592     GXSetNumTexGens(0);
593     GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
594 
595     for ( x = 0 ; x < NUM_TEVSTAGES ; ++x )
596     {
597         GXSetTevOrder(
598             GX_TEVSTAGE0,
599             GX_TEXCOORD_NULL,
600             GX_TEXMAP_NULL,
601             ChannelIDTbl[tevc[CTRL_CH][x]] );
602 
603         MTXTrans(mt, (f32)ALI_COL(x), (f32)ALI_ROW(2), 0);
604         GXLoadPosMtxImm(mt, GX_PNMTX0);
605         DrawQuad();
606     }
607 }
608 
609 /*---------------------------------------------------------------------------*
610     Name:           DrawResultPanels
611 
612     Description:    Draw quads for the final row (TEV combined result)
613 
614     Arguments:      tevc : pointer for tev control status object
615 
616     Returns:        none
617  *---------------------------------------------------------------------------*/
DrawResultPanels(MyTevCtrlObj tevc)618 static void DrawResultPanels( MyTevCtrlObj tevc )
619 {
620     Mtx  mt;
621     u32  x;
622 
623     GXSetNumChans(NUM_CHANNELS);
624     GXSetNumTexGens(NUM_TEXCOORDS);
625 
626     for ( x = 0 ; x < NUM_TEVSTAGES ; ++x )
627     {
628         GXSetNumTevStages((u8)(x+1));
629         GXSetTevOrder(
630             StageIDTbl[x],
631             CoordIDTbl[tevc[CTRL_TC][x]],
632             MapIDTbl[tevc[CTRL_TM][x]],
633             ChannelIDTbl[tevc[CTRL_CH][x]] );
634         GXSetTevOp(StageIDTbl[x], TevModeTbl[tevc[CTRL_MD][x]]);
635 
636         MTXTrans(mt, (f32)ALI_COL(x), (f32)ALI_ROW(3), 0);
637         GXLoadPosMtxImm(mt, GX_PNMTX0);
638         DrawQuad();
639     }
640 }
641 
642 /*---------------------------------------------------------------------------*
643     Name:           DrawCaption
644 
645     Description:    Draw captions
646 
647     Arguments:      sc : pointer to the structure of scene control parameters
648 
649     Returns:        none
650  *---------------------------------------------------------------------------*/
DrawCaption(MySceneCtrlObj * sc)651 static void DrawCaption( MySceneCtrlObj* sc )
652 {
653     u32  i;
654     s16  x;
655 
656     DEMOInitCaption(DM_FT_OPQ, sc->screenWd, sc->screenHt);
657 
658     for ( i = 0 ; i < NUM_TEVSTAGES ; ++i )
659     {
660         x = (s16)ALI_COL(i);
661         DEMOPrintf(x, (s16)(ALI_ROW(0)-16), 0, "[STAGE%d]", i);
662         x += 8;
663         DEMOPrintf(x, (s16)(ALI_ROW(0)+72), 0, "TEXMAP%d", sc->tev[CTRL_TM][i]);
664         DEMOPrintf(x, (s16)(ALI_ROW(1)+72), 0, "TCOORD%d", sc->tev[CTRL_TC][i]);
665         DEMOPrintf(x, (s16)(ALI_ROW(2)+72), 0, "COLOR%d", sc->tev[CTRL_CH][i]);
666         DEMOPuts(x, (s16)(ALI_ROW(3)+72), 0, TevModeStr[sc->tev[CTRL_MD][i]]);
667     }
668 
669     // Cursor
670     DEMOPrintf(
671         (s16)ALI_COL(sc->curX),
672         (s16)(ALI_ROW(sc->curY) + 72),
673         0,
674         "%c",
675         0x7F );
676 }
677 
678 /*---------------------------------------------------------------------------*
679     Name:           AnimTexMtx
680 
681     Description:    Generates animating texcoord generator matrices.
682 
683     Arguments:      tg  : pointer to texgen matrices array
684                     cnt : counter for animation
685 
686     Returns:        none
687  *---------------------------------------------------------------------------*/
AnimTexMtx(Mtx * tg,u32 cnt)688 static void AnimTexMtx( Mtx* tg, u32 cnt )
689 {
690     Mtx  m0, m1, m2;
691     f32  st, ss;
692 
693     // Matrix 0 is always identity.
694     MTXIdentity(tg[0]);
695 
696     // Matrix 1
697     st = (f32)( cnt % 200 ) / 200.0F;
698     MTXTrans(tg[1], st, st, 0);
699 
700     // Matrix 2
701     st = (f32)( cnt % 90 ) * 4.0F;
702     MTXTrans(m0, -0.5F, -0.5F, 0.0F);
703     MTXRotDeg(m1, 'z', st);
704     MTXConcat(m1, m0, m2);
705     MTXTrans(m0, 0.5F, 0.5F, 0.0F);
706     MTXConcat(m0, m2, tg[2]);
707 
708     // Matrix 3
709     st = (f32)( cnt % 200 ) / 200.0F;
710     MTXTrans(m0, st, 0.0F, 0.0F);
711     MTXScale(m1, -1.0F, 2.0F, 1.0F);
712     MTXConcat(m0, m1, tg[3]);
713 
714     // Matrix 4
715     st = (f32)( cnt % 360 ) * PI / 180.0F;
716     ss = ( sinf(st) + 1.0F ) * 1.5F + 1.0F;
717     MTXScale(tg[4], ss, ss, 1.0F);
718 
719     // Matrix 5
720     st = (f32)( cnt % 180 ) * PI / 90.0F;
721     ss = ( sinf(st) + 1.0F ) * 2.0F + 0.5F;
722     MTXRotDeg(m1, 'z', 45);
723     MTXScale(m2, 1.0F, ss, 1.0F);
724     MTXConcat(m2, m1, m0);
725     MTXConcat(m1, m0, m2);
726     MTXTrans(m0, 0.5F, 0.5F, 0.0F);
727     MTXConcat(m0, m2, tg[5]);
728 
729     // Matrix 6
730     st = (f32)( cnt % 360 );
731     MTXTrans(m0, -1.0F, -1.0F, 0.0F);
732     MTXScale(m1, 2.0F, 2.0F, 0.0F);
733     MTXConcat(m1, m0, m2);
734     MTXRotDeg(m1, 'z', -st);
735     MTXConcat(m1, m2, m0);
736     MTXTrans(m2, 1.0F, 1.0F, 0.0F);
737     MTXConcat(m2, m0, tg[6]);
738 
739     // Matrix 7
740     st = (f32)( cnt % 360 );
741     MTXRotDeg(m1, 'z', st);
742     st = st * PI / 180.0F;
743     ss = ( sinf(st) + 1.5F ) * 0.5F;
744     MTXScale(m0, ss, 1.0F, 1.0F);
745     MTXConcat(m1, m0, m2);
746     MTXTrans(m0, ss, -ss, 0.0F);
747     MTXConcat(m0, m2, tg[7]);
748 }
749 
750 /*---------------------------------------------------------------------------*
751     Name:           PrintIntro
752 
753     Description:    Prints the directions on how to use this demo.
754 
755     Arguments:      none
756 
757     Returns:        none
758  *---------------------------------------------------------------------------*/
PrintIntro(void)759 static void PrintIntro( void )
760 {
761     OSReport("\n\n");
762     OSReport("************************************************\n");
763     OSReport("tev-multi: multiple TEV stages test\n");
764     OSReport("************************************************\n");
765     OSReport("to quit hit the start button\n");
766     OSReport("\n");
767     OSReport("Main Stick  : move the cursor\n");
768     OSReport("X/Y Buttons : change parameter\n");
769     OSReport("A Button    : freeze animation\n");
770     OSReport("B Button    : change channel color (if selected)\n");
771     OSReport("************************************************\n\n");
772 }
773 
774 /*============================================================================*/
775