created frontend functionality for creating Quad objects

This commit is contained in:
Josh Holtrop 2010-12-19 00:11:35 -05:00
parent 791fb14925
commit dff232ec66
4 changed files with 167 additions and 1 deletions

View File

@ -331,6 +331,15 @@ int Engine::addObject(bool is_static, bool is_reference, bool enable_blending,
return id;
}
int Engine::addQuad(float cx, float cy, float cz,
float v1x, float v1y, float v1z,
float v2x, float v2y, float v2z)
{
Quad * q = new Quad(cx, cy, cz, v1x, v1y, v1z, v2x, v2y, v2z);
int id = m_quads.add(q);
return id;
}
int Engine::addSound(refptr<AV::Sound> avs)
{
return m_sounds.add(avs);
@ -452,6 +461,11 @@ Engine::Object * Engine::getObject(int id)
return m_objects.contains(id) ? m_objects[id] : NULL;
}
Engine::Quad * Engine::getQuad(int id)
{
return m_quads.contains(id) ? m_quads[id] : NULL;
}
refptr<AV::Sound> Engine::getSound(int id)
{
return m_sounds.contains(id) ? m_sounds[id] : NULL;
@ -1238,6 +1252,12 @@ void Engine::drawObjects()
{
it->second->draw();
}
for (std::map<int, Quad *>::const_iterator it = m_quads.begin();
it != m_quads.end();
it++)
{
it->second->draw();
}
}
/******** Engine::EngineFileLoader functions ********/

View File

@ -165,7 +165,7 @@ class Engine
void setVisible(bool v) { m_visible = v; }
void draw()
{
if (m_visible && m_dl > 0)
if (m_visible)
glCallList(m_dl);
}
void setOffset(float f)
@ -206,6 +206,9 @@ class Engine
int addObject(bool is_static, bool is_reference, bool enable_blending,
OdeWorld::GeomType geom_type,
refptr< std::vector<float> > args);
int addQuad(float cx, float cy, float cz,
float v1x, float v1y, float v1z,
float v2x, float v2y, float v2z);
int addSound(refptr<AV::Sound> avs);
int addAMotor(Object * o1, Object * o2);
int addHinge(Object * o1, Object * o2,
@ -223,6 +226,7 @@ class Engine
void removeObject(int id);
int cloneObject(const Object * obj);
Object * getObject(int id);
Quad * getQuad(int id);
refptr<AV::Sound> getSound(int id);
void doPhysics();
void drawObjects();
@ -327,6 +331,7 @@ class Engine
std::string m_engine_path;
OdeWorld m_world;
IDSet<Object *> m_objects;
IDSet<Quad *> m_quads;
IDSet< refptr<AV::Sound> > m_sounds;
IDSet<dJointID> m_joints;
GLdouble m_eye[3];

130
ag.cc
View File

@ -699,6 +699,56 @@ fail:
return g_engine->clearEventHandler(L);
}
int createQuad(lua_State * L)
{
int argc = lua_gettop(L);
bool valid = true;
if (argc == 9)
{
for (int i = 0; i < argc; i++)
{
if (!lua_isnumber(L, i))
{
valid = false;
break;
}
}
}
else
{
valid = false;
}
if (valid)
{
int qid = g_engine->addQuad(
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),
lua_tonumber(L, 9));
lua_newtable(L);
lua_pushinteger(L, qid);
lua_setfield(L, -2, "id");
lua_pushcfunction(L, quad::setBlending);
lua_setfield(L, -2, "setBlending");
lua_pushcfunction(L, quad::setOffset);
lua_setfield(L, -2, "setOffset");
lua_pushcfunction(L, quad::setTexture);
lua_setfield(L, -2, "setTexture");
lua_pushcfunction(L, quad::setVisible);
lua_setfield(L, -2, "setVisible");
}
else
{
lua_pushnil(L);
}
return 1;
}
int exit(lua_State * L)
{
g_engine->exit();
@ -1578,6 +1628,86 @@ fail:
}
}
namespace quad
{
Engine::Quad * getQuad(lua_State * L, int index)
{
Engine::Quad * ret = NULL;
lua_getfield(L, index, "id");
if (lua_isnumber(L, -1))
{
int id = lua_tointeger(L, -1);
ret = g_engine->getQuad(id);
}
lua_pop(L, 1);
return ret;
}
int setBlending(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 2 && lua_istable(L, 1) && lua_isboolean(L, 2))
{
Engine::Quad * q = getQuad(L, 1);
if (q != NULL)
{
q->setBlending(lua_toboolean(L, 2));
}
}
return 0;
}
int setOffset(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 2 && lua_istable(L, 1) && lua_isnumber(L, 2))
{
Engine::Quad * q = getQuad(L, 1);
if (q != NULL)
{
q->setBlending(lua_tonumber(L, 2));
}
}
return 0;
}
int setTexture(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 2 && lua_istable(L, 1) && lua_istable(L, 2))
{
Engine::Quad * q = getQuad(L, 1);
if (q != NULL)
{
lua_getfield(L, 2, "id");
if (lua_isnumber(L, -1))
{
GLuint id = (GLuint) lua_tointeger(L, -1);
q->setTexture(id);
}
lua_pop(L, 1);
}
}
return 0;
}
int setVisible(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 2 && lua_istable(L, 1) && lua_isboolean(L, 2))
{
Engine::Quad * q = getQuad(L, 1);
if (q != NULL)
{
q->setVisible(lua_toboolean(L, 2));
}
}
return 0;
}
}
namespace joint
{
int setAMotorAxis(lua_State * L)

11
ag.h
View File

@ -14,6 +14,7 @@ namespace ag
/* Lua interfaces */
int callList(lua_State * L);
int clearEventHandler(lua_State * L);
int createQuad(lua_State * L);
int doPhysics(lua_State * L);
int drawObjects(lua_State * L);
int elapsedTime(lua_State * L);
@ -96,6 +97,16 @@ namespace ag
int getSize(lua_State * L);
}
namespace quad
{
Engine::Quad * getQuad(lua_State * L, int index);
int setBlending(lua_State * L);
int setOffset(lua_State * L);
int setTexture(lua_State * L);
int setVisible(lua_State * L);
}
namespace joint
{
int setAMotorAxis(lua_State * L);