[Opal-commits] opal/src/ODE ODESimulator.cpp,1.86,1.87 ODESimulator.h,1.59,1.60
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-03-09 02:10:01
|
Update of /cvsroot/opal/opal/src/ODE In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11688/src/ODE Modified Files: ODESimulator.cpp ODESimulator.h Log Message: added a RaycastSensor, which replaces the old Simulator ray casting functions Index: ODESimulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/ODE/ODESimulator.h,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** ODESimulator.h 8 Mar 2005 22:05:05 -0000 1.59 --- ODESimulator.h 9 Mar 2005 02:09:50 -0000 1.60 *************** *** 32,35 **** --- 32,36 ---- #include "../Defines.h" #include "../Simulator.h" + #include "../RaycastSensor.h" #include "ODESolid.h" #include "ODEJoint.h" *************** *** 56,59 **** --- 57,62 ---- ODESimulator(); + virtual ~ODESimulator(); + virtual void OPAL_CALL destroy(); *************** *** 77,83 **** // std::vector<Solid*>* solids); - virtual RaycastResult OPAL_CALL shootRay(const Point3r& origin, - const Vec3r& dir, real length); - virtual void OPAL_CALL setGravity(const Vec3r& gravity); --- 80,83 ---- *************** *** 88,106 **** virtual void OPAL_CALL internal_stepPhysics(); ! dWorldID OPAL_CALL internal_getWorldID()const; ! dSpaceID OPAL_CALL internal_getSpaceID()const; ! dJointGroupID OPAL_CALL internal_getJointGroupID()const; /// Helper function for volume collision checking. void OPAL_CALL internal_addCollidedSolid(Solid* solid); ! /// Helper function for ray casting. ! void OPAL_CALL internal_setRaycastResult(Solid* solid, const Point3r& intersection, const Vec3r& normal, real distance); protected: - virtual ~ODESimulator(); /// The ODE world ID used by this Simulator. --- 88,108 ---- virtual void OPAL_CALL internal_stepPhysics(); ! virtual dWorldID OPAL_CALL internal_getWorldID()const; ! virtual dSpaceID OPAL_CALL internal_getSpaceID()const; ! virtual dJointGroupID OPAL_CALL internal_getJointGroupID()const; /// Helper function for volume collision checking. void OPAL_CALL internal_addCollidedSolid(Solid* solid); ! virtual const RaycastResult& OPAL_CALL internal_fireRay( ! const Rayr& r); ! ! /// Helper function used for ray casting. ! virtual void OPAL_CALL internal_setRaycastResult(Solid* solid, const Point3r& intersection, const Vec3r& normal, real distance); protected: /// The ODE world ID used by this Simulator. Index: ODESimulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/ODE/ODESimulator.cpp,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** ODESimulator.cpp 8 Mar 2005 22:05:04 -0000 1.86 --- ODESimulator.cpp 9 Mar 2005 02:09:50 -0000 1.87 *************** *** 812,816 **** //helper function for collision callback ! //void createOneSidedContact)dJointID contactJoint, dBodyID movingObject, // dBodyID staticObject, dVector3 pos) //{ --- 812,816 ---- //helper function for collision callback ! //void createOneSidedContact(dJointID contactJoint, dBodyID movingObject, // dBodyID staticObject, dVector3 pos) //{ *************** *** 846,850 **** Joint* ODESimulator::createJoint() ! { Joint* newJoint = new ODEJoint(mWorldID); addJoint(newJoint); --- 846,850 ---- Joint* ODESimulator::createJoint() ! { Joint* newJoint = new ODEJoint(mWorldID); addJoint(newJoint); *************** *** 852,855 **** --- 852,887 ---- } + const RaycastResult& ODESimulator::internal_fireRay(const Rayr& r) + { + Point3r origin = r.getOrigin(); + real length = r.getLength(); + Vec3r dir = r.getDir(); + + // Normalized the vector if possible. + if (0 != length) + { + dir.normalize(); + } + + mRaycastResult.solid = NULL; + mRaycastResult.intersection.set(0,0,0); + mRaycastResult.normal.set(1,0,0); + mRaycastResult.distance = 0; + + dGeomID rayGeomID = dCreateRay(mRootSpaceID, length); + dGeomRaySet(rayGeomID, origin[0], origin[1], origin[2], dir[0], + dir[1], dir[2]); + + // Check for collisions. This will fill mRaycastResult with valid + // data. Its Solid pointer will remain NULL if nothing was hit. + dSpaceCollide2(rayGeomID, (dGeomID)mRootSpaceID, this, + &ode_hidden::internal_raycastCollisionCallback); + + // Finished with ODE ray, so destroy it. + dGeomDestroy(rayGeomID); + + return mRaycastResult; + } + //void ODESimulator::collide(const Solid* solid, std::vector<Solid*>* solids) //{ *************** *** 879,910 **** //} - RaycastResult ODESimulator::shootRay(const Point3r& origin, - const Vec3r& dir, real length) - { - mRaycastResult.solid = NULL; - mRaycastResult.intersection.set(0,0,0); - mRaycastResult.normal.set(1,0,0); - mRaycastResult.distance = 0; - - dGeomID rayGeomID = dCreateRay(mRootSpaceID, length); - dGeomRaySet(rayGeomID, origin[0], origin[1], origin[2], dir[0], - dir[1], dir[2]); - - //check for collisions; this will fill mRaycastResult (if a collision occurs) - dSpaceCollide2(rayGeomID, (dGeomID)mRootSpaceID, this, - &ode_hidden::internal_raycastCollisionCallback); - - RaycastResult result; - result.solid = mRaycastResult.solid; //note that this may remain NULL - result.intersection = mRaycastResult.intersection; - result.normal = mRaycastResult.normal; - result.distance = mRaycastResult.distance; - - // Finished with ODE ray, so destroy it. - dGeomDestroy(rayGeomID); - - return result; - } - void ODESimulator::setGravity(const Vec3r& gravity) { --- 911,914 ---- |