From f3a8825d21f51c40d6e0323349c1f98561c4c5af Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Sat, 28 Feb 2009 03:57:19 +0000 Subject: [PATCH] [NEW] GRRLIB_Circle function by Dark-Link --- GRRLIB/GRRLIB/GRRLIB.c | 32 ++++++++++++++++++++++++++++++++ GRRLIB/GRRLIB/GRRLIB.h | 1 + examples/lesson1/source/main.c | 1 + readme.txt | 2 -- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/GRRLIB/GRRLIB/GRRLIB.c b/GRRLIB/GRRLIB/GRRLIB.c index bd1c288..1068e64 100644 --- a/GRRLIB/GRRLIB/GRRLIB.c +++ b/GRRLIB/GRRLIB/GRRLIB.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "../lib/libpng/pngu/pngu.h" #include "../lib/libjpeg/jpeglib.h" #include "GRRLIB.h" @@ -90,6 +91,37 @@ inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8 } } +/** + * Draw a circle. + * @author Dark-Link + * @param x. + * @param y. + * @param radius the radius of the circle. + * @param color the color of the circle in RGBA format. + * @param filled true to fill the circle with a color. + */ +inline void GRRLIB_Circle(f32 x, f32 y, f32 radius, u32 color, u8 filled) { + Vector v[36]; + u32 a; + f32 ra; + f32 G_DTOR = M_DTOR * 10; + + for (a = 0; a < 36; a++) { + ra = a * G_DTOR; + + v[a].x = cos(ra) * radius + x; + v[a].y = sin(ra) * radius + y; + v[a].z = 0.0f; + } + + if (!filled) { + GRRLIB_GXEngine(v, color, 36, GX_LINESTRIP); + } + else { + GRRLIB_GXEngine(v, color, 36, GX_TRIANGLEFAN); + } +} + /** * Draw a polygon. * @param v diff --git a/GRRLIB/GRRLIB/GRRLIB.h b/GRRLIB/GRRLIB/GRRLIB.h index 46031a1..eaa4f2c 100644 --- a/GRRLIB/GRRLIB/GRRLIB.h +++ b/GRRLIB/GRRLIB/GRRLIB.h @@ -69,6 +69,7 @@ void GRRLIB_NPlot(Vector v[], u32 color, long n); inline void GRRLIB_Line(f32 x1, f32 y1, f32 x2, f32 y2, u32 color); inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8 filled); +inline void GRRLIB_Circle(f32 x, f32 y, f32 radius, u32 color, u8 filled); void GRRLIB_NGone(Vector v[], u32 color, long n); void GRRLIB_NGoneFilled(Vector v[], u32 color, long n); diff --git a/examples/lesson1/source/main.c b/examples/lesson1/source/main.c index 624c148..11eadee 100644 --- a/examples/lesson1/source/main.c +++ b/examples/lesson1/source/main.c @@ -147,6 +147,7 @@ int main() { GRRLIB_Line(100, 100, 350, 200, GRRLIB_SILVER); GRRLIB_NGoneFilled(triangle, GRRLIB_GRAY, 3); GRRLIB_Rectangle(left + 150, top + 150, 200, 200, 0x0000FFC8, 1); // Blue with alpha + GRRLIB_Circle(left + 300, top + 300, 50, GRRLIB_OLIVE, 1); // Draw a yellow four pixel dot where the wiimote is pointing GRRLIB_Plot(ir1.sx, ir1.sy, GRRLIB_YELLOW); diff --git a/readme.txt b/readme.txt index 099b873..e1cfc3d 100644 --- a/readme.txt +++ b/readme.txt @@ -24,8 +24,6 @@ ChangeLog : * Color format change for ALL GRRLib function (now its RGBA) to fit to GX_Color format and use GX_Color1u32 -* Name Change GRRLIB_LoadTexture to GRRLIB_LoadTexturePNG - * GRRLib introduce a new texture structure (easier to handle texture width, height, etc ...): typedef struct GRRLIB_texImg{ unsigned int w;