26 NewtonWorldRayCast( world->
getNewtonWorld(), (
float*)&startpt, (
float*)&endpt, OgreNewt::Raycast::newtonRaycastFilter,
this, OgreNewt::Raycast::newtonRaycastPreFilter, 0);
32 float Raycast::newtonRaycastFilter(
const NewtonBody* body,
const NewtonCollision*
const shapeHit,
const dFloat*
const hitContact,
const dFloat* hitNormal, dLong collisionID,
void* userData, dFloat intersectParam)
37 Body* bod = (
Body*)NewtonBodyGetUserData( body );
39 Ogre::Vector3 normal = Ogre::Vector3( hitNormal[0], hitNormal[1], hitNormal[2] );
43 return intersectParam;
52 if (me->
userCallback( bod, intersectParam, normal, collisionID ))
53 return intersectParam;
59 unsigned Raycast::newtonRaycastPreFilter(
const NewtonBody *body,
const NewtonCollision *collision,
void* userData)
64 Body* bod = (Body*)NewtonBodyGetUserData( body );
65 const World* world = bod->getWorld();
68 me->m_treecollisioncallback_bodyalreadyadded =
false;
69 me->m_treecollisioncallback_lastbody = bod;
71 if (me->userPreFilterCallback( bod ))
76 if( world->getDebugger().isRaycastRecording() && world->getDebugger().isRaycastRecordingHitBodies() )
104 go( world, startpt, endpt, sorted );
115 std::sort(mRayList.begin(), mRayList.end());
131 Ogre::Real dist = Ogre::Math::POS_INFINITY;
133 RaycastInfoList::const_iterator it;
134 for (it = mRayList.begin(); it != mRayList.end(); it++)
136 if (it->mDistance < dist)
150 if (hitnum < mRayList.size())
152 return mRayList.at(hitnum);
167 newinfo.
mBody = body;
172 mRayList.push_back( newinfo );
simple class that represents a single raycast rigid body intersection.
Ogre::Real mDistance
dist from point1 of the raycast, in range [0,1].
OgreNewt::Body * mBody
pointer to body intersected with
Ogre::Vector3 mNormal
normal of intersection.
dLong mCollisionID
collision ID of the primitive hit by the ray (for compound collision bodies)
bool userCallback(Body *body, Ogre::Real distance, const Ogre::Vector3 &normal, dLong collisionID)
the all-important custom callback function.
BasicRaycastInfo getInfoAt(unsigned int hitnum) const
retrieve the raycast info for a specific hit.
int getHitCount() const
how many bodies did we hit?
BasicRaycastInfo getFirstHit() const
get the closest body hit by the ray.
~BasicRaycast()
destuctor.
BasicRaycast()
empty constructor
void go(const OgreNewt::World *world, const Ogre::Vector3 &startpt, const Ogre::Vector3 &endpt, bool sorted)
perform a raycast
main class for all Rigid Bodies in the system.
OgreNewt::World *const getWorld() const
get a pointer to the OgreNewt::World this body belongs to.
bool isRaycastRecording()
returns true, if currently recording raycasts
bool isRaycastRecordingHitBodies()
returns true, if hit bodies are currently recording
void addHitBody(const OgreNewt::Body *body)
this function is used internally
void addDiscardedBody(const OgreNewt::Body *body)
this function is used internally
void addRay(const Ogre::Vector3 &startpt, const Ogre::Vector3 &endpt)
this function is used internally
bool m_treecollisioncallback_bodyalreadyadded
save if this body was already added by RayCastCallback from TreeCollision
OgreNewt::Body * m_treecollisioncallback_lastbody
save the last OgreNewt::Body from the newtonRaycastPreFilter to use this for example the TreeCollisio...
virtual ~Raycast()
destuctor.
virtual bool userCallback(OgreNewt::Body *body, Ogre::Real distance, const Ogre::Vector3 &normal, dLong collisionID)=0
user callback filter function
void go(const OgreNewt::World *world, const Ogre::Vector3 &startpt, const Ogre::Vector3 &endpt)
performs the raycast.
represents a physics world.
Debugger & getDebugger() const
get the debugger for this world
NewtonWorld * getNewtonWorld() const
retrieves a pointer to the NewtonWorld