changed OdeWorld::pickObjects to return distance, position, and normal information along with object identifier

git-svn-id: svn://anubis/misc/OdeWorld@240 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2010-09-16 21:12:47 +00:00
parent 24140708e3
commit 95045f6470
2 changed files with 20 additions and 29 deletions

View File

@ -47,7 +47,7 @@ void OdeWorld_pick_collide_callback(void * data, dGeomID o1, dGeomID o2)
{
dGeomID other = o1 == ow->m_pick_ray ? o2 : o1;
ow->m_pick_points.push_back(
new OdeWorld::PickedGeom(other, contact_geom.depth));
new OdeWorld::PickedObject(other, contact_geom));
}
}
@ -140,13 +140,13 @@ dJointID OdeWorld::createHinge(dBodyID b1, dBodyID b2,
return j;
}
static bool RPPickedGeomComparator(const refptr<OdeWorld::PickedGeom> & one,
const refptr<OdeWorld::PickedGeom> & two)
static bool RPPickedObjectComparator(const refptr<OdeWorld::PickedObject> & one,
const refptr<OdeWorld::PickedObject> & two)
{
return one->dist < two->dist;
}
refptr< vector<OdeWorld::Object *> > OdeWorld::pickObjects(
refptr< vector< OdeWorld::PickedObjectRef > > OdeWorld::pickObjects(
float start_x, float start_y, float start_z,
float dir_x, float dir_y, float dir_z)
{
@ -156,15 +156,8 @@ refptr< vector<OdeWorld::Object *> > OdeWorld::pickObjects(
dSpaceCollide2(m_pick_ray, (dGeomID) m_space,
this, OdeWorld_pick_collide_callback);
std::sort(m_pick_points.begin(), m_pick_points.end(),
RPPickedGeomComparator);
refptr< vector<Object *> > ret = new vector<Object *>();
for (vector< refptr<PickedGeom> >::const_iterator it = m_pick_points.begin();
it != m_pick_points.end();
it++)
{
ret->push_back((Object *) dGeomGetData((*it)->geom));
}
return ret;
RPPickedObjectComparator);
return new vector<OdeWorld::PickedObjectRef>(m_pick_points);
}
void OdeWorld::destroyBody(dBodyID body)

View File

@ -76,29 +76,27 @@ class OdeWorld
dGeomID cloneGeom(dGeomID geom, dBodyID body);
};
class PickedGeom
{
public:
dGeomID geom;
float dist;
PickedGeom(dGeomID g, float d)
: geom(g), dist(d)
{
}
};
class PickedObject
{
public:
Object * obj;
float dist;
float pos[3];
float normal[3];
PickedObject(Object * obj, float dist)
: obj(obj), dist(dist)
PickedObject(dGeomID geom, dContactGeom & contact)
{
obj = (Object *) dGeomGetData(geom);
dist = contact.depth;
pos[0] = contact.pos[0];
pos[1] = contact.pos[1];
pos[2] = contact.pos[2];
normal[0] = contact.normal[0];
normal[1] = contact.normal[1];
normal[2] = contact.normal[2];
}
};
typedef refptr<PickedObject> PickedObjectRef;
OdeWorld();
~OdeWorld();
@ -174,7 +172,7 @@ class OdeWorld
#endif
dJointSetAMotorParam(j, dParamBounce, val);
}
refptr< std::vector<Object *> > pickObjects(
refptr< std::vector<PickedObjectRef> > pickObjects(
float start_x, float start_y, float start_z,
float dir_x, float dir_y, float dir_z);
@ -195,7 +193,7 @@ class OdeWorld
dJointGroupID m_contactJointGroup;
std::map<dBodyID, int> m_bodies;
dGeomID m_pick_ray;
std::vector< refptr<PickedGeom> > m_pick_points;
std::vector< refptr<PickedObject> > m_pick_points;
};
#endif