From a60a729b496ed1a872cebe319e1203c0b6c5022a Mon Sep 17 00:00:00 2001 From: josh Date: Mon, 28 Sep 2009 02:24:28 +0000 Subject: [PATCH] filling out the add*() functions more git-svn-id: svn://anubis/misc/OdeWorld@150 bd8a9e45-a331-0410-811e-c64571078777 --- OdeWorld.cc | 34 ++++++++++++++++++++++++++++++++++ OdeWorld.h | 4 ++++ 2 files changed, 38 insertions(+) diff --git a/OdeWorld.cc b/OdeWorld.cc index e163857..a259028 100644 --- a/OdeWorld.cc +++ b/OdeWorld.cc @@ -143,11 +143,21 @@ vector OdeWorld::loadPhy(const std::string & path, return ret; } +void OdeWorld::setupBody(bool static_data, dBodyID * body) +{ + if (!static_data && *body == 0) + *body = dBodyCreate(m_world); +} + dGeomID OdeWorld::addCube(const string & name, bool static_data, dBodyID * body, const vector args) { if (args.size() != 9) return 0; + setupBody(static_data, body); + dGeomID id = dCreateBox(m_space, args[0], args[1], args[2]); + dGeomSetBody(id, *body); + return id; } dGeomID OdeWorld::addSphere(const string & name, bool static_data, @@ -155,6 +165,10 @@ dGeomID OdeWorld::addSphere(const string & name, bool static_data, { if (args.size() != 4) return 0; + setupBody(static_data, body); + dGeomID id = dCreateSphere(m_space, args[0]); + dGeomSetBody(id, *body); + return id; } dGeomID OdeWorld::addCylinder(const string & name, bool static_data, @@ -162,6 +176,21 @@ dGeomID OdeWorld::addCylinder(const string & name, bool static_data, { if (args.size() != 8) return 0; + setupBody(static_data, body); + dGeomID id = dCreateCylinder(m_space, args[0], args[1]); + dGeomSetBody(id, *body); + return id; +} + +dGeomID OdeWorld::addCCylinder(const string & name, bool static_data, + dBodyID * body, const vector args) +{ + if (args.size() != 8) + return 0; + setupBody(static_data, body); + dGeomID id = dCreateCCylinder(m_space, args[0], args[1]); + dGeomSetBody(id, *body); + return id; } dGeomID OdeWorld::addPlane(const string & name, bool static_data, @@ -169,5 +198,10 @@ dGeomID OdeWorld::addPlane(const string & name, bool static_data, { if (args.size() != 6) return 0; + setupBody(static_data, body); + float a, b, c, d; + /* TODO: find a, b, c, d from args */ + dGeomID id = dCreatePlane(m_space, a, b, c, d); + return id; } diff --git a/OdeWorld.h b/OdeWorld.h index ac4d7a2..3276805 100644 --- a/OdeWorld.h +++ b/OdeWorld.h @@ -24,6 +24,8 @@ class OdeWorld dBodyID * body, const std::vector args); dGeomID addCylinder(const std::string & name, bool static_data, dBodyID * body, const std::vector args); + dGeomID addCCylinder(const std::string & name, bool static_data, + dBodyID * body, const std::vector args); dGeomID addPlane(const std::string & name, bool static_data, dBodyID * body, const std::vector args); @@ -34,6 +36,8 @@ class OdeWorld dWorldID m_world; dSpaceID m_space; dJointGroupID m_contactJointGroup; + + void setupBody(bool static_data, dBodyID * body); }; #endif