1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/3D_Pol_Simple
3 File: main.c
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-17#$
14 $Rev: 8556 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 //---------------------------------------------------------------------------
19 // A simple example:
20 //
21 // Simply display a rotating cube without lights and vertex colors.
22 //---------------------------------------------------------------------------
23
24 #ifdef SDK_TWL
25 #include <twl.h>
26 #else
27 #include <nitro.h>
28 #endif
29 #include "DEMO.h"
30
31 s16 gCubeGeometry[3 * 8] = {
32 FX16_ONE, FX16_ONE, FX16_ONE,
33 FX16_ONE, FX16_ONE, -FX16_ONE,
34 FX16_ONE, -FX16_ONE, FX16_ONE,
35 FX16_ONE, -FX16_ONE, -FX16_ONE,
36 -FX16_ONE, FX16_ONE, FX16_ONE,
37 -FX16_ONE, FX16_ONE, -FX16_ONE,
38 -FX16_ONE, -FX16_ONE, FX16_ONE,
39 -FX16_ONE, -FX16_ONE, -FX16_ONE
40 };
41
42
vtx(int idx)43 static void vtx(int idx)
44 {
45 G3_Vtx(gCubeGeometry[idx * 3], gCubeGeometry[idx * 3 + 1], gCubeGeometry[idx * 3 + 2]);
46 }
47
quad(int idx0,int idx1,int idx2,int idx3)48 static void quad(int idx0, int idx1, int idx2, int idx3)
49 {
50 vtx(idx0);
51 vtx(idx1);
52 vtx(idx2);
53 vtx(idx3);
54 }
55
56 #ifdef SDK_TWL
TwlMain(void)57 void TwlMain(void)
58 #else
59 void NitroMain(void)
60 #endif
61 {
62 u16 Rotate = 0; // for rotating cubes(0-65535)
63
64 //---------------------------------------------------------------------------
65 // Initialize:
66 // They enable IRQ interrupts, initialize VRAM, and set BG #0 for 3D mode.
67 //---------------------------------------------------------------------------
68 DEMOInitCommon();
69 DEMOInitVRAM();
70 DEMOInitDisplay3D();
71
72 DEMOStartDisplay();
73 while (1)
74 {
75 G3X_Reset();
76 Rotate += 256;
77
78 //---------------------------------------------------------------------------
79 // Set up a camera matrix
80 //---------------------------------------------------------------------------
81 {
82 VecFx32 Eye = { 0, 0, FX32_ONE }; // Eye position
83 VecFx32 at = { 0, 0, 0 }; // Viewpoint
84 VecFx32 vUp = { 0, FX32_ONE, 0 }; // Up
85
86 // Matrix mode is changed to GX_MTXMODE_POSITION_VECTOR internally,
87 // and the camera matrix is loaded to the current matrix.
88 G3_LookAt(&Eye, &vUp, &at, NULL);
89 }
90
91 G3_PushMtx();
92
93 {
94 fx16 s = FX_SinIdx(Rotate);
95 fx16 c = FX_CosIdx(Rotate);
96
97 G3_Translate(0, 0, -5 * FX32_ONE);
98
99 G3_RotX(s, c);
100 G3_RotY(s, c);
101 G3_RotZ(s, c);
102
103 // The current matrix is Rz * Ry * Rx * Trns * Cam.
104 }
105
106 G3_MaterialColorDiffAmb(GX_RGB(31, 31, 31), // diffuse
107 GX_RGB(16, 16, 16), // ambient
108 TRUE // use diffuse as vtx color if TRUE
109 );
110
111 G3_MaterialColorSpecEmi(GX_RGB(16, 16, 16), // specular
112 GX_RGB(0, 0, 0), // emission
113 FALSE // use shininess table if TRUE
114 );
115
116 G3_PolygonAttr(GX_LIGHTMASK_NONE, // no lights
117 GX_POLYGONMODE_MODULATE, // modulation mode
118 GX_CULL_BACK, // cull back
119 0, // polygon ID(0 - 63)
120 31, // alpha(0 - 31)
121 0 // OR of GXPolygonAttrMisc's value
122 );
123
124 G3_Begin(GX_BEGIN_QUADS);
125
126 {
127 quad(2, 0, 4, 6);
128 quad(7, 5, 1, 3);
129 quad(6, 4, 5, 7);
130 quad(3, 1, 0, 2);
131 quad(5, 4, 0, 1);
132 quad(6, 7, 3, 2);
133 }
134
135 G3_End();
136
137 G3_PopMtx(1);
138
139 // swapping the polygon list RAM, the vertex RAM, etc.
140 G3_SwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_W);
141
142 #ifdef SDK_AUTOTEST
143 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
144 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
145 EXT_TestScreenShot(100, 0xF34A239D);
146 EXT_TestTickCounter();
147 #endif //SDK_AUTOTEST
148
149 OS_WaitVBlankIntr(); // Waiting the end of VBlank interrupt
150 }
151 }
152
153 //---------------------------------------------------------------------------
154 // VBlank interrupt function:
155 //
156 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
157 // OS_EnableIrqMask selects IRQ interrupts to enable, and
158 // OS_EnableIrq enables IRQ interrupts.
159 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
160 //---------------------------------------------------------------------------
VBlankIntr(void)161 void VBlankIntr(void)
162 {
163 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt
164 }
165