added visibility flag to Engine::Object and ag::object::setVisible() to control it

git-svn-id: svn://anubis/anaglym/trunk@68 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-10-12 16:41:42 +00:00
parent 207f7e628a
commit 792e087885
5 changed files with 34 additions and 14 deletions

16
ag.cc
View File

@ -115,6 +115,8 @@ namespace ag
lua_setfield(L, -2, "clone"); lua_setfield(L, -2, "clone");
lua_pushcfunction(L, object::destroy); lua_pushcfunction(L, object::destroy);
lua_setfield(L, -2, "destroy"); lua_setfield(L, -2, "destroy");
lua_pushcfunction(L, object::setVisible);
lua_setfield(L, -2, "setVisible");
} }
static int loadModelSpecify(lua_State * L, bool static_data) static int loadModelSpecify(lua_State * L, bool static_data)
@ -347,5 +349,19 @@ namespace ag
} }
return 0; return 0;
} }
int setVisible(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 2)
{
Engine::Object * obj = getObject(L, 1);
if (obj != NULL && lua_isboolean(L, 2))
{
obj->setVisible(lua_toboolean(L, 2));
}
}
return 0;
}
} }
} }

1
ag.h
View File

@ -26,6 +26,7 @@ namespace ag
int getPosition(lua_State * L); int getPosition(lua_State * L);
int clone(lua_State * L); int clone(lua_State * L);
int destroy(lua_State * L); int destroy(lua_State * L);
int setVisible(lua_State * L);
} }
} }

View File

@ -355,10 +355,12 @@ Engine::Object::Object(bool is_static, OdeWorld & world, GLuint dl)
m_display_list = dl; m_display_list = dl;
m_display_list_refcnt = new int; m_display_list_refcnt = new int;
*m_display_list_refcnt = 1; *m_display_list_refcnt = 1;
m_is_visible = true;
} }
Engine::Object::Object(const Engine::Object & orig) Engine::Object::Object(const Engine::Object & orig)
{ {
m_is_visible = orig.m_is_visible;
m_ode_object = new OdeWorld::Object(*orig.m_ode_object); m_ode_object = new OdeWorld::Object(*orig.m_ode_object);
m_display_list = orig.m_display_list; m_display_list = orig.m_display_list;
m_display_list_refcnt = orig.m_display_list_refcnt; m_display_list_refcnt = orig.m_display_list_refcnt;
@ -379,6 +381,8 @@ Engine::Object::~Object()
void Engine::Object::draw() void Engine::Object::draw()
{ {
if (m_is_visible)
{
const dReal * pos = m_ode_object->getPosition(); const dReal * pos = m_ode_object->getPosition();
const dReal * rot = m_ode_object->getRotation(); const dReal * rot = m_ode_object->getRotation();
bool transform = (pos != NULL && rot != NULL); bool transform = (pos != NULL && rot != NULL);
@ -390,4 +394,5 @@ void Engine::Object::draw()
if (transform) if (transform)
glPopMatrix(); glPopMatrix();
}
} }

View File

@ -33,6 +33,8 @@ class Engine
{ {
m_ode_object->loadPhy(path); m_ode_object->loadPhy(path);
} }
void setVisible(bool visible) { m_is_visible = visible; }
bool getVisible() { return m_is_visible; }
void draw(); void draw();
@ -40,6 +42,7 @@ class Engine
OdeWorld::Object * m_ode_object; OdeWorld::Object * m_ode_object;
GLuint m_display_list; GLuint m_display_list;
int * m_display_list_refcnt; int * m_display_list_refcnt;
bool m_is_visible;
}; };
Engine(); Engine();

View File

@ -1,10 +1,5 @@
function update() function update()
elapsed = ag.elapsedTime()
if (elapsed > 2000 and ball2there) then
ball2:destroy()
ball2there = false
end
ballx, bally, ballz = ball:getPosition() ballx, bally, ballz = ball:getPosition()
ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1) ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1)
ag.doPhysics() ag.doPhysics()
@ -15,11 +10,11 @@ end
--ag.setCamera(8, -8, 15, -8, 8, 4, 0, 0, 1) --ag.setCamera(8, -8, 15, -8, 8, 4, 0, 0, 1)
arena = ag.loadStaticModel("boxarena") arena = ag.loadStaticModel("boxarena")
arena:setVisible(false)
ball = ag.loadModel("ball") ball = ag.loadModel("ball")
ball:setPosition(-7, 7.4, 12) ball:setPosition(-7, 7.4, 12)
ball2 = ball:clone() ball2 = ball:clone()
ball2:setPosition(-7, 7.4, 14) ball2:setPosition(-7, 7.4, 14)
ball2there = true
ball3 = ball:clone() ball3 = ball:clone()
ball3:setPosition(-7, 7.4, 16) ball3:setPosition(-7, 7.4, 16)
logo = ag.loadModel("dwlogo") logo = ag.loadModel("dwlogo")