From 50bf5c1a0ae2abcc4e5655cdb7152da177150d84 Mon Sep 17 00:00:00 2001
From: Josh Holtrop
Date: Wed, 3 Mar 2010 15:43:12 +0000
Subject: [PATCH] added ag.fillArc() and ag.fillCircle() and associated
documentation
git-svn-id: svn://anubis/anaglym/trunk@275 99a6e188-d820-4881-8870-2d33a10e2619
---
.todo | 1 -
Engine.cc | 25 ++++++++++++++++-
Engine.h | 2 ++
ag.cc | 56 +++++++++++++++++++++++++++++++++++++++
ag.h | 2 ++
doc/index.html | 26 ++++++++++++++++++
tests/managed_objects.lua | 2 ++
7 files changed, 112 insertions(+), 2 deletions(-)
diff --git a/.todo b/.todo
index aa4e6fa..5e7b7d7 100644
--- a/.todo
+++ b/.todo
@@ -1,3 +1,2 @@
add audio capabilities
-add fillCircle()
add gradient functionality
diff --git a/Engine.cc b/Engine.cc
index 27e4996..8487b28 100644
--- a/Engine.cc
+++ b/Engine.cc
@@ -822,16 +822,39 @@ void Engine::drawImage(float width, float height, float x, float y,
void Engine::drawArc(float r, float g, float b, float x, float y,
float radius, float a1, float a2)
+{
+ a1 *= M_PI / 180.0f;
+ a2 *= M_PI / 180.0f;
+ int segments = 1 + (int) (fabsf(a2 - a1) / (M_2_PI / 16.0f));
+ float step = (a2 - a1) / segments;
+ glPushMatrix();
+ glTranslatef(x, y, 0);
+ glColor3f(r, g, b);
+ glBegin(GL_LINE_STRIP);
+ float angle = a1;
+ for (int i = 0; i <= segments; i++)
+ {
+ glVertex2f(radius * cos(angle), radius * sin(angle));
+ angle += step;
+ }
+ glEnd();
+ glPopMatrix();
+}
+
+void Engine::fillArc(float r, float g, float b, float x, float y,
+ float radius, float a1, float a2)
{
a1 *= M_PI / 180.0f;
a2 *= M_PI / 180.0f;
int segments = 1 + (int) (fabsf(a2 - a1) / (M_2_PI / 16.0f));
float step = (a2 - a1) / segments;
glPushAttrib(GL_ENABLE_BIT);
+ glDisable(GL_LIGHTING);
glPushMatrix();
glTranslatef(x, y, 0);
glColor3f(r, g, b);
- glBegin(GL_LINE_STRIP);
+ glBegin(GL_TRIANGLE_FAN);
+ glVertex2f(0.0f, 0.0f);
float angle = a1;
for (int i = 0; i <= segments; i++)
{
diff --git a/Engine.h b/Engine.h
index 3c3253f..b09cce9 100644
--- a/Engine.h
+++ b/Engine.h
@@ -217,6 +217,8 @@ class Engine
float width, float height, float x, float y, float rot = 0.0f);
void drawImage(float width, float height, float x, float y,
int tex, float rot = 0.0f);
+ void fillArc(float r, float g, float b, float x, float y,
+ float radius, float a1, float a2);
void drawArc(float r, float g, float b, float x, float y,
float radius, float a1, float a2);
void drawPoint(float size, float r, float g, float b,
diff --git a/ag.cc b/ag.cc
index 263fc51..fd5865f 100644
--- a/ag.cc
+++ b/ag.cc
@@ -36,6 +36,8 @@ namespace ag
{ "endFrame", endFrame },
{ "endList", endList },
{ "exit", exit },
+ { "fillArc", fillArc },
+ { "fillCircle", fillCircle },
{ "fillRect", fillRect },
{ "getCamera", getCamera },
{ "getCursorVisible", getCursorVisible },
@@ -758,6 +760,60 @@ namespace ag
return 0;
}
+ int fillArc(lua_State * L)
+ {
+ int argc = lua_gettop(L);
+ if (argc == 8)
+ {
+ bool valid = true;
+ for (int i = 1; i <= argc; i++)
+ {
+ if (!lua_isnumber(L, i))
+ valid = false;
+ }
+ if (valid)
+ {
+ g_engine->fillArc(
+ lua_tonumber(L, 1),
+ lua_tonumber(L, 2),
+ lua_tonumber(L, 3),
+ lua_tonumber(L, 4),
+ lua_tonumber(L, 5),
+ lua_tonumber(L, 6),
+ lua_tonumber(L, 7),
+ lua_tonumber(L, 8));
+ }
+ }
+ return 0;
+ }
+
+ int fillCircle(lua_State * L)
+ {
+ int argc = lua_gettop(L);
+ if (argc == 6)
+ {
+ bool valid = true;
+ for (int i = 1; i <= argc; i++)
+ {
+ if (!lua_isnumber(L, i))
+ valid = false;
+ }
+ if (valid)
+ {
+ g_engine->fillArc(
+ lua_tonumber(L, 1),
+ lua_tonumber(L, 2),
+ lua_tonumber(L, 3),
+ lua_tonumber(L, 4),
+ lua_tonumber(L, 5),
+ lua_tonumber(L, 6),
+ 0.0,
+ 360.0);
+ }
+ }
+ return 0;
+ }
+
int fillRect(lua_State * L)
{
int argc = lua_gettop(L);
diff --git a/ag.h b/ag.h
index 49074ae..abeafe6 100644
--- a/ag.h
+++ b/ag.h
@@ -55,6 +55,8 @@ namespace ag
int drawPoint(lua_State * L);
int drawRect(lua_State * L);
int drawText(lua_State * L);
+ int fillArc(lua_State * L);
+ int fillCircle(lua_State * L);
int fillRect(lua_State * L);
int getTextSize(lua_State * L);
diff --git a/doc/index.html b/doc/index.html
index 5fb2f89..82f5603 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -344,6 +344,32 @@ will be executed and callbacks to other events may still be called.
The engine should exit within one update step.
+
+fillArc
+ag.fillArc(r, g, b, x, y, radius, a1, a2)
+
+This function tells the engine to draw a filled-in arc to the screen.
+The color of the arc is specified by (r, g, b).
+x and y specify the coordinates of the center
+of the arc.
+The arc ranges from angle a1 to a2, which are
+specified in degrees, going counter-clockwise from the East.
+fillArc() should normally be called from the
+update_overlay event handler.
+
+
+
+fillCircle
+ag.fillCircle(r, g, b, x, y, radius)
+
+This function tells the engine to draw a solid circle to the screen.
+The color of the circle is specified by (r, g, b).
+x and y specify the coordinates of the center
+of the circle.
+fillCircle() should normally be called from the
+update_overlay event handler.
+
+
fillRect
ag.fillRect(r, g, b, width, height, x, y [, rot])
diff --git a/tests/managed_objects.lua b/tests/managed_objects.lua
index c0e9ca3..1a2991b 100644
--- a/tests/managed_objects.lua
+++ b/tests/managed_objects.lua
@@ -78,4 +78,6 @@ function update_overlay_event(width, height)
if (pt_x >= 0 and pt_y >= 0) then
ag.drawCircle(0, 1, 0, pt_x, pt_y, 5)
end
+ ag.fillArc(1, 1, 0, 50, 50, 30, 30, 330)
+ ag.fillCircle(1, 0, 1, width - 50, height - 50, 40)
end