filled in Engine::Object::{get,set}Position()

git-svn-id: svn://anubis/anaglym/trunk@44 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-10-01 03:38:39 +00:00
parent 0753f243c5
commit 05858c0c22
3 changed files with 29 additions and 1 deletions

9
ag.cc
View File

@ -246,6 +246,7 @@ namespace ag
position[i] = lua_tonumber(L, i + 2);
}
}
obj->setPosition(position[0], position[1], position[2]);
}
}
@ -260,9 +261,15 @@ namespace ag
Engine::Object * obj = getObject(L, 1);
if (obj != NULL)
{
double x, y, z;
obj->getPosition(&x, &y, &z);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
lua_pushnumber(L, z);
return 3;
}
}
return 3;
return 0;
}
}
}

View File

@ -239,3 +239,22 @@ void Engine::Object::loadPhy(const std::string & path, bool static_data)
{
geoms = g_engine->m_world.loadPhy(path, &body, static_data);
}
void Engine::Object::setPosition(double x, double y, double z)
{
if (body != 0)
{
dBodySetPosition(body, x, y, z);
}
}
void Engine::Object::getPosition(double * x, double * y, double * z)
{
if (body != 0)
{
const dReal * pos = dBodyGetPosition(body);
*x = pos[0];
*y = pos[1];
*z = pos[2];
}
}

View File

@ -26,6 +26,8 @@ class Engine
void draw() { glCallList(display_list); }
void loadPhy(const std::string & path,
bool static_data = false);
void setPosition(double x, double y, double z);
void getPosition(double * x, double * y, double * z);
};
Engine();