added ag.fillArc() and ag.fillCircle() and associated documentation

git-svn-id: svn://anubis/anaglym/trunk@275 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2010-03-03 15:43:12 +00:00
parent a646edfaa2
commit 50bf5c1a0a
7 changed files with 112 additions and 2 deletions

1
.todo
View File

@ -1,3 +1,2 @@
add audio capabilities add audio capabilities
add fillCircle()
add gradient functionality add gradient functionality

View File

@ -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, void Engine::drawArc(float r, float g, float b, float x, float y,
float radius, float a1, float a2) 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; a1 *= M_PI / 180.0f;
a2 *= M_PI / 180.0f; a2 *= M_PI / 180.0f;
int segments = 1 + (int) (fabsf(a2 - a1) / (M_2_PI / 16.0f)); int segments = 1 + (int) (fabsf(a2 - a1) / (M_2_PI / 16.0f));
float step = (a2 - a1) / segments; float step = (a2 - a1) / segments;
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_LIGHTING);
glPushMatrix(); glPushMatrix();
glTranslatef(x, y, 0); glTranslatef(x, y, 0);
glColor3f(r, g, b); glColor3f(r, g, b);
glBegin(GL_LINE_STRIP); glBegin(GL_TRIANGLE_FAN);
glVertex2f(0.0f, 0.0f);
float angle = a1; float angle = a1;
for (int i = 0; i <= segments; i++) for (int i = 0; i <= segments; i++)
{ {

View File

@ -217,6 +217,8 @@ class Engine
float width, float height, float x, float y, float rot = 0.0f); float width, float height, float x, float y, float rot = 0.0f);
void drawImage(float width, float height, float x, float y, void drawImage(float width, float height, float x, float y,
int tex, float rot = 0.0f); 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, void drawArc(float r, float g, float b, float x, float y,
float radius, float a1, float a2); float radius, float a1, float a2);
void drawPoint(float size, float r, float g, float b, void drawPoint(float size, float r, float g, float b,

56
ag.cc
View File

@ -36,6 +36,8 @@ namespace ag
{ "endFrame", endFrame }, { "endFrame", endFrame },
{ "endList", endList }, { "endList", endList },
{ "exit", exit }, { "exit", exit },
{ "fillArc", fillArc },
{ "fillCircle", fillCircle },
{ "fillRect", fillRect }, { "fillRect", fillRect },
{ "getCamera", getCamera }, { "getCamera", getCamera },
{ "getCursorVisible", getCursorVisible }, { "getCursorVisible", getCursorVisible },
@ -758,6 +760,60 @@ namespace ag
return 0; 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 fillRect(lua_State * L)
{ {
int argc = lua_gettop(L); int argc = lua_gettop(L);

2
ag.h
View File

@ -55,6 +55,8 @@ namespace ag
int drawPoint(lua_State * L); int drawPoint(lua_State * L);
int drawRect(lua_State * L); int drawRect(lua_State * L);
int drawText(lua_State * L); int drawText(lua_State * L);
int fillArc(lua_State * L);
int fillCircle(lua_State * L);
int fillRect(lua_State * L); int fillRect(lua_State * L);
int getTextSize(lua_State * L); int getTextSize(lua_State * L);

View File

@ -344,6 +344,32 @@ will be executed and callbacks to other events may still be called.
The engine should exit within one update step. The engine should exit within one update step.
</p> </p>
<a name="ag_fillArc" />
<h3>fillArc</h3>
<p><tt>ag.fillArc(r, g, b, x, y, radius, a1, a2)</tt></p>
<p>
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).
<tt>x</tt> and <tt>y</tt> specify the coordinates of the center
of the arc.
The arc ranges from angle <tt>a1</tt> to <tt>a2</tt>, which are
specified in degrees, going counter-clockwise from the East.
<tt>fillArc()</tt> should normally be called from the
<tt>update_overlay</tt> event handler.
</p>
<a name="ag_fillCircle" />
<h3>fillCircle</h3>
<p><tt>ag.fillCircle(r, g, b, x, y, radius)</tt></p>
<p>
This function tells the engine to draw a solid circle to the screen.
The color of the circle is specified by (r, g, b).
<tt>x</tt> and <tt>y</tt> specify the coordinates of the center
of the circle.
<tt>fillCircle()</tt> should normally be called from the
<tt>update_overlay</tt> event handler.
</p>
<a name="ag_fillRect" /> <a name="ag_fillRect" />
<h3>fillRect</h3> <h3>fillRect</h3>
<p><tt>ag.fillRect(r, g, b, width, height, x, y [, rot])</tt></p> <p><tt>ag.fillRect(r, g, b, width, height, x, y [, rot])</tt></p>

View File

@ -78,4 +78,6 @@ function update_overlay_event(width, height)
if (pt_x >= 0 and pt_y >= 0) then if (pt_x >= 0 and pt_y >= 0) then
ag.drawCircle(0, 1, 0, pt_x, pt_y, 5) ag.drawCircle(0, 1, 0, pt_x, pt_y, 5)
end end
ag.fillArc(1, 1, 0, 50, 50, 30, 30, 330)
ag.fillCircle(1, 0, 1, width - 50, height - 50, 40)
end end