mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-22 15:02:20 +00:00
[ADD] Adding GRRLIB_DrawCylinder
[CHG] Light/Primitive Demo code
This commit is contained in:
parent
6847fba41f
commit
96783d84bb
3 changed files with 53 additions and 5 deletions
|
@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled);
|
||||||
void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled);
|
void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled);
|
||||||
void GRRLIB_DrawCube(f32 size, 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
|
// GRRLIB_Freetype.c - FreeType function for GRRLIB
|
||||||
|
|
|
@ -50,14 +50,17 @@ int main() {
|
||||||
GRRLIB_LightSwitch(GX_LIGHT0|GX_LIGHT1|GX_LIGHT2,RGBA(Amb,Amb,Amb,0xFF),0x808080FF,0);
|
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_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_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_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_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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue