diff --git a/GRRLIB/GRRLIB/GRRLIB_3D.c b/GRRLIB/GRRLIB/GRRLIB_3D.c index 48df284..172e39d 100644 --- a/GRRLIB/GRRLIB/GRRLIB_3D.c +++ b/GRRLIB/GRRLIB/GRRLIB_3D.c @@ -145,7 +145,6 @@ void GRRLIB_2dMode() { GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GRRLIB_Settings.lights = 0; - } /** @@ -218,6 +217,7 @@ void GRRLIB_SetTexture(GRRLIB_texImg *tex, bool rep) { * @param nsides Number of faces per ring. * @param rings Number of rings. * @param filled Wired or not. + * @param col Color of the torus. */ void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col) { int i, j; @@ -248,10 +248,10 @@ void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col) GX_Position3f32(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); GX_Normal3f32(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); - GX_Color1u32(col); + GX_Color1u32(col); GX_Position3f32(cosTheta * dist, -sinTheta * dist, r * sinPhi); GX_Normal3f32(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); - GX_Color1u32(col); + GX_Color1u32(col); } GX_End(); theta = theta1; @@ -266,6 +266,7 @@ void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col) * @param lats Number of lattitudes. * @param longs Number of longitutes. * @param filled Wired or not. + * @param col Color of the sphere. */ void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col) { int i, j; @@ -290,10 +291,10 @@ void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col) { GX_Position3f32(x * zr0 * r, y * zr0 * r, z0 * r); GX_Normal3f32(x * zr0 * r, y * zr0 * r, z0 * r); - GX_Color1u32(col); + GX_Color1u32(col); GX_Position3f32(x * zr1 * r, y * zr1 * r, z1 * r); GX_Normal3f32(x * zr1 * r, y * zr1 * r, z1 * r); - GX_Color1u32(col); + GX_Color1u32(col); } GX_End(); } @@ -303,6 +304,7 @@ void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col) { * Draw a cube (with normal). * @param size Size of the cube edge. * @param filled Wired or not. + * @param col Color of the cube. */ void GRRLIB_DrawCube(f32 size, bool filled, u32 col) { static f32 n[6][3] = @@ -363,6 +365,7 @@ void GRRLIB_DrawCube(f32 size, bool filled, u32 col) { * @param h High of the cylinder. * @param d Dencity of slice. * @param filled Wired or not. + * @param col Color of the cylinder. */ void GRRLIB_DrawCylinder(f32 r, f32 h, int d, bool filled, u32 col) { int i; @@ -408,43 +411,44 @@ void GRRLIB_DrawCylinder(f32 r, f32 h, int d, bool filled, u32 col) { } /** - * Set Ambiant Color + * Set ambient color. + * When no diffuse ligth is shinig on a object, the color is equal to ambient color. + * @param ambientcolor Ambient color in RGBA format. */ -void GRRLIB_SetLightAmbiant(u32 ambiantcolor){ - GX_SetChanAmbColor(GX_COLOR0A0, (GXColor) { R(ambiantcolor), G(ambiantcolor), B(ambiantcolor), 0xFF}); +void GRRLIB_SetLightAmbient(u32 ambientcolor) { + GX_SetChanAmbColor(GX_COLOR0A0, (GXColor) { R(ambientcolor), G(ambientcolor), B(ambientcolor), 0xFF}); } /** - * Set Diffuse Light Parameters - * @param num number of the light - * @param pos position of the diffuse light (x/y/z) - * @param distattn distance attenuation - * @param brightness Brightness of the light - * @param lightcolor color of the light - * @param ambiant anbiant color. + * Set diffuse light parameters. + * @param num Number of the light. It's a number from 0 to 7. + * @param pos Position of the diffuse light (x/y/z). + * @param distattn Distance attenuation. + * @param brightness Brightness of the light. The value should be between 0 and 1. + * @param lightcolor Color of the light in RGBA format. */ -void GRRLIB_SetLightDiff(int num, guVector pos, float distattn, float brightness , u32 lightcolor){ -GXLightObj MyLight; -guVector lpos={pos.x,pos.y,pos.z}; +void GRRLIB_SetLightDiff(u8 num, guVector pos, f32 distattn, f32 brightness, u32 lightcolor) { + GXLightObj MyLight; + guVector lpos = {pos.x, pos.y, pos.z}; - GRRLIB_Settings.lights |= (1< #include -#include #include @@ -15,7 +14,7 @@ extern Mtx _GRR_view; int main() { -float l1=0,l2=0; + float l1=0, l2=0; float a=0; int camZ=13.0f; @@ -39,48 +38,46 @@ float l1=0,l2=0; if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_MINUS) camZ--; GRRLIB_Camera3dSettings(0.0f,0.0f,camZ, 0,1,0, 0,0,0); - GRRLIB_SetLightAmbiant(0x333333FF); + GRRLIB_SetLightAmbient(0x333333FF); - if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A){ - // Set all light off to get the spere no light sourced (only get the vertex color) - GRRLIB_SetLightOff(); - GRRLIB_3dMode(0.1,1000,45,0,1); - GRRLIB_ObjectView(sin(l1)*4.0f,0.0f,cos(l1)*4.0f, 0,0,0,1,1,1); - GRRLIB_DrawSphere(0.2f,20,20,true,0xFF0000FF); - l1+=0.03f; - } + if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A) { + // Set all light off to get the spere no light sourced (only get the vertex color) + GRRLIB_SetLightOff(); + GRRLIB_3dMode(0.1,1000,45,0,1); + GRRLIB_ObjectView(sin(l1)*4.0f,0.0f,cos(l1)*4.0f, 0,0,0,1,1,1); + GRRLIB_DrawSphere(0.2f, 20, 20, true, 0xFF0000FF); + l1+=0.03f; + } - if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_B){ - // Set all light off to get the spere no light sourced (only get the vertex color) - GRRLIB_SetLightOff(); - GRRLIB_3dMode(0.1,1000,45,0,1); - GRRLIB_ObjectView(0.0f,sin(l2)*4.0f,cos(l2)*4.0f, 0,0,0,1,1,1); - GRRLIB_DrawSphere(0.2f,20,20,true,0x00FF00FF); - l2+=0.05f; - } + if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_B) { + // Set all light off to get the spere no light sourced (only get the vertex color) + GRRLIB_SetLightOff(); + GRRLIB_3dMode(0.1,1000,45,0,1); + GRRLIB_ObjectView(0.0f,sin(l2)*4.0f,cos(l2)*4.0f, 0,0,0,1,1,1); + GRRLIB_DrawSphere(0.2f, 20, 20, true, 0x00FF00FF); + l2+=0.05f; + } + // Set a dummy black light to get the ambiant one when no light is selected + GRRLIB_SetLightDiff(0,(guVector){sin(l1)*4.0f,0.0f,cos(l1)*4.0f},20.0f,1.0f,0x000000FF); - // SET a dummy black light to get the ambiant one when no light is selected - GRRLIB_SetLightDiff(0,(guVector){sin(l1)*4,0.0f,cos(l1)*4.0f},20.0f,1.0f,0x000000FF); + if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A) { + GRRLIB_SetLightDiff(0,(guVector){sin(l1)*4.0f,0.0f,cos(l1)*4.0f},20.0f,1.0f,0xFF0000FF); + } - if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A){ - GRRLIB_SetLightDiff(0,(guVector){sin(l1)*4,0.0f,cos(l1)*4.0f},20.0f,1.0f,0xFF0000FF); - } - - if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_B){ - GRRLIB_SetLightDiff(1,(guVector){0.0f,sin(l2)*4.0f,cos(l2)*4.0f},20.0f,1.0f,0x00FF00FF); - } + if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_B) { + GRRLIB_SetLightDiff(1,(guVector){0.0f,sin(l2)*4.0f,cos(l2)*4.0f},20.0f,1.0f,0x00FF00FF); + } GRRLIB_3dMode(0.1,1000,45,0,1); GRRLIB_ObjectView(0,0,0, a,a*2,a*3,1,1,1); - GRRLIB_DrawTorus(1,2,60,60,true,0xFFFFFFFF); - + GRRLIB_DrawTorus(1, 2, 60, 60, true, 0xFFFFFFFF); a+=0.5f; - // Switch To 2D Mode to display text + // Switch to 2D Mode to display text GRRLIB_2dMode(); GRRLIB_Printf((640-(16*29))/2, 20, tex_font, 0xFFFFFFFF, 1, "PRESS + OR - TO ZOOM"); GRRLIB_Printf((640-(16*29))/2, 40, tex_font, 0xFFFFFFFF, 1, "HOLD A - RED / B - GREEN");