diff --git a/GRRLIB/GRRLIB/GRRLIB_3D.c b/GRRLIB/GRRLIB/GRRLIB_3D.c index dcd5561..e8259c1 100644 --- a/GRRLIB/GRRLIB/GRRLIB_3D.c +++ b/GRRLIB/GRRLIB/GRRLIB_3D.c @@ -374,3 +374,47 @@ void GRRLIB_DrawCube(f32 size, bool filled) } } +/** + * Draw a Cube (with normal). + * @param r Radius of the cylinder. + * @param h High of the cylinder. + * @param d Dencity of slice. + * @param filled Wired or not. +*/ +void GRRLIB_DrawCylinder(f32 r, f32 h, int d, bool filled){ + int i; + + if(filled) GX_Begin(GX_TRIANGLESTRIP,GX_VTXFMT0, 2 * (d+1)); + else GX_Begin(GX_LINESTRIP,GX_VTXFMT0, 2 * (d+1)); + for(i = 0 ; i <= d ; i++){ + f32 dx = cosf( M_PI * 2.0f * i / d ); + f32 dy = sinf( M_PI * 2.0f * i / d ); + GX_Position3f32( r * dx, -0.5f * h, r * dy ); + GX_Normal3f32( dx, 0.0f, dy ); + GX_Position3f32( r * dx, 0.5f * h, r * dy ); + GX_Normal3f32( dx, 0.0f, dy ); + } + GX_End(); + + if(filled) GX_Begin(GX_TRIANGLEFAN,GX_VTXFMT0,d+2); + else GX_Begin(GX_LINESTRIP,GX_VTXFMT0,d+2); + GX_Position3f32(0.0f, -0.5f * h, 0.0f); + GX_Normal3f32(0.0f, -1.0f, 0.0f); + for(i = 0 ; i <= d ; i++){ + GX_Position3f32( r * cosf( M_PI * 2.0f * i / d ), -0.5f * h, r * sinf( M_PI * 2.0f * i / d ) ); + GX_Normal3f32(0.0f, -1.0f, 0.0f); + } + GX_End(); + + if(filled) GX_Begin(GX_TRIANGLEFAN,GX_VTXFMT0,d+2); + else GX_Begin(GX_LINESTRIP,GX_VTXFMT0,d+2); + GX_Position3f32(0.0f, 0.5f * h, 0.0f); + GX_Normal3f32(0.0f, 1.0f, 0.0f); + for(i = 0 ; i <= d ; i++){ + GX_Position3f32( r * cosf( M_PI * 2.0f * i / d ), 0.5f * h, r * sinf( M_PI * 2.0f * i / d ) ); + GX_Normal3f32(0.0f, 1.0f, 0.0f); + } + GX_End(); + +} + diff --git a/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h b/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h index 9e668f3..b639636 100644 --- a/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h +++ b/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h @@ -153,6 +153,7 @@ void GRRLIB_LightSwitch(u8 id, u32 ambcol, u32 matcol, u8 colsrc); void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled); void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled); void GRRLIB_DrawCube(f32 size, bool filled); +void GRRLIB_DrawCylinder(f32 r, f32 h, int d, bool filled); //------------------------------------------------------------------------------ // GRRLIB_Freetype.c - FreeType function for GRRLIB diff --git a/examples/3D_LightDiffuse/source/main.c b/examples/3D_LightDiffuse/source/main.c index 8af4894..2c96dd9 100644 --- a/examples/3D_LightDiffuse/source/main.c +++ b/examples/3D_LightDiffuse/source/main.c @@ -50,15 +50,18 @@ int main() { GRRLIB_LightSwitch(GX_LIGHT0|GX_LIGHT1|GX_LIGHT2,RGBA(Amb,Amb,Amb,0xFF),0x808080FF,0); GRRLIB_ObjectView(0,0,0, a,a*2,a*3, 1,1,1); - GRRLIB_DrawTorus(0.4f, 3.0f, 20, 50, 1); + GRRLIB_DrawTorus(0.4f, 3.0f, 20, 50, true); GRRLIB_ObjectView(0,0,0, -a,a*2,-a*3, 1,1,1); - GRRLIB_DrawSphere(2.0f, 30, 30, 0); + GRRLIB_DrawSphere(2.0f, 30, 30, false); GRRLIB_ObjectView(-4,-4,0, a,a*2,-a*3, 1,1,1); - GRRLIB_DrawCube(2.0f, 0); + GRRLIB_DrawCube(2.0f, false); GRRLIB_ObjectView(4,-4,0, a,-a*2,-a*3, 1,1,1); - GRRLIB_DrawCube(2.0f, 1); + GRRLIB_DrawCube(2.0f, true); + GRRLIB_ObjectView(-4,4,0, a,-a*2,-a*3, 1,1,1); + GRRLIB_DrawCylinder(1.0f, 2.0f, 20, true); + GRRLIB_ObjectView(4,4,0, a,-a*2,-a*3, 1,1,1); + GRRLIB_DrawCylinder(1.0f, 2.0f, 20, false); - a+=0.5f;