From 05858c0c22c8b408a5d9d13eca4e6939ffee4df5 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 1 Oct 2009 03:38:39 +0000 Subject: [PATCH] filled in Engine::Object::{get,set}Position() git-svn-id: svn://anubis/anaglym/trunk@44 99a6e188-d820-4881-8870-2d33a10e2619 --- ag.cc | 9 ++++++++- anaglym.cc | 19 +++++++++++++++++++ anaglym.h | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) 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();