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:
parent
a646edfaa2
commit
50bf5c1a0a
25
Engine.cc
25
Engine.cc
@ -827,7 +827,6 @@ void Engine::drawArc(float r, float g, float b, float x, float y,
|
||||
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);
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, 0);
|
||||
glColor3f(r, g, b);
|
||||
@ -840,6 +839,30 @@ void Engine::drawArc(float r, float g, float b, float x, float y,
|
||||
}
|
||||
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_TRIANGLE_FAN);
|
||||
glVertex2f(0.0f, 0.0f);
|
||||
float angle = a1;
|
||||
for (int i = 0; i <= segments; i++)
|
||||
{
|
||||
glVertex2f(radius * cos(angle), radius * sin(angle));
|
||||
angle += step;
|
||||
}
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
|
2
Engine.h
2
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,
|
||||
|
56
ag.cc
56
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);
|
||||
|
2
ag.h
2
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);
|
||||
|
||||
|
@ -344,6 +344,32 @@ will be executed and callbacks to other events may still be called.
|
||||
The engine should exit within one update step.
|
||||
</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" />
|
||||
<h3>fillRect</h3>
|
||||
<p><tt>ag.fillRect(r, g, b, width, height, x, y [, rot])</tt></p>
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user