From 925140f3fbcd9da3e459971ec516cb1a0d061b3e Mon Sep 17 00:00:00 2001 From: josh Date: Mon, 28 Sep 2009 02:32:39 +0000 Subject: [PATCH] replaced setupBody() with setupGeom() git-svn-id: svn://anubis/misc/OdeWorld@151 bd8a9e45-a331-0410-811e-c64571078777 --- OdeWorld.cc | 40 +++++++++++++++++++++++++--------------- OdeWorld.h | 7 ++++++- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/OdeWorld.cc b/OdeWorld.cc index a259028..daafba1 100644 --- a/OdeWorld.cc +++ b/OdeWorld.cc @@ -143,20 +143,15 @@ 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); + setupGeom(name, static_data, body, id, true, + args[3], args[4], args[5], + args[6], args[7], args[8]); return id; } @@ -165,9 +160,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); + setupGeom(name, static_data, body, id, true, + args[1], args[2], args[3], + 0.0, 0.0, 0.0); return id; } @@ -176,9 +172,10 @@ 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); + setupGeom(name, static_data, body, id, true, + args[2], args[3], args[4], + args[5], args[6], args[7]); return id; } @@ -187,9 +184,10 @@ dGeomID OdeWorld::addCCylinder(const string & name, bool static_data, { if (args.size() != 8) return 0; - setupBody(static_data, body); dGeomID id = dCreateCCylinder(m_space, args[0], args[1]); - dGeomSetBody(id, *body); + setupGeom(name, static_data, body, id, true, + args[2], args[3], args[4], + args[5], args[6], args[7]); return id; } @@ -198,10 +196,22 @@ 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); + setupGeom(name, static_data, body, id, false, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); return id; } +void OdeWorld::setupGeom(const std::string & name, bool static_data, + dBodyID * body, dGeomID geom, bool placeable, + float locx, float locy, float locz, + float rotx, float roty, float rotz) +{ + if (placeable && !static_data && *body == 0) + *body = dBodyCreate(m_world); + if (placeable) + dGeomSetBody(geom, *body); + /* TODO: set up mass, location, and rotation */ +} diff --git a/OdeWorld.h b/OdeWorld.h index 3276805..22aab79 100644 --- a/OdeWorld.h +++ b/OdeWorld.h @@ -5,6 +5,7 @@ #include #include #include +#include class OdeWorld { @@ -36,8 +37,12 @@ class OdeWorld dWorldID m_world; dSpaceID m_space; dJointGroupID m_contactJointGroup; + std::map m_objects; - void setupBody(bool static_data, dBodyID * body); + void setupGeom(const std::string & name, bool static_data, + dBodyID * body, dGeomID geom, bool placeable, + float locx, float locy, float locz, + float rotx, float roty, float rotz); }; #endif