Custom needsCollision on raycasts in Bullet Physics

By , last updated June 30, 2019

Implement this class, and use it as an argument when doing raycasts in Bullet Physics

class MyOwnRayResultCallback : public btCollisionWorld::ClosestRayResultCallback
		explicit MyOwnRayResultCallback(const btVector3 &rayFromWorld, const btVector3&	rayToWorld) :
			ClosestRayResultCallback(rayFromWorld, rayToWorld) 
		virtual ~MyOwnRayResultCallback() {}

		virtual bool needsCollision(btBroadphaseProxy* proxy0) const
			btCollisionObject *collobj = static_cast<btCollisionObject*>( proxy0->m_clientObject );
			bullet::Userpointer *userptr = getUserpointer(collobj);

			return false;

Then use it in you application by sending it to btPhysicsWorld.

MyOwnRayResultCallback rayCallback(startPosition, endPosition);
m_PhysicsWorld->rayTest(startPosition, endPosition, rayCallback);

Professional Software Developer, doing mostly C++. Connect with Kent on Twitter.


Be the first to comment.

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>