allowed OdeWorld::Object objects to be initialized with an optional scale param

git-svn-id: svn://anubis/misc/OdeWorld@171 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2009-10-12 21:29:32 +00:00
parent e9d8872826
commit 24774bfe34
2 changed files with 29 additions and 14 deletions

View File

@ -80,9 +80,9 @@ void OdeWorld::step()
dJointGroupEmpty(m_contactJointGroup); dJointGroupEmpty(m_contactJointGroup);
} }
OdeWorld::Object * OdeWorld::createObject(bool is_static) OdeWorld::Object * OdeWorld::createObject(bool is_static, float scale)
{ {
return new Object(is_static, m_world, m_space); return new Object(is_static, m_world, m_space, scale);
} }
/* push an OpenGL matrix onto the matrix stack for a given /* push an OpenGL matrix onto the matrix stack for a given
@ -110,12 +110,14 @@ void OdeWorld::pushTransform(const dReal * pos, const dReal * R)
glMultMatrixf(matrix); glMultMatrixf(matrix);
} }
OdeWorld::Object::Object(bool is_static, dWorldID world, dSpaceID space) OdeWorld::Object::Object(bool is_static, dWorldID world, dSpaceID space,
float scale)
{ {
m_is_static = is_static; m_is_static = is_static;
m_world = world; m_world = world;
m_space = space; m_space = space;
m_body = 0; m_body = 0;
m_scale = scale;
dMassSetZero(&m_mass); dMassSetZero(&m_mass);
} }
@ -124,6 +126,7 @@ OdeWorld::Object::Object(const OdeWorld::Object & orig)
m_is_static = orig.m_is_static; m_is_static = orig.m_is_static;
m_world = orig.m_world; m_world = orig.m_world;
m_space = orig.m_space; m_space = orig.m_space;
m_scale = orig.m_scale;
/* make a copy of the ODE body */ /* make a copy of the ODE body */
if (orig.m_body != 0) if (orig.m_body != 0)
{ {
@ -359,9 +362,15 @@ void OdeWorld::Object::addCube(const vector<float> args)
{ {
if (args.size() != 9) if (args.size() != 9)
return; return;
dGeomID id = dCreateBox(0, args[0], args[1], args[2]); dGeomID id = dCreateBox(0,
m_scale * args[0],
m_scale * args[1],
m_scale * args[2]);
dMass mass; dMass mass;
dMassSetBox(&mass, 1.0, args[0], args[1], args[2]); dMassSetBox(&mass, 1.0,
m_scale * args[0],
m_scale * args[1],
m_scale * args[2]);
setupGeom(id, &mass, setupGeom(id, &mass,
args[3], args[4], args[5], args[3], args[4], args[5],
args[6], args[7], args[8]); args[6], args[7], args[8]);
@ -371,9 +380,9 @@ void OdeWorld::Object::addSphere(const vector<float> args)
{ {
if (args.size() != 4) if (args.size() != 4)
return; return;
dGeomID id = dCreateSphere(0, args[0]); dGeomID id = dCreateSphere(0, m_scale * args[0]);
dMass mass; dMass mass;
dMassSetSphere(&mass, 1.0, args[0]); dMassSetSphere(&mass, 1.0, m_scale * args[0]);
setupGeom(id, &mass, setupGeom(id, &mass,
args[1], args[2], args[3], args[1], args[2], args[3],
0.0, 0.0, 0.0); 0.0, 0.0, 0.0);
@ -383,9 +392,9 @@ void OdeWorld::Object::addCylinder(const vector<float> args)
{ {
if (args.size() != 8) if (args.size() != 8)
return; return;
dGeomID id = dCreateCylinder(0, args[0], args[1]); dGeomID id = dCreateCylinder(0, m_scale * args[0], m_scale * args[1]);
dMass mass; dMass mass;
dMassSetCylinder(&mass, 1.0, 3, args[0], args[1]); dMassSetCylinder(&mass, 1.0, 3, m_scale * args[0], m_scale * args[1]);
setupGeom(id, &mass, setupGeom(id, &mass,
args[2], args[3], args[4], args[2], args[3], args[4],
args[5], args[6], args[7]); args[5], args[6], args[7]);
@ -395,9 +404,9 @@ void OdeWorld::Object::addCCylinder(const vector<float> args)
{ {
if (args.size() != 8) if (args.size() != 8)
return; return;
dGeomID id = dCreateCCylinder(0, args[0], args[1]); dGeomID id = dCreateCCylinder(0, m_scale * args[0], m_scale * args[1]);
dMass mass; dMass mass;
dMassSetCappedCylinder(&mass, 1.0, 3, args[0], args[1]); dMassSetCappedCylinder(&mass, 1.0, 3, m_scale * args[0], m_scale * args[1]);
setupGeom(id, &mass, setupGeom(id, &mass,
args[2], args[3], args[4], args[2], args[3], args[4],
args[5], args[6], args[7]); args[5], args[6], args[7]);
@ -417,7 +426,7 @@ void OdeWorld::Object::addPlane(const vector<float> args)
float a = rotated_plane_direction[0]; float a = rotated_plane_direction[0];
float b = rotated_plane_direction[1]; float b = rotated_plane_direction[1];
float c = rotated_plane_direction[2]; float c = rotated_plane_direction[2];
float d = a * args[0] + b * args[1] + c * args[2]; float d = m_scale * (a * args[0] + b * args[1] + c * args[2]);
dGeomID id = dCreatePlane(m_space, a, b, c, d); dGeomID id = dCreatePlane(m_space, a, b, c, d);
m_geoms.push_back(id); m_geoms.push_back(id);
@ -427,6 +436,10 @@ void OdeWorld::Object::setupGeom(dGeomID geom, dMass * mass,
float locx, float locy, float locz, float locx, float locy, float locz,
float rotx, float roty, float rotz) float rotx, float roty, float rotz)
{ {
locx = m_scale * locx;
locy = m_scale * locy;
locz = m_scale * locz;
dMatrix3 rot; dMatrix3 rot;
dRFromEulerAngles(rot, rotx, roty, rotz); dRFromEulerAngles(rot, rotx, roty, rotz);
dGeomSetRotation(geom, rot); dGeomSetRotation(geom, rot);

View File

@ -16,7 +16,8 @@ class OdeWorld
class Object class Object
{ {
public: public:
Object(bool is_static, dWorldID world, dSpaceID space); Object(bool is_static, dWorldID world, dSpaceID space,
float scale = 1.0f);
Object(const Object & orig); Object(const Object & orig);
~Object(); ~Object();
@ -40,6 +41,7 @@ class OdeWorld
dWorldID m_world; dWorldID m_world;
dSpaceID m_space; dSpaceID m_space;
std::vector<dGeomID> m_geoms; std::vector<dGeomID> m_geoms;
float m_scale;
void setupGeom(dGeomID geom, dMass * mass, void setupGeom(dGeomID geom, dMass * mass,
float locx, float locy, float locz, float locx, float locy, float locz,
@ -47,7 +49,7 @@ class OdeWorld
dGeomID cloneGeom(dGeomID geom, dBodyID body); dGeomID cloneGeom(dGeomID geom, dBodyID body);
}; };
Object * createObject(bool is_static); Object * createObject(bool is_static, float scale = 1.0f);
void setGravity(float x, float y, float z) void setGravity(float x, float y, float z)
{ {
dWorldSetGravity(m_world, x, y, z); dWorldSetGravity(m_world, x, y, z);