filling out the add*() functions more

git-svn-id: svn://anubis/misc/OdeWorld@150 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2009-09-28 02:24:28 +00:00
parent d234e0147f
commit a60a729b49
2 changed files with 38 additions and 0 deletions

View File

@ -143,11 +143,21 @@ vector<dGeomID> OdeWorld::loadPhy(const std::string & path,
return ret; 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, dGeomID OdeWorld::addCube(const string & name, bool static_data,
dBodyID * body, const vector<float> args) dBodyID * body, const vector<float> args)
{ {
if (args.size() != 9) if (args.size() != 9)
return 0; 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, 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) if (args.size() != 4)
return 0; 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, 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) if (args.size() != 8)
return 0; 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<float> 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, 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) if (args.size() != 6)
return 0; 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;
} }

View File

@ -24,6 +24,8 @@ class OdeWorld
dBodyID * body, const std::vector<float> args); dBodyID * body, const std::vector<float> args);
dGeomID addCylinder(const std::string & name, bool static_data, dGeomID addCylinder(const std::string & name, bool static_data,
dBodyID * body, const std::vector<float> args); dBodyID * body, const std::vector<float> args);
dGeomID addCCylinder(const std::string & name, bool static_data,
dBodyID * body, const std::vector<float> args);
dGeomID addPlane(const std::string & name, bool static_data, dGeomID addPlane(const std::string & name, bool static_data,
dBodyID * body, const std::vector<float> args); dBodyID * body, const std::vector<float> args);
@ -34,6 +36,8 @@ class OdeWorld
dWorldID m_world; dWorldID m_world;
dSpaceID m_space; dSpaceID m_space;
dJointGroupID m_contactJointGroup; dJointGroupID m_contactJointGroup;
void setupBody(bool static_data, dBodyID * body);
}; };
#endif #endif