newbie's question

User avatar
sjinny
Posts: 11
Joined: Tue Apr 24, 2007 6:20 am

newbie's question

Post by sjinny »

i want to use a rigid body to control the camera's moving and collision. And i want the camera collides with other things but the other things wont be effected by the camera.
the manual says the demo "Gjk Convex Cast / Sweep Demo" shows something like what i need but i can't understand the codes.
How should i make my camera rigid body ? Thanks~~
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

You can use a convex-cast from the look-at point backwards to find a collision-free path.

Easiest is probably to use the raycast/sphere cast in btCollisionWorld. Currently it doesn't allow to specify the sphere-radius in the interface, so you will need to manually call the 'rayCastSingle' for each individual object in the world/closeby.

Code: Select all

void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans,
					  btCollisionObject* collisionObject,
					  const btCollisionShape* collisionShape,
					  const btTransform& colObjWorldTransform,
					  RayResultCallback& resultCallback)
{
	
	btSphereShape pointShape(btScalar(0.0));
	pointShape.setMargin(0.f);
....
}
You can change the pointShape radius to be larger (and fit the camera), or use a convex shape to approximate the camera better.

When a character demo will be added to Bullet, I will add a camera collision sample too.

Hope this helps,
Erwin