0
\$\begingroup\$

I added some boxes in a collision world, then use btCollisionWorld::contactTest to test if any box contact with a given sphere. Below is the code:

    int SpacePhysics::SphereContactTest(const btVector3 &center, btScalar radius) {
        btSphereShape *sphere_shape = new btSphereShape(radius);
        btCollisionObject *sphere = new btCollisionObject();
        sphere->setCollisionShape(sphere_shape);
        sphere->setWorldTransform(btTransform(btQuaternion(), center));
        collision_world_->contactTest(sphere, result_callback);
        delete sphere;
        delete sphere_shape;
        return result_callback.hit_count;
    }

However no contact can be detected(when it should), if I use btCollisionWorld::contactPairTest to test the sphere with all the collision objects in the world, the contacts can be detected. But using btCollisionWorld::contactTest nothing can be detected. What's the proper way to use btCollisionWorld::contactTest?

\$\endgroup\$
1
\$\begingroup\$

Found the reason:

sphere->setWorldTransform(btTransform(btQuaternion(), center));

set the sphere with a invalid transform, therefore no collision can be detect. Although I don't understand why contactPairTest can still detect collision.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.