From ccb6708633d359e15bd0ee2ff6c5b42d271de665 Mon Sep 17 00:00:00 2001 From: josh Date: Thu, 8 Oct 2009 04:11:43 +0000 Subject: [PATCH] added createObject() factory method, get position/rotation functions for Objects git-svn-id: svn://anubis/misc/OdeWorld@162 bd8a9e45-a331-0410-811e-c64571078777 --- OdeWorld.cc | 31 +++++++++++++++++++++++++++++++ OdeWorld.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/OdeWorld.cc b/OdeWorld.cc index acacaa0..ca0a03f 100644 --- a/OdeWorld.cc +++ b/OdeWorld.cc @@ -80,6 +80,11 @@ void OdeWorld::step() dJointGroupEmpty(m_contactJointGroup); } +OdeWorld::Object * OdeWorld::createObject(bool is_static) +{ + return new Object(is_static, m_world, m_space); +} + /* push an OpenGL matrix onto the matrix stack for a given * ODE body position and rotation */ void OdeWorld::pushTransform(const float pos[3], const float R[12]) @@ -306,3 +311,29 @@ void OdeWorld::Object::setupGeom(dGeomID geom, dMass * mass, dBodySetMass(m_body, &origmass); } } + +const dReal * OdeWorld::Object::getPosition() +{ + if (m_body != NULL) + { + return dBodyGetPosition(m_body); + } + else if (m_geoms.size() > 0) + { + return dGeomGetPosition(m_geoms[0]); + } + return NULL; +} + +const dReal * OdeWorld::Object::getRotation() +{ + if (m_body != NULL) + { + return dBodyGetRotation(m_body); + } + else if (m_geoms.size() > 0) + { + return dGeomGetRotation(m_geoms[0]); + } + return NULL; +} diff --git a/OdeWorld.h b/OdeWorld.h index 60b6773..ee190d1 100644 --- a/OdeWorld.h +++ b/OdeWorld.h @@ -21,6 +21,8 @@ class OdeWorld void loadPhy(const std::string & path); void setPosition(double x, double y, double z); void getPosition(double * x, double * y, double * z); + const dReal * getPosition(); + const dReal * getRotation(); std::vector loadPhy(const std::string & path, dBodyID * body, bool is_static = false); void addCube(const std::vector args); @@ -42,6 +44,7 @@ class OdeWorld }; + Object * createObject(bool is_static); void setGravity(float x, float y, float z) { dWorldSetGravity(m_world, x, y, z);