diff --git a/ag.cc b/ag.cc index 86106ae..d2e52b1 100644 --- a/ag.cc +++ b/ag.cc @@ -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; } } } diff --git a/anaglym.cc b/anaglym.cc index 04546b1..639762b 100644 --- a/anaglym.cc +++ b/anaglym.cc @@ -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]; + } +} diff --git a/anaglym.h b/anaglym.h index 2c77364..be603b3 100644 --- a/anaglym.h +++ b/anaglym.h @@ -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();