updated documentation - added handler / callback prototype section, added key names section; added ag::drawArc() and ag::drawCircle() w/ documentation; added tests/transparent.png and tests/imagetest.lua; renamed init() event to init_event(); re-added missing drawImage Lua hook; changed images to draw transparent parts correctly through to background
git-svn-id: svn://anubis/anaglym/trunk@197 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
8ea89aea33
commit
b546ea74dd
1
.todo
1
.todo
@ -1,2 +1 @@
|
|||||||
- finish bowling demo
|
- finish bowling demo
|
||||||
- finish ag and std documentation
|
|
||||||
|
80
Engine.cc
80
Engine.cc
@ -215,7 +215,7 @@ bool Engine::load(const char * program)
|
|||||||
|
|
||||||
void Engine::checkForAllHandlerFunctions()
|
void Engine::checkForAllHandlerFunctions()
|
||||||
{
|
{
|
||||||
checkForFunction("init", init);
|
checkForFunction("init_event", init);
|
||||||
checkForFunction("update_event", update);
|
checkForFunction("update_event", update);
|
||||||
checkForFunction("update_overlay_event", update_overlay);
|
checkForFunction("update_overlay_event", update_overlay);
|
||||||
checkForFunction("key_down_event", key_down);
|
checkForFunction("key_down_event", key_down);
|
||||||
@ -557,8 +557,6 @@ void Engine::drawLine(float r, float g, float b,
|
|||||||
{
|
{
|
||||||
checkGLError();
|
checkGLError();
|
||||||
glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT);
|
glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT);
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
glLineWidth(width);
|
glLineWidth(width);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
@ -578,8 +576,6 @@ void Engine::drawRect(float r, float g, float b,
|
|||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(x, y, 0);
|
glTranslatef(x, y, 0);
|
||||||
glRotatef(rot, 0, 0, 1);
|
glRotatef(rot, 0, 0, 1);
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
glBegin(GL_LINE_LOOP);
|
glBegin(GL_LINE_LOOP);
|
||||||
glColor3f(r, g, b);
|
glColor3f(r, g, b);
|
||||||
@ -601,8 +597,6 @@ void Engine::fillRect(float r, float g, float b,
|
|||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(x, y, 0);
|
glTranslatef(x, y, 0);
|
||||||
glRotatef(rot, 0, 0, 1);
|
glRotatef(rot, 0, 0, 1);
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
glEnable(GL_POLYGON_SMOOTH);
|
glEnable(GL_POLYGON_SMOOTH);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor3f(r, g, b);
|
glColor3f(r, g, b);
|
||||||
@ -620,14 +614,16 @@ void Engine::drawImage(float width, float height, float x, float y,
|
|||||||
int tex, float rot)
|
int tex, float rot)
|
||||||
{
|
{
|
||||||
checkGLError();
|
checkGLError();
|
||||||
glPushAttrib(GL_ENABLE_BIT);
|
/* TODO: check following flags */
|
||||||
|
glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(x, y, 0);
|
glTranslatef(x, y, 0);
|
||||||
glRotatef(rot, 0, 0, 1);
|
glRotatef(rot, 0, 0, 1);
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
glEnable(GL_POLYGON_SMOOTH);
|
glEnable(GL_POLYGON_SMOOTH);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||||
glBindTexture(GL_TEXTURE_2D, tex);
|
glBindTexture(GL_TEXTURE_2D, tex);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glTexCoord2f(0, 0);
|
glTexCoord2f(0, 0);
|
||||||
@ -644,6 +640,29 @@ void Engine::drawImage(float width, float height, float x, float y,
|
|||||||
checkGLError();
|
checkGLError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
glPushAttrib(GL_ENABLE_BIT);
|
||||||
|
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();
|
||||||
|
glPopAttrib();
|
||||||
|
}
|
||||||
|
|
||||||
/* called by SDL when the update timer expires */
|
/* called by SDL when the update timer expires */
|
||||||
Uint32 Engine::updateCallback(Uint32 interval, void * param)
|
Uint32 Engine::updateCallback(Uint32 interval, void * param)
|
||||||
{
|
{
|
||||||
@ -762,27 +781,28 @@ void Engine::update_overlay_event()
|
|||||||
{
|
{
|
||||||
checkGLError();
|
checkGLError();
|
||||||
glPushAttrib(GL_ENABLE_BIT);
|
glPushAttrib(GL_ENABLE_BIT);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
int width = m_video.getWidth();
|
glDisable(GL_LIGHTING);
|
||||||
int height = m_video.getHeight();
|
int width = m_video.getWidth();
|
||||||
glMatrixMode(GL_PROJECTION);
|
int height = m_video.getHeight();
|
||||||
glPushMatrix();
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glPushMatrix();
|
||||||
glOrtho(0, width, 0, height, -1.01, 1.01);
|
glLoadIdentity();
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glOrtho(0, width, 0, height, -1.01, 1.01);
|
||||||
glLoadIdentity();
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
lua_getfield(m_luaState, LUA_GLOBALSINDEX,
|
lua_getfield(m_luaState, LUA_GLOBALSINDEX,
|
||||||
EVENT_HANDLER_AG_NAME(update_overlay));
|
EVENT_HANDLER_AG_NAME(update_overlay));
|
||||||
lua_pushnumber(m_luaState, width);
|
lua_pushnumber(m_luaState, width);
|
||||||
lua_pushnumber(m_luaState, height);
|
lua_pushnumber(m_luaState, height);
|
||||||
/* call the update_overlay function
|
/* call the update_overlay function
|
||||||
* - pops the function ref from the stack, then the arguments */
|
* - pops the function ref from the stack, then the arguments */
|
||||||
int s = lua_pcall(m_luaState, 2, 0, 0);
|
int s = lua_pcall(m_luaState, 2, 0, 0);
|
||||||
reportErrors(s);
|
reportErrors(s);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
checkGLError();
|
checkGLError();
|
||||||
}
|
}
|
||||||
|
2
Engine.h
2
Engine.h
@ -151,6 +151,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 drawArc(float r, float g, float b, float x, float y,
|
||||||
|
float radius, float a1, float a2);
|
||||||
|
|
||||||
/* lua services */
|
/* lua services */
|
||||||
int setCamera(lua_State * L);
|
int setCamera(lua_State * L);
|
||||||
|
63
ag.cc
63
ag.cc
@ -23,6 +23,9 @@ namespace ag
|
|||||||
static const luaL_Reg functions[] = {
|
static const luaL_Reg functions[] = {
|
||||||
{ "clearEventHandler", clearEventHandler },
|
{ "clearEventHandler", clearEventHandler },
|
||||||
{ "doPhysics", doPhysics },
|
{ "doPhysics", doPhysics },
|
||||||
|
{ "drawArc", drawArc },
|
||||||
|
{ "drawCircle", drawCircle },
|
||||||
|
{ "drawImage", drawImage },
|
||||||
{ "drawLine", drawLine },
|
{ "drawLine", drawLine },
|
||||||
{ "drawObjects", drawObjects },
|
{ "drawObjects", drawObjects },
|
||||||
{ "drawRect", drawRect },
|
{ "drawRect", drawRect },
|
||||||
@ -55,8 +58,8 @@ namespace ag
|
|||||||
{ "createBoxStatic", createBoxStatic },
|
{ "createBoxStatic", createBoxStatic },
|
||||||
{ "createCapsule", createCapsule },
|
{ "createCapsule", createCapsule },
|
||||||
{ "createCapsuleStatic", createCapsuleStatic },
|
{ "createCapsuleStatic", createCapsuleStatic },
|
||||||
{ "createCylinder", createCylinder },
|
// { "createCylinder", createCylinder },
|
||||||
{ "createCylinderStatic", createCylinderStatic },
|
// { "createCylinderStatic", createCylinderStatic },
|
||||||
{ "createPlane", createPlane },
|
{ "createPlane", createPlane },
|
||||||
{ "createSphere", createSphere },
|
{ "createSphere", createSphere },
|
||||||
{ "createSphereStatic", createSphereStatic },
|
{ "createSphereStatic", createSphereStatic },
|
||||||
@ -478,13 +481,67 @@ namespace ag
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int drawArc(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->drawArc(
|
||||||
|
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 drawCircle(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->drawArc(
|
||||||
|
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 drawImage(lua_State * L)
|
int drawImage(lua_State * L)
|
||||||
{
|
{
|
||||||
int argc = lua_gettop(L);
|
int argc = lua_gettop(L);
|
||||||
if (argc == 5 || argc == 6)
|
if (argc == 5 || argc == 6)
|
||||||
{
|
{
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
for (int i = 1; i <= 6; i++)
|
for (int i = 1; i <= argc; i++)
|
||||||
if (i != 5 && !lua_isnumber(L, i))
|
if (i != 5 && !lua_isnumber(L, i))
|
||||||
valid = false;
|
valid = false;
|
||||||
if (!lua_istable(L, 5))
|
if (!lua_istable(L, 5))
|
||||||
|
2
ag.h
2
ag.h
@ -34,6 +34,8 @@ namespace ag
|
|||||||
int startFrame(lua_State * L);
|
int startFrame(lua_State * L);
|
||||||
|
|
||||||
/* 2D overlay functions */
|
/* 2D overlay functions */
|
||||||
|
int drawArc(lua_State * L);
|
||||||
|
int drawCircle(lua_State * L);
|
||||||
int drawImage(lua_State * L);
|
int drawImage(lua_State * L);
|
||||||
int drawLine(lua_State * L);
|
int drawLine(lua_State * L);
|
||||||
int drawRect(lua_State * L);
|
int drawRect(lua_State * L);
|
||||||
|
365
doc/index.html
365
doc/index.html
@ -29,6 +29,8 @@ The library functions are documented below.
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="#std"><tt>std</tt> library</a></li>
|
<li><a href="#std"><tt>std</tt> library</a></li>
|
||||||
|
<li><a href="#handlers">Lua Event Handlers</a></li>
|
||||||
|
<li><a href="#key_names">Key Names</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
@ -42,16 +44,8 @@ The library functions are documented below.
|
|||||||
<p>
|
<p>
|
||||||
This function removes a Lua callback function from being associated
|
This function removes a Lua callback function from being associated
|
||||||
with the engine event specified.
|
with the engine event specified.
|
||||||
<tt>event_name</tt> should be one of the following strings:
|
<tt>event_name</tt> should be a string containing an event name.
|
||||||
<ul>
|
See <a href="#handlers">Lua event handlers</a> for a list of events.
|
||||||
<li><tt>"update"</tt></li>
|
|
||||||
<li><tt>"update_overlay"</tt></li>
|
|
||||||
<li><tt>"key_down"</tt></li>
|
|
||||||
<li><tt>"key_up"</tt></li>
|
|
||||||
<li><tt>"mousebutton_down"</tt></li>
|
|
||||||
<li><tt>"mousebutton_up"</tt></li>
|
|
||||||
<li><tt>"mouse_motion"</tt></li>
|
|
||||||
</ul>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<a name="ag_doPhysics" />
|
<a name="ag_doPhysics" />
|
||||||
@ -64,6 +58,48 @@ mode is enabled; this mode is enabled by default.
|
|||||||
See <a href="#ag_setAutoPhysics">setAutoPhysics</a> for more information.
|
See <a href="#ag_setAutoPhysics">setAutoPhysics</a> for more information.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<a name="ag_drawArc" />
|
||||||
|
<h3>drawArc</h3>
|
||||||
|
<p><tt>ag.drawArc(r, g, b, x, y, radius, a1, a2)</tt></p>
|
||||||
|
<p>
|
||||||
|
This function tells the engine to draw an 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>drawArc()</tt> should normally be called from the
|
||||||
|
<tt>update_overlay</tt> event handler.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a name="ag_drawCircle" />
|
||||||
|
<h3>drawCircle</h3>
|
||||||
|
<p><tt>ag.drawCircle(r, g, b, x, y, radius)</tt></p>
|
||||||
|
<p>
|
||||||
|
This function tells the engine to draw a 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>drawCircle()</tt> should normally be called from the
|
||||||
|
<tt>update_overlay</tt> event handler.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a name="ag_drawImage" />
|
||||||
|
<h3>drawImage</h3>
|
||||||
|
<p><tt>ag.drawImage(width, height, x, y, texture, [, rot])</tt></p>
|
||||||
|
<p>
|
||||||
|
This function tells the engine to draw an image to the screen.
|
||||||
|
<tt>width</tt> and <tt>height</tt> specify the size of the image,
|
||||||
|
in pixels.
|
||||||
|
<tt>x</tt> and <tt>y</tt> specify the coordinates of the center
|
||||||
|
of the image.
|
||||||
|
The image to be drawn is specified by <tt>texture</tt>, which
|
||||||
|
should be loaded by
|
||||||
|
<a href="#ag_loadTexture"><tt>ag.loadTexture()</tt></a>.
|
||||||
|
<tt>drawImage()</tt> should normally be called from the
|
||||||
|
<tt>update_overlay</tt> event handler.
|
||||||
|
</p>
|
||||||
|
|
||||||
<a name="ag_drawLine" />
|
<a name="ag_drawLine" />
|
||||||
<h3>drawLine</h3>
|
<h3>drawLine</h3>
|
||||||
<p><tt>ag.drawLine(r, g, b, x1, y1, x2, y2 [, width])</tt></p>
|
<p><tt>ag.drawLine(r, g, b, x1, y1, x2, y2 [, width])</tt></p>
|
||||||
@ -206,7 +242,7 @@ libraries such as <a href="#std">std</a>.
|
|||||||
This function returns a boolean value for whether or not the key
|
This function returns a boolean value for whether or not the key
|
||||||
given by <tt>key</tt> is currently pressed or not.
|
given by <tt>key</tt> is currently pressed or not.
|
||||||
<tt>key</tt> should be a string corresponding to a key name.
|
<tt>key</tt> should be a string corresponding to a key name.
|
||||||
See <a href="#keys">keys</a> for key names.
|
See <a href="#key_names">Key Names</a> for key names.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<a name="ag_loadModel" />
|
<a name="ag_loadModel" />
|
||||||
@ -280,16 +316,8 @@ occurs.
|
|||||||
There can be only one registered handler per event, so if a previous
|
There can be only one registered handler per event, so if a previous
|
||||||
Lua function was registered for <tt>event_name</tt>, it will be
|
Lua function was registered for <tt>event_name</tt>, it will be
|
||||||
overwritten to call the new handler.
|
overwritten to call the new handler.
|
||||||
<tt>event_name</tt> should be one of:
|
<tt>event_name</tt> should be a string containing the name of the event.
|
||||||
<ul>
|
See <a href="#handlers">Lua event handlers</a> for a list of event names.
|
||||||
<li><tt>"update"</tt></li>
|
|
||||||
<li><tt>"update_overlay"</tt></li>
|
|
||||||
<li><tt>"key_down"</tt></li>
|
|
||||||
<li><tt>"key_up"</tt></li>
|
|
||||||
<li><tt>"mousebutton_down"</tt></li>
|
|
||||||
<li><tt>"mousebutton_up"</tt></li>
|
|
||||||
<li><tt>"mouse_motion"</tt></li>
|
|
||||||
</ul>
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
When the Lua script is initially loaded, any functions found
|
When the Lua script is initially loaded, any functions found
|
||||||
@ -624,6 +652,16 @@ ag.import("std")
|
|||||||
</pre>
|
</pre>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<a name="std_createPlanePointNormal" />
|
||||||
|
<h3>createPlanePointNormal</h3>
|
||||||
|
<p><tt>obj = std.createPlanePointNormal(x, y, z, nx, ny, nz)</tt></p>
|
||||||
|
<p>
|
||||||
|
This function simply wraps
|
||||||
|
<a href="#ag_createPlane"><tt>ag.createPlane()</tt></a>
|
||||||
|
allowing the user to specify a point on the plane with coordinates (x, y, z)
|
||||||
|
and the surface normal of the plane (nx, ny, nz).
|
||||||
|
</p>
|
||||||
|
|
||||||
<a name="std_crossProduct" />
|
<a name="std_crossProduct" />
|
||||||
<h3>crossProduct</h3>
|
<h3>crossProduct</h3>
|
||||||
<p><tt>cp = std.crossProduct(vec1, vec2)</tt></p>
|
<p><tt>cp = std.crossProduct(vec1, vec2)</tt></p>
|
||||||
@ -648,15 +686,286 @@ The indices of <tt>vec1</tt> and <tt>vec2</tt> should be from 1 to 3.
|
|||||||
This allows specifying a Lua array directly as a parameter to the function.
|
This allows specifying a Lua array directly as a parameter to the function.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<a name="std_createPlanePointNormal" />
|
<a name="std_pctx" />
|
||||||
<h3>createPlanePointNormal</h3>
|
<h3>pctx</h3>
|
||||||
<p><tt>obj = std.createPlanePointNormal(x, y, z, nx, ny, nz)</tt></p>
|
<p><tt>pixels_x = std.pctx(percent)</tt></p>
|
||||||
<p>
|
<p>
|
||||||
This function simply wraps
|
This function returns the number of pixels corresponding to
|
||||||
<a href="#ag_createPlane"><tt>ag.createPlane()</tt></a>
|
<tt>percent</tt> percent of the screen's X axis.
|
||||||
allowing the user to specify a point on the plane with coordinates (x, y, z)
|
<tt>percent</tt> should be between 0.0 and 1.0.
|
||||||
and the surface normal of the plane (nx, ny, nz).
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<a name="std_pcty" />
|
||||||
|
<h3>pcty</h3>
|
||||||
|
<p><tt>pixels_y = std.pcty(percent)</tt></p>
|
||||||
|
<p>
|
||||||
|
This function returns the number of pixels corresponding to
|
||||||
|
<tt>percent</tt> percent of the screen's Y axis.
|
||||||
|
<tt>percent</tt> should be between 0.0 and 1.0.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<a name="handlers" />
|
||||||
|
<h2>Lua Event Handlers</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The following is a list of all events that the Anaglym engine
|
||||||
|
handles:
|
||||||
|
<ul>
|
||||||
|
<li><a href="#handler_update"><tt>update</tt></a></li>
|
||||||
|
<li><a href="#handler_update_overlay"><tt>update_overlay</tt></a></li>
|
||||||
|
<li><a href="#handler_key_down"><tt>key_down</tt></a></li>
|
||||||
|
<li><a href="#handler_key_up"><tt>key_up</tt></a></li>
|
||||||
|
<li><a href="#handler_mousebutton_down"><tt>mousebutton_down</tt></a></li>
|
||||||
|
<li><a href="#handler_mousebutton_up"><tt>mousebutton_up</tt></a></li>
|
||||||
|
<li><a href="#handler_mouse_motion"><tt>mouse_motion</tt></a></li>
|
||||||
|
</ul>
|
||||||
|
Lua callback functions may be registered for each of these events.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
When a Lua script is loaded, any defined function that matches the
|
||||||
|
name of an engine event with "<tt>_event</tt>" appended will
|
||||||
|
automatically be registered as a callback for that engine event.
|
||||||
|
For example, a function named <tt>key_up_event()</tt> in
|
||||||
|
a loaded Lua script will automatically be registered to receive
|
||||||
|
<tt>key_up</tt> event notifications.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The prototypes for the Lua event handler callback functions follow.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a name="handler_update" />
|
||||||
|
<h3>update</h3>
|
||||||
|
<p><tt>function update_event()</tt></p>
|
||||||
|
<p>
|
||||||
|
This function is called for every frame that is drawn on the screen.
|
||||||
|
It could be called up to a few dozen times per second.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a name="handler_update_overlay" />
|
||||||
|
<h3>update_overlay</h3>
|
||||||
|
<p><tt>function update_overlay_event(width, height)</tt></p>
|
||||||
|
<p>
|
||||||
|
This function is called immediately after the <tt>update</tt>
|
||||||
|
function.
|
||||||
|
During this event, the coordinate system is reset from the normal
|
||||||
|
3D system to a 2D system.
|
||||||
|
The coordinates range from (0, 0) in the lower-left corner of the
|
||||||
|
screen to (width, height) in the upper-right corner of the screen.
|
||||||
|
In this mode, depth testing is disabled, so any graphics drawn will
|
||||||
|
"overlay" whatever is currently on the screen.
|
||||||
|
<tt>width</tt> and <tt>height</tt> contain the size of the
|
||||||
|
Anaglym engine window, in pixels.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a name="handler_key_down" />
|
||||||
|
<h3>key_down</h3>
|
||||||
|
<p><tt>function key_down_event(key_name)</tt></p>
|
||||||
|
<p>
|
||||||
|
This function is called when a key is initially pressed.
|
||||||
|
<tt>key_name</tt> is a string containing the name of the
|
||||||
|
key pressed.
|
||||||
|
See <a href="#key_names">Key Names</a> for a list of key names.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a name="handler_key_up" />
|
||||||
|
<h3>key_up</h3>
|
||||||
|
<p><tt>function key_up_event(key_name)</tt></p>
|
||||||
|
<p>
|
||||||
|
This function is called when a key is released.
|
||||||
|
<tt>key_name</tt> is a string containing the name of the
|
||||||
|
key released.
|
||||||
|
See <a href="#key_names">Key Names</a> for a list of key names.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a name="handler_mousebutton_down" />
|
||||||
|
<h3>mousebutton_down</h3>
|
||||||
|
<p><tt>function mousebutton_down_event(button, x, y)</tt></p>
|
||||||
|
<p>
|
||||||
|
This function is called when a mouse button is pressed.
|
||||||
|
<tt>button</tt> contains the number of the button pressed
|
||||||
|
(1: left, 2: middle, 3: right, 4: scroll wheel up, 5: scroll wheel down).
|
||||||
|
The position of the cursor when the mouse button was pressed is at
|
||||||
|
(x, y).
|
||||||
|
This position is only meaningful when the cursor is shown.
|
||||||
|
By default, it is hidden.
|
||||||
|
Cursor visibility can be toggled with the F2 key.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a name="handler_mousebutton_up" />
|
||||||
|
<h3>mousebutton_up</h3>
|
||||||
|
<p><tt>function mousebutton_up_event(button, x, y)</tt></p>
|
||||||
|
<p>
|
||||||
|
This function is called when a mouse button is released.
|
||||||
|
<tt>button</tt> contains the number of the button released
|
||||||
|
(1: left, 2: middle, 3: right, 4: scroll wheel up, 5: scroll wheel down).
|
||||||
|
The position of the cursor when the mouse button was released is at
|
||||||
|
(x, y).
|
||||||
|
This position is only meaningful when the cursor is shown.
|
||||||
|
By default, it is hidden.
|
||||||
|
Cursor visibility can be toggled with the F2 key.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a name="handler_mouse_motion" />
|
||||||
|
<h3>mouse_motion</h3>
|
||||||
|
<p><tt>function mouse_motion_event(x, y, xrel, yrel)</tt></p>
|
||||||
|
<p>
|
||||||
|
This function is called when the mouse moves.
|
||||||
|
(x, y) specifies the position that the cursor was moved to.
|
||||||
|
This position is only meaningful when the cursor is shown.
|
||||||
|
<tt>xrel</tt> and <tt>yrel</tt> contain the relative
|
||||||
|
movement distance.
|
||||||
|
These values are meaningful regardless of the cursor visibility state.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<a name="key_names" />
|
||||||
|
<h2>Key Names</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><tt>backspace</tt></li>
|
||||||
|
<li><tt>tab</tt></li>
|
||||||
|
<li><tt>clear</tt></li>
|
||||||
|
<li><tt>return</tt></li>
|
||||||
|
<li><tt>pause</tt></li>
|
||||||
|
<li><tt>escape</tt></li>
|
||||||
|
<li><tt>space</tt></li>
|
||||||
|
<li><tt>exclaim</tt></li>
|
||||||
|
<li><tt>quotedbl</tt></li>
|
||||||
|
<li><tt>hash</tt></li>
|
||||||
|
<li><tt>dollar</tt></li>
|
||||||
|
<li><tt>ampersand</tt></li>
|
||||||
|
<li><tt>quote</tt></li>
|
||||||
|
<li><tt>leftparen</tt></li>
|
||||||
|
<li><tt>rightparen</tt></li>
|
||||||
|
<li><tt>asterisk</tt></li>
|
||||||
|
<li><tt>plus</tt></li>
|
||||||
|
<li><tt>comma</tt></li>
|
||||||
|
<li><tt>minus</tt></li>
|
||||||
|
<li><tt>period</tt></li>
|
||||||
|
<li><tt>slash</tt></li>
|
||||||
|
<li><tt>0</tt></li>
|
||||||
|
<li><tt>1</tt></li>
|
||||||
|
<li><tt>2</tt></li>
|
||||||
|
<li><tt>3</tt></li>
|
||||||
|
<li><tt>4</tt></li>
|
||||||
|
<li><tt>5</tt></li>
|
||||||
|
<li><tt>6</tt></li>
|
||||||
|
<li><tt>7</tt></li>
|
||||||
|
<li><tt>8</tt></li>
|
||||||
|
<li><tt>9</tt></li>
|
||||||
|
<li><tt>colon</tt></li>
|
||||||
|
<li><tt>semicolon</tt></li>
|
||||||
|
<li><tt>less</tt></li>
|
||||||
|
<li><tt>equals</tt></li>
|
||||||
|
<li><tt>greater</tt></li>
|
||||||
|
<li><tt>question</tt></li>
|
||||||
|
<li><tt>at</tt></li>
|
||||||
|
<li><tt>leftbracket</tt></li>
|
||||||
|
<li><tt>backslash</tt></li>
|
||||||
|
<li><tt>rightbracket</tt></li>
|
||||||
|
<li><tt>caret</tt></li>
|
||||||
|
<li><tt>underscore</tt></li>
|
||||||
|
<li><tt>backquote</tt></li>
|
||||||
|
<li><tt>a</tt></li>
|
||||||
|
<li><tt>b</tt></li>
|
||||||
|
<li><tt>c</tt></li>
|
||||||
|
<li><tt>d</tt></li>
|
||||||
|
<li><tt>e</tt></li>
|
||||||
|
<li><tt>f</tt></li>
|
||||||
|
<li><tt>g</tt></li>
|
||||||
|
<li><tt>h</tt></li>
|
||||||
|
<li><tt>i</tt></li>
|
||||||
|
<li><tt>j</tt></li>
|
||||||
|
<li><tt>k</tt></li>
|
||||||
|
<li><tt>l</tt></li>
|
||||||
|
<li><tt>m</tt></li>
|
||||||
|
<li><tt>n</tt></li>
|
||||||
|
<li><tt>o</tt></li>
|
||||||
|
<li><tt>p</tt></li>
|
||||||
|
<li><tt>q</tt></li>
|
||||||
|
<li><tt>r</tt></li>
|
||||||
|
<li><tt>s</tt></li>
|
||||||
|
<li><tt>t</tt></li>
|
||||||
|
<li><tt>u</tt></li>
|
||||||
|
<li><tt>v</tt></li>
|
||||||
|
<li><tt>w</tt></li>
|
||||||
|
<li><tt>x</tt></li>
|
||||||
|
<li><tt>y</tt></li>
|
||||||
|
<li><tt>z</tt></li>
|
||||||
|
<li><tt>delete</tt></li>
|
||||||
|
<li><tt>kp0</tt></li>
|
||||||
|
<li><tt>kp1</tt></li>
|
||||||
|
<li><tt>kp2</tt></li>
|
||||||
|
<li><tt>kp3</tt></li>
|
||||||
|
<li><tt>kp4</tt></li>
|
||||||
|
<li><tt>kp5</tt></li>
|
||||||
|
<li><tt>kp6</tt></li>
|
||||||
|
<li><tt>kp7</tt></li>
|
||||||
|
<li><tt>kp8</tt></li>
|
||||||
|
<li><tt>kp9</tt></li>
|
||||||
|
<li><tt>kp_period</tt></li>
|
||||||
|
<li><tt>kp_divide</tt></li>
|
||||||
|
<li><tt>kp_multiply</tt></li>
|
||||||
|
<li><tt>kp_minus</tt></li>
|
||||||
|
<li><tt>kp_plus</tt></li>
|
||||||
|
<li><tt>kp_enter</tt></li>
|
||||||
|
<li><tt>kp_equals</tt></li>
|
||||||
|
<li><tt>up</tt></li>
|
||||||
|
<li><tt>down</tt></li>
|
||||||
|
<li><tt>right</tt></li>
|
||||||
|
<li><tt>left</tt></li>
|
||||||
|
<li><tt>insert</tt></li>
|
||||||
|
<li><tt>home</tt></li>
|
||||||
|
<li><tt>end</tt></li>
|
||||||
|
<li><tt>pageup</tt></li>
|
||||||
|
<li><tt>pagedown</tt></li>
|
||||||
|
<li><tt>f1</tt></li>
|
||||||
|
<li><tt>f2</tt></li>
|
||||||
|
<li><tt>f3</tt></li>
|
||||||
|
<li><tt>f4</tt></li>
|
||||||
|
<li><tt>f5</tt></li>
|
||||||
|
<li><tt>f6</tt></li>
|
||||||
|
<li><tt>f7</tt></li>
|
||||||
|
<li><tt>f8</tt></li>
|
||||||
|
<li><tt>f9</tt></li>
|
||||||
|
<li><tt>f10</tt></li>
|
||||||
|
<li><tt>f11</tt></li>
|
||||||
|
<li><tt>f12</tt></li>
|
||||||
|
<li><tt>f13</tt></li>
|
||||||
|
<li><tt>f14</tt></li>
|
||||||
|
<li><tt>f15</tt></li>
|
||||||
|
<li><tt>numlock</tt></li>
|
||||||
|
<li><tt>capslock</tt></li>
|
||||||
|
<li><tt>scrollock</tt></li>
|
||||||
|
<li><tt>rshift</tt></li>
|
||||||
|
<li><tt>lshift</tt></li>
|
||||||
|
<li><tt>rctrl</tt></li>
|
||||||
|
<li><tt>lctrl</tt></li>
|
||||||
|
<li><tt>ralt</tt></li>
|
||||||
|
<li><tt>lalt</tt></li>
|
||||||
|
<li><tt>rmeta</tt></li>
|
||||||
|
<li><tt>lmeta</tt></li>
|
||||||
|
<li><tt>lsuper</tt></li>
|
||||||
|
<li><tt>rsuper</tt></li>
|
||||||
|
<li><tt>mode</tt></li>
|
||||||
|
<li><tt>compose</tt></li>
|
||||||
|
<li><tt>help</tt></li>
|
||||||
|
<li><tt>print</tt></li>
|
||||||
|
<li><tt>sysreq</tt></li>
|
||||||
|
<li><tt>break</tt></li>
|
||||||
|
<li><tt>menu</tt></li>
|
||||||
|
<li><tt>power</tt></li>
|
||||||
|
<li><tt>euro</tt></li>
|
||||||
|
<li><tt>undo</tt></li>
|
||||||
|
<li><tt>last</tt></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
20
lib/std.lua
20
lib/std.lua
@ -43,3 +43,23 @@ std.createPlanePointNormal = function(x, y, z, nx, ny, nz)
|
|||||||
-- invoke the ag routine to create a plane based on a, b, c, d parameters
|
-- invoke the ag routine to create a plane based on a, b, c, d parameters
|
||||||
return ag.createPlane(nx, ny, nz, nx * x, ny * y, nz * z)
|
return ag.createPlane(nx, ny, nz, nx * x, ny * y, nz * z)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Convert screen percent to pixel count along X axis
|
||||||
|
-- Input:
|
||||||
|
-- percent: percent (0.0 - 1.0) of the screen's X axis
|
||||||
|
-- Output:
|
||||||
|
-- Number of pixels corresponding to 'percent' percent of the X axis
|
||||||
|
std.pctx = function(percent)
|
||||||
|
local width = ag.getScreenSize()
|
||||||
|
return width * percent
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Convert screen percent to pixel count along Y axis
|
||||||
|
-- Input:
|
||||||
|
-- percent: percent (0.0 - 1.0) of the screen's Y axis
|
||||||
|
-- Output:
|
||||||
|
-- Number of pixels corresponding to 'percent' percent of the Y axis
|
||||||
|
std.pcty = function(percent)
|
||||||
|
local width, height = ag.getScreenSize()
|
||||||
|
return height * percent
|
||||||
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
function init()
|
function init_event()
|
||||||
arena = ag.loadModelStatic("boxarena")
|
arena = ag.loadModelStatic("boxarena")
|
||||||
ball = ag.loadModel("checkerball")
|
ball = ag.loadModel("checkerball")
|
||||||
ball:setPosition(-7, 7.4, 12)
|
ball:setPosition(-7, 7.4, 12)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
function init()
|
function init_event()
|
||||||
local rows = 5
|
local rows = 5
|
||||||
local offset = 1
|
local offset = 1
|
||||||
local pin = ag.loadModel("bowling_pin", 0.5)
|
local pin = ag.loadModel("bowling_pin", 0.5)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
function init()
|
function init_event()
|
||||||
local levels = 7
|
local levels = 7
|
||||||
local crate = ag.loadModel("crate", 0.5)
|
local crate = ag.loadModel("crate", 0.5)
|
||||||
local offset = 0.5
|
local offset = 0.5
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
function init()
|
function init_event()
|
||||||
crates = {}
|
crates = {}
|
||||||
|
|
||||||
levels = 5
|
levels = 5
|
||||||
|
17
tests/imagetest.lua
Normal file
17
tests/imagetest.lua
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
function init_event()
|
||||||
|
ag.import("std")
|
||||||
|
image = ag.loadTexture("transparent.png")
|
||||||
|
local crate = ag.loadModelStatic("crate")
|
||||||
|
ag.setCamera(5, -5, 5)
|
||||||
|
end
|
||||||
|
|
||||||
|
function update_overlay_event(width, height)
|
||||||
|
local time = ag.elapsedTime()
|
||||||
|
local rot = time / 1000 * 90
|
||||||
|
local scale = math.sin(time / 1000) * 1.5 / 2 + 1.25
|
||||||
|
ag.drawImage(256 * scale, 256 * scale, width / 2, height / 2, image, rot);
|
||||||
|
ag.drawArc(1, 0, 0.5, width * 0.8, height * 0.8, height * 0.15,
|
||||||
|
90, 180);
|
||||||
|
ag.drawCircle(0, 0, 1, width * 0.8, height * 0.2, height * 0.15);
|
||||||
|
end
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
function init()
|
function init_event()
|
||||||
local crate_texture = ag.loadTexture("checker.jpg")
|
local crate_texture = ag.loadTexture("checker.jpg")
|
||||||
local ground = ag.createPlaneStatic(0, 0, 1, 0)
|
local ground = ag.createPlaneStatic(0, 0, 1, 0)
|
||||||
ground:setColor(0.2, 1.0, 0.2)
|
ground:setColor(0.2, 1.0, 0.2)
|
||||||
|
BIN
tests/transparent.png
Normal file
BIN
tests/transparent.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
Loading…
x
Reference in New Issue
Block a user