mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-12-23 02:39:19 +00:00
[ADD] Adding GRRLIB_DrawSphere
[CHG] Light and primitive demo to add a sphere
This commit is contained in:
parent
864f2610e9
commit
d352bd354d
3 changed files with 41 additions and 3 deletions
|
@ -286,3 +286,37 @@ void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled){
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a Sphere (with normal).
|
||||
* @param r Radius of the Sprhere.
|
||||
* @param lats Number of lattitudes.
|
||||
* @param longs Number of Longitutes.
|
||||
* @param filled Wired or not.
|
||||
*/
|
||||
void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled) {
|
||||
int i,j;
|
||||
|
||||
for(i = 0; i <= lats; i++) {
|
||||
f32 lat0 = M_PI * (-0.5F + (f32) (i - 1) / lats);
|
||||
f32 z0 = sin(lat0);
|
||||
f32 zr0 = cos(lat0);
|
||||
|
||||
f32 lat1 = M_PI * (-0.5F + (f32) i / lats);
|
||||
f32 z1 = sin(lat1);
|
||||
f32 zr1 = cos(lat1);
|
||||
if(filled) GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2*(longs+1));
|
||||
else GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 2*(longs+1));
|
||||
for(j = 0; j <= longs; j++) {
|
||||
f32 lng = 2 * M_PI * (f32) (j - 1) / longs;
|
||||
f32 x = cos(lng);
|
||||
f32 y = sin(lng);
|
||||
|
||||
GX_Position3f32(x * zr0 * r, y * zr0 * r, z0 * r);
|
||||
GX_Normal3f32(x * zr0 * r, y * zr0 * r, z0 * r);
|
||||
GX_Position3f32(x * zr1 * r, y * zr1 * r, z1 * r);
|
||||
GX_Normal3f32(x * zr1 * r, y * zr1 * r, z1 * r);
|
||||
}
|
||||
GX_End();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@ void GRRLIB_InitLight(u8 id, guVector lpos, u32 lcol);
|
|||
void GRRLIB_LightOff(void);
|
||||
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);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// GRRLIB_Freetype.c - FreeType function for GRRLIB
|
||||
|
|
|
@ -50,9 +50,12 @@ 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, 2.0f, 20, 50, 0);
|
||||
GRRLIB_ObjectView(0,0,0, -a,-a*2,-a*3, 1,1,1);
|
||||
GRRLIB_DrawTorus(0.8f, 4.0f, 20, 50, 1);
|
||||
GRRLIB_DrawTorus(0.4f, 3.0f, 20, 50, 1);
|
||||
GRRLIB_ObjectView(0,0,0, -a,a*2,-a*3, 1,1,1);
|
||||
GRRLIB_DrawSphere(2.0f, 30, 30, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
a+=0.5f;
|
||||
|
||||
|
|
Loading…
Reference in a new issue