I notice that btDynamicsWorld::rayTest works only with Ray-Sphere intersection. So if my objects are Boxes, Cylinders or Cones rayTest says there's no collision at all.
I created some sandbox testing environment like this:
Code: Select all
PhysWorld w(0,-0.0001,0;) // create physics wrapper and set gravity to very small value
btRigidBody* box1, *box2;
btDefaultMotionState ms1, ms2;
//btSphereShape shape(4);
btBoxShape shape(btVector3(4,4,4));
//btCylinderShape shape(btVector3(4,4,4));
//btConeShape shape(4,4);
//btCapsuleShape shape(4,4);
{
btTransform t;
t.setOrigin(btVector3(0,0,0));
ms1.setWorldTransform(t);
RigidBodyDesc desc(&shape, &ms1, 10);
box1 = w.createRigidBody(desc);
}
{
btTransform t;
t.setOrigin(btVector3(0,0,10));
ms2.setWorldTransform(t);
RigidBodyDesc desc(&shape, &ms2, 10);
box2 = w.createRigidBody(desc);
}
Code: Select all
btVector3 from(0,0,0), to(0,0,15);
btCollisionWorld::ClosestRayResultCallback res(from,to);
mWorld->rayTest(from, to, res);
if(res.hasHit()){
printf("collision\n");
}
What to do, if I need other shapes rather then Spheres?
I'm using svn 2321 version of Bullet.