Reduce variable scope

This commit is contained in:
Crayon2000 2022-11-23 23:35:53 -05:00
parent 95c915f5f8
commit 7e35d7b62d
5 changed files with 114 additions and 134 deletions

View file

@ -26,9 +26,9 @@ THE SOFTWARE.
// User should not directly modify these
Mtx _GRR_view; // Should be static as soon as all light functions needing this var will be in this file ;)
static guVector _GRR_cam = {0.0F, 0.0F, 0.0F},
_GRR_up = {0.0F, 1.0F, 0.0F},
_GRR_look = {0.0F, 0.0F, -100.0F};
static guVector _GRR_cam = {0.0f, 0.0f, 0.0f},
_GRR_up = {0.0f, 1.0f, 0.0f},
_GRR_look = {0.0f, 0.0f, -100.0f};
static guVector _GRRaxisx = (guVector){1, 0, 0}; // DO NOT MODIFY!!!
static guVector _GRRaxisy = (guVector){0, 1, 0}; // Even at runtime
static guVector _GRRaxisz = (guVector){0, 0, 1}; // NOT ever!
@ -134,7 +134,7 @@ void GRRLIB_2dMode() {
GX_LoadProjectionMtx(m, GX_ORTHOGRAPHIC);
guMtxIdentity(view);
guMtxTransApply(view, view, 0, 0, -100.0F);
guMtxTransApply(view, view, 0, 0, -100.0f);
GX_LoadPosMtxImm(view, GX_PNMTX0);
GX_ClearVtxDesc();

View file

@ -34,12 +34,12 @@ THE SOFTWARE.
#define DEFAULT_FIFO_SIZE (256 * 1024) /**< GX fifo buffer size. */
GRRLIB_drawSettings GRRLIB_Settings;
Mtx GXmodelView2D;
GRRLIB_drawSettings GRRLIB_Settings;
Mtx GXmodelView2D;
static void *gp_fifo = NULL;
static void *gp_fifo = NULL;
static bool is_setup = false; // To control entry and exit
static bool is_setup = false; // To control entry and exit
/**
* Initialize GRRLIB. Call this once at the beginning your code.
@ -176,7 +176,7 @@ int GRRLIB_Init (void) {
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
guMtxIdentity(GXmodelView2D);
guMtxTransApply(GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -100.0F);
guMtxTransApply(GXmodelView2D, GXmodelView2D, 0.0f, 0.0f, -100.0f);
GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0);
guOrtho(perspective, 0.0f, rmode->efbHeight, 0.0f, rmode->fbWidth, 0.0f, 1000.0f);
@ -219,13 +219,11 @@ int GRRLIB_Init (void) {
* and only if the setup function has been called.
*/
void GRRLIB_Exit (void) {
static bool done = false;
static bool done = false;
if (done == true || is_setup == false) {
return;
}
else {
done = true;
}
done = true;
// Allow write access to the full screen
GX_SetClipMode( GX_CLIP_DISABLE );
@ -233,8 +231,10 @@ void GRRLIB_Exit (void) {
// We empty both frame buffers on our way out
// otherwise dead frames are sometimes seen when starting the next app
GRRLIB_FillScreen( 0x000000FF ); GRRLIB_Render();
GRRLIB_FillScreen( 0x000000FF ); GRRLIB_Render();
GRRLIB_FillScreen( 0x000000FF );
GRRLIB_Render();
GRRLIB_FillScreen( 0x000000FF );
GRRLIB_Render();
// Shut down the GX engine
GX_DrawDone();

View file

@ -52,9 +52,9 @@ int main() {
GRRLIB_3dMode(0.1, 1000, 45, false, true);
if(demo==0) {
if(demo == 0) {
/////////////////// DEFINE A DIFFUSE LIGHT /////////////////////////////////////////////
guVector l0pos={0.0f,20.0f,0.0f};
guVector l0pos={0.0f, 20.0f, 0.0f};
guVecMultiply(_GRR_view, &l0pos, &l0pos);
GX_InitLightPos(&MyLight0, l0pos.x, l0pos.y, l0pos.z);
GX_InitLightColor(&MyLight0, (GXColor) { 0xFF, 0x00, 0x00, 0xFF });
@ -80,9 +80,9 @@ int main() {
GRRLIB_2dMode();
GRRLIB_Printf(20, 30, tex_font, 0xFFFFFFFF, 1, "Simple Demo 1 Diffuse Light Source");
}
else if(demo==1) {
else if(demo == 1) {
/////////////////// DEFINE 2 DIFFUSE LIGHTS /////////////////////////////////////////////
guVector l0pos={0.0f,20.0f,0.0f};
guVector l0pos={0.0f, 20.0f, 0.0f};
guVecMultiply(_GRR_view, &l0pos, &l0pos);
GX_InitLightPos(&MyLight0, l0pos.x, l0pos.y, l0pos.z);
GX_InitLightColor(&MyLight0, (GXColor) { 0x00, 0xFF, 0x00, 0xFF });
@ -116,13 +116,13 @@ int main() {
GRRLIB_2dMode();
GRRLIB_Printf(20, 30, tex_font, 0xFFFFFFFF, 1, "Simple Demo 2 Diffuse Light Sources");
}
else if(demo==2) {
else if(demo == 2) {
/////////////////// DEFINE A SPECULAR LIGHT /////////////////////////////////////////////
guVector l0dir={0.0f,0.0f,0.0f};
guVector l0dir={0.0f, 0.0f, 0.0f};
GX_InitSpecularDir(&MyLight0, l0dir.x,l0dir.y,l0dir.z);
GX_InitLightShininess(&MyLight0, 20); // between 4 and 255 !!!
GX_InitLightColor(&MyLight0, (GXColor){0xFF,0xFF,0xFF,0xFF});
GX_InitLightColor(&MyLight0, (GXColor){0xFF, 0xFF, 0xFF,0xFF});
GX_LoadLightObj(&MyLight0, GX_LIGHT0);
/////////////////////// Turn light ON ////////////////////////////////////////////////
@ -143,8 +143,8 @@ int main() {
GRRLIB_ObjectView(0,0,0, a,a*2,a*3, 1.0f,1.0f,1.0f);
GX_SetChanAmbColor(GX_COLOR0, (GXColor) { 0xFF, 0xFF, 0xFF, 0xFF});
GX_SetChanMatColor(GX_COLOR0, (GXColor) { 0x00, 0x00, 0x00, 0xFF});
GX_SetChanAmbColor(GX_COLOR1, (GXColor){0x00,0x00,0x00,0x00});
GX_SetChanMatColor(GX_COLOR1, (GXColor){0xFF,0xFF,0xFF,0xFF});
GX_SetChanAmbColor(GX_COLOR1, (GXColor){0x00, 0x00, 0x00, 0x00});
GX_SetChanMatColor(GX_COLOR1, (GXColor){0xFF, 0xFF, 0xFF, 0xFF});
GRRLIB_DrawTorus(0.6f, 2.0f, 60, 60, true, 0xFFFFFFFF);
a+=0.8f;
@ -155,13 +155,13 @@ int main() {
GRRLIB_2dMode();
GRRLIB_Printf(20, 30, tex_font, 0xFFFFFFFF, 1, "Simple Demo 1 Specular Source with shininess = 20");
}
else if(demo==3) {
else if(demo == 3) {
/////////////////// DEFINE A SPECULAR LIGHT /////////////////////////////////////////////
guVector l0dir={0.0f,0.0f,0.0f};
guVector l0dir={0.0f, 0.0f, 0.0f};
GX_InitSpecularDir(&MyLight0, l0dir.x,l0dir.y,l0dir.z);
GX_InitLightShininess(&MyLight0, 200); // between 4 and 255 !!!
GX_InitLightColor(&MyLight0, (GXColor){0xFF,0xFF,0xFF,0xFF});
GX_InitLightColor(&MyLight0, (GXColor){0xFF, 0xFF, 0xFF, 0xFF});
GX_LoadLightObj(&MyLight0, GX_LIGHT0);
/////////////////////// Turn light ON ////////////////////////////////////////////////
@ -182,9 +182,9 @@ int main() {
GRRLIB_ObjectView(0,0,0, a,a*2,a*3, 1.0f,1.0f,1.0f);
GX_SetChanAmbColor(GX_COLOR0, (GXColor) { 0xFF, 0xFF, 0xFF, 0xFF});
GX_SetChanMatColor(GX_COLOR0, (GXColor) { 0x00, 0x00, 0x00, 0xFF});
GX_SetChanAmbColor(GX_COLOR1, (GXColor){0x00,0x00,0x00,0x00});
GX_SetChanMatColor(GX_COLOR1, (GXColor){0xFF,0xFF,0xFF,0xFF});
GRRLIB_DrawTorus(0.6f, 2.0f, 60, 60,true, 0xFFFFFFFF);
GX_SetChanAmbColor(GX_COLOR1, (GXColor){0x00, 0x00, 0x00, 0x00});
GX_SetChanMatColor(GX_COLOR1, (GXColor){0xFF, 0xFF, 0xFF, 0xFF});
GRRLIB_DrawTorus(0.6f, 2.0f, 60, 60, true, 0xFFFFFFFF);
a+=0.8f;
//////////////////////////// Turn light off and Write demo name
@ -194,9 +194,9 @@ int main() {
GRRLIB_2dMode();
GRRLIB_Printf(20, 30, tex_font, 0xFFFFFFFF, 1, "Simple Demo 1 Specular Source with shininess = 200");
}
else if(demo==4) {
else if(demo == 4) {
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_NRM, GX_TEXMTX0); // We say we use the Normal coord to map the texture (since there is no textcoord with this torus)
guLightFrustum(mv, 1.0F, -1.0F, 1.0F, -1.0F, 1.0F, 0.5F, 0.5F, 0.5F, 0.5F); // we are projecting the texture like a light (ie : videoprojector))
guLightFrustum(mv, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 0.5f); // we are projecting the texture like a light (ie : videoprojector))
guMtxScale(mr, -2.8f, -2.8f, 0.0f); //here is a little scaling to fit the torus
guMtxConcat(mr, mv, mv);
@ -216,9 +216,9 @@ int main() {
GRRLIB_2dMode();
GRRLIB_Printf(20, 30, tex_font, 0xFFFFFFFF, 1, "Simple Demo Mapping Using textgen from normal coord");
}
else if(demo==5) {
else if(demo == 5) {
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_NRM, GX_TEXMTX0); // We say we use the Normal coord to map the texture (since there is no textcoord with this torus)
guLightFrustum(mv, 1.0F, -1.0F, 1.0F, -1.0F, 1.0F, 0.5F, 0.5F, 0.5F, 0.5F); // we are projecting the texture like a light (ie : videoprojector))
guLightFrustum(mv, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 0.5f); // we are projecting the texture like a light (ie : videoprojector))
guMtxRotDeg(rx, 'X', a); // Here i rotate the texture
guMtxRotDeg(ry, 'Y', a*2); // in the inverse way
guMtxRotDeg(rz, 'Z', a*3); // of the

View file

@ -10,71 +10,61 @@
int main() {
int offset1, offset2, offset3, offset4;
int periode1, periode2, periode3, periode4;
int length1, length2, length3, length4;
int amp1, amp2, amp3, amp4;
int origine1, origine2, origine3, origine4;
int adc1, adc2, adc3, adc4;
float siny1, siny2, siny3, siny4;
int x;
float pas1, pas2, pas3, pas4;
// Initialise the Graphics & Video subsystem
GRRLIB_Init();
// Initialise the Wiimotes
// Initialise the Wii Remotes
WPAD_Init();
adc1=0;
offset1=0;
origine1=0;
length1=1280;
amp1=100;
periode1=1;
pas1=(periode1*360.0F)/length1;
siny1 = offset1*pas1;
const int adc1=0;
const int offset1=0;
const int origin1=0;
const int length1=1280;
const int amp1=100;
const int period1=1;
const float pas1=(period1*360.0f)/length1;
float siny1 = offset1*pas1;
adc2=1;
offset2=0;
origine2=0;
length2=1280;
amp2=40;
periode2=2;
pas2=(periode2*360.0F)/length2;
siny2 = offset2*pas2;
const int adc2=1;
const int offset2=0;
const int origin2=0;
const int length2=1280;
const int amp2=40;
const int period2=2;
const float pas2=(period2*360.0f)/length2;
float siny2 = offset2*pas2;
adc3=-3;
offset3=0;
origine3=0;
length3=1280;
amp3=30;
periode3=1;
pas3=(periode3*360.0F)/length3;
siny3 = offset3*pas3;
const int adc3=-3;
const int offset3=0;
const int origin3=0;
const int length3=1280;
const int amp3=30;
const int period3=1;
const float pas3=(period3*360.0f)/length3;
float siny3 = offset3*pas3;
adc4=-7;
offset4=0;
origine4=0;
length4=1280;
amp4=70;
periode4=1;
pas4=(periode4*360.0F)/length4;
siny4 = offset4*pas4;
const int adc4=-7;
const int offset4=0;
const int origin4=0;
const int length4=1280;
const int amp4=70;
const int period4=1;
const float pas4=(period4*360.0f)/length4;
float siny4 = offset4*pas4;
while (1) {
GRRLIB_FillScreen(0x000000FF);
WPAD_ScanPads(); // Scan the Wiimotes
WPAD_ScanPads(); // Scan the Wii Remotes
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) break;
float old1=siny1;
float old2=siny2;
float old3=siny3;
float old4=siny4;
const float old1=siny1;
const float old2=siny2;
const float old3=siny3;
const float old4=siny4;
for (x=0; x<=640; x++) {
for (u16 x=0; x<=640; x++) {
siny1+=pas1;
siny2+=pas2;
siny3+=pas3;
@ -83,11 +73,11 @@ int main() {
GX_Begin(GX_LINES, GX_VTXFMT0, 2);
GX_Position3f32(x, 0, 0);
GX_Color1u32(0x000000FF);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origine1)+(sin(DegToRad(siny2))*amp2+origine2)+(sin(DegToRad(siny3))*amp3+origine3)+(sin(DegToRad(siny4))*amp4+origine4)+240, 0);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origin1)+(sin(DegToRad(siny2))*amp2+origin2)+(sin(DegToRad(siny3))*amp3+origin3)+(sin(DegToRad(siny4))*amp4+origin4)+240, 0);
GX_Color1u32(0xFF00007F);
GX_End();
GX_Begin(GX_LINES, GX_VTXFMT0, 2);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origine1)+(sin(DegToRad(siny2))*amp2+origine2)+(sin(DegToRad(siny3))*amp3+origine3)+(sin(DegToRad(siny4))*amp4+origine4)+240, 0);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origin1)+(sin(DegToRad(siny2))*amp2+origin2)+(sin(DegToRad(siny3))*amp3+origin3)+(sin(DegToRad(siny4))*amp4+origin4)+240, 0);
GX_Color1u32(0xFF00007F);
GX_Position3f32(x, 480, 0);
GX_Color1u32(0x000000FF);

View file

@ -10,16 +10,6 @@
int main() {
int offset1, offset2, offset3, offset4;
int periode1, periode2, periode3, periode4;
int length1, length2, length3, length4;
int amp1, amp2, amp3, amp4;
int origine1, origine2, origine3, origine4;
int adc1, adc2, adc3, adc4;
float siny1, siny2, siny3, siny4;
int x;
float pas1, pas2, pas3, pas4;
// Initialise the Graphics & Video subsystem
GRRLIB_Init();
@ -27,54 +17,54 @@ int main() {
PAD_Init();
adc1=0;
offset1=0;
origine1=0;
length1=1280;
amp1=100;
periode1=1;
pas1=(periode1*360.0F)/length1;
siny1 = offset1*pas1;
const int adc1=0;
const int offset1=0;
const int origin1=0;
const int length1=1280;
const int amp1=100;
const int period1=1;
const float pas1=(period1*360.0f)/length1;
float siny1 = offset1*pas1;
adc2=1;
offset2=0;
origine2=0;
length2=1280;
amp2=40;
periode2=2;
pas2=(periode2*360.0F)/length2;
siny2 = offset2*pas2;
const int adc2=1;
const int offset2=0;
const int origin2=0;
const int length2=1280;
const int amp2=40;
const int period2=2;
const float pas2=(period2*360.0f)/length2;
float siny2 = offset2*pas2;
adc3=-3;
offset3=0;
origine3=0;
length3=1280;
amp3=30;
periode3=1;
pas3=(periode3*360.0F)/length3;
siny3 = offset3*pas3;
const int adc3=-3;
const int offset3=0;
const int origin3=0;
const int length3=1280;
const int amp3=30;
const int period3=1;
const float pas3=(period3*360.0f)/length3;
float siny3 = offset3*pas3;
adc4=-7;
offset4=0;
origine4=0;
length4=1280;
amp4=70;
periode4=1;
pas4=(periode4*360.0F)/length4;
siny4 = offset4*pas4;
const int adc4=-7;
const int offset4=0;
const int origin4=0;
const int length4=1280;
const int amp4=70;
const int period4=1;
const float pas4=(period4*360.0f)/length4;
float siny4 = offset4*pas4;
while (1) {
GRRLIB_FillScreen(0x000000FF);
PAD_ScanPads(); // Scan the GameCube controllers
if (PAD_ButtonsDown(0) & PAD_BUTTON_START) break;
float old1=siny1;
float old2=siny2;
float old3=siny3;
float old4=siny4;
const float old1=siny1;
const float old2=siny2;
const float old3=siny3;
const float old4=siny4;
for (x=0; x<=640; x++) {
for (u16 x=0; x<=640; x++) {
siny1+=pas1;
siny2+=pas2;
siny3+=pas3;
@ -83,11 +73,11 @@ int main() {
GX_Begin(GX_LINES, GX_VTXFMT0, 2);
GX_Position3f32(x, 0, 0);
GX_Color1u32(0x000000FF);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origine1)+(sin(DegToRad(siny2))*amp2+origine2)+(sin(DegToRad(siny3))*amp3+origine3)+(sin(DegToRad(siny4))*amp4+origine4)+240, 0);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origin1)+(sin(DegToRad(siny2))*amp2+origin2)+(sin(DegToRad(siny3))*amp3+origin3)+(sin(DegToRad(siny4))*amp4+origin4)+240, 0);
GX_Color1u32(0xFF00007F);
GX_End();
GX_Begin(GX_LINES, GX_VTXFMT0, 2);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origine1)+(sin(DegToRad(siny2))*amp2+origine2)+(sin(DegToRad(siny3))*amp3+origine3)+(sin(DegToRad(siny4))*amp4+origine4)+240, 0);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origin1)+(sin(DegToRad(siny2))*amp2+origin2)+(sin(DegToRad(siny3))*amp3+origin3)+(sin(DegToRad(siny4))*amp4+origin4)+240, 0);
GX_Color1u32(0xFF00007F);
GX_Position3f32(x, 480, 0);
GX_Color1u32(0x000000FF);