supported setting/getting a position/rotation for ODE objects with neither a body nor a geometry so that they can still be drawn in a certain orientation even if they do not participate in physics at all
git-svn-id: svn://anubis/misc/OdeWorld@182 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
parent
24774bfe34
commit
816e04f68f
94
OdeWorld.cc
94
OdeWorld.cc
@ -119,6 +119,11 @@ OdeWorld::Object::Object(bool is_static, dWorldID world, dSpaceID space,
|
||||
m_body = 0;
|
||||
m_scale = scale;
|
||||
dMassSetZero(&m_mass);
|
||||
for (int i = 0; i < 3; i++)
|
||||
m_position[i] = 0.0;
|
||||
for (int j = 0; j < 3; j++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
m_rotation[j * 4 + i] = (j == i) ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
OdeWorld::Object::Object(const OdeWorld::Object & orig)
|
||||
@ -127,6 +132,10 @@ OdeWorld::Object::Object(const OdeWorld::Object & orig)
|
||||
m_world = orig.m_world;
|
||||
m_space = orig.m_space;
|
||||
m_scale = orig.m_scale;
|
||||
for (int i = 0; i < 3; i++)
|
||||
m_position[i] = orig.m_position[i];
|
||||
for (int i = 0; i < 12; i++)
|
||||
m_rotation[i] = orig.m_rotation[i];
|
||||
/* make a copy of the ODE body */
|
||||
if (orig.m_body != 0)
|
||||
{
|
||||
@ -259,42 +268,6 @@ dGeomID OdeWorld::Object::cloneGeom(dGeomID geom, dBodyID body)
|
||||
return id;
|
||||
}
|
||||
|
||||
void OdeWorld::Object::setPosition(double x, double y, double z)
|
||||
{
|
||||
if (m_is_static)
|
||||
{
|
||||
for (int i = 0, sz = m_geoms.size(); i < sz; i++)
|
||||
dGeomSetPosition(m_geoms[i], x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_body != 0)
|
||||
dBodySetPosition(m_body, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
void OdeWorld::Object::getPosition(double * x, double * y, double * z)
|
||||
{
|
||||
const dReal * pos = NULL;
|
||||
if (m_is_static)
|
||||
{
|
||||
if (m_geoms.size() > 0)
|
||||
pos = dGeomGetPosition(m_geoms[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_body != 0)
|
||||
pos = dBodyGetPosition(m_body);
|
||||
}
|
||||
|
||||
if (pos != NULL)
|
||||
{
|
||||
*x = pos[0];
|
||||
*y = pos[1];
|
||||
*z = pos[2];
|
||||
}
|
||||
}
|
||||
|
||||
void OdeWorld::Object::loadPhy(const std::string & path)
|
||||
{
|
||||
ifstream ifs(path.c_str());
|
||||
@ -476,7 +449,7 @@ const dReal * OdeWorld::Object::getPosition()
|
||||
{
|
||||
return dGeomGetPosition(m_geoms[0]);
|
||||
}
|
||||
return NULL;
|
||||
return m_position;
|
||||
}
|
||||
|
||||
const dReal * OdeWorld::Object::getRotation()
|
||||
@ -489,5 +462,50 @@ const dReal * OdeWorld::Object::getRotation()
|
||||
{
|
||||
return dGeomGetRotation(m_geoms[0]);
|
||||
}
|
||||
return NULL;
|
||||
return m_rotation;
|
||||
}
|
||||
|
||||
void OdeWorld::Object::setPosition(double x, double y, double z)
|
||||
{
|
||||
if (m_is_static)
|
||||
{
|
||||
for (int i = 0, sz = m_geoms.size(); i < sz; i++)
|
||||
dGeomSetPosition(m_geoms[i], x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_body != 0)
|
||||
dBodySetPosition(m_body, x, y, z);
|
||||
}
|
||||
m_position[0] = x;
|
||||
m_position[1] = y;
|
||||
m_position[2] = z;
|
||||
}
|
||||
|
||||
void OdeWorld::Object::getPosition(double * x, double * y, double * z)
|
||||
{
|
||||
const dReal * pos = NULL;
|
||||
if (m_is_static)
|
||||
{
|
||||
if (m_geoms.size() > 0)
|
||||
pos = dGeomGetPosition(m_geoms[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_body != 0)
|
||||
pos = dBodyGetPosition(m_body);
|
||||
}
|
||||
|
||||
if (pos != NULL)
|
||||
{
|
||||
*x = pos[0];
|
||||
*y = pos[1];
|
||||
*z = pos[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
*x = m_position[0];
|
||||
*y = m_position[1];
|
||||
*z = m_position[2];
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ class OdeWorld
|
||||
dSpaceID m_space;
|
||||
std::vector<dGeomID> m_geoms;
|
||||
float m_scale;
|
||||
dReal m_position[3];
|
||||
dReal m_rotation[12];
|
||||
|
||||
void setupGeom(dGeomID geom, dMass * mass,
|
||||
float locx, float locy, float locz,
|
||||
|
Loading…
x
Reference in New Issue
Block a user