From 95045f64707b902a3d4f2f1affd797553947fed6 Mon Sep 17 00:00:00 2001 From: josh Date: Thu, 16 Sep 2010 21:12:47 +0000 Subject: [PATCH] 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 --- OdeWorld.cc | 19 ++++++------------- OdeWorld.h | 30 ++++++++++++++---------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/OdeWorld.cc b/OdeWorld.cc index a472bd3..b812640 100644 --- a/OdeWorld.cc +++ b/OdeWorld.cc @@ -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 & one, - const refptr & two) +static bool RPPickedObjectComparator(const refptr & one, + const refptr & two) { return one->dist < two->dist; } -refptr< vector > 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::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 > ret = new vector(); - for (vector< refptr >::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(m_pick_points); } void OdeWorld::destroyBody(dBodyID body) diff --git a/OdeWorld.h b/OdeWorld.h index 543d695..dedf6c7 100644 --- a/OdeWorld.h +++ b/OdeWorld.h @@ -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 PickedObjectRef; OdeWorld(); ~OdeWorld(); @@ -174,7 +172,7 @@ class OdeWorld #endif dJointSetAMotorParam(j, dParamBounce, val); } - refptr< std::vector > pickObjects( + refptr< std::vector > 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 m_bodies; dGeomID m_pick_ray; - std::vector< refptr > m_pick_points; + std::vector< refptr > m_pick_points; }; #endif