[Solved]Ghost object is allways in collision
Posted: Tue Oct 06, 2015 8:37 am
Hello everybody!
Ok, so i've implemented bullet for rigid body simulation, and it works perfectly. The problem is, that when i add a ghost object to the dynamic world, it shows me that it's always intersecting with something, even when I move it way outside of other objects aabb's.
For start, I do this initialisation:
broadphase = new btDbvtBroadphase();
broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
collision_config = new btDefaultCollisionConfiguration();
collision_dispatcher = new btCollisionDispatcher(collision_config);
dispatcher_info= new btDispatcherInfo();
constraint_solver = new btSequentialImpulseConstraintSolver;
dynamics_world = new btDiscreteDynamicsWorld(collision_dispatcher,broadphase,constraint_solver,collision_config);
the ghost object is created as follows:
ghost_object[0] = new btPairCachingGhostObject();
collision_shape= new btBoxShape(half_extents);
ghost_object[0]->setCollisionShape(collision_shape);
btTransform bullet_matrix;
bullet_matrix.setOrigin(btVector3(5,5,0));
ghost_object[0]->setWorldTransform(bullet_matrix);
ghost_object[0]->setCollisionFlags(ghost_object[0]->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE );
ghost_object[0]->setUserIndex(33); dynamics_world->addCollisionObject(ghost_object[0],btBroadphaseProxy::SensorTrigger,btBroadphaseProxy::StaticFilter);
It doesn't matter if the collision shape is bigger or smaller, it always detects that it is in collision with all the objects of the given filter (static objects in this case).
I tried implementing the static objects, as boxes, static planes, and triangle meshes, i get the same result.
What I found strange, is that if I look at the proxy of the ghost object, it's aabbMin and aabbMax are very, very large negative and positive values respectively.
Also, I tried:
dynamics_world->updateAabbs();
dynamics_world->getBroadphase()->calculateOverlappingPairs(dynamics_world->getDispatcher());
but sadly, with the same result.
What I need is a ghost object that I can move with the character so that it will detect when a wall is in front of him, but for starters, I need to know how to set up the ghost object so that it only detects what is colliding with it's aabb.
Also, if I use only a collision object (no ghost) i get the exact same results.
if I move the collision object with the character, it detects collision propperly the first time, only that after that is says that it's colliding continously, until I exit the aabb of the static object.
The character is a dynamic rigid body which I control with forces and impulses. After each physics tic, I update the collision object's transform acordingly
The tick callback:
btManifoldArray manifoldArray;
btBroadphasePairArray& pairArray =
ghost_object->getOverlappingPairCache()->getOverlappingPairArray();
int numPairs = pairArray.size();
for (int i = 0; i < numPairs; ++i)
{
manifoldArray.clear();
const btBroadphasePair& pair = pairArray;
btBroadphasePair* collisionPair =
dynamics_world->getPairCache()->findPair(
pair.m_pProxy0,pair.m_pProxy1);
if (!collisionPair) continue;
if (collisionPair->m_algorithm)
collisionPair->m_algorithm->getAllContactManifolds(manifoldArray);
for (int j=0;j<manifoldArray.size();j++)
{
btPersistentManifold* manifold = manifoldArray[j];
bool isFirstBody = manifold->getBody0() == ghost_object;
bool isSecondBody = manifold->getBody1() == ghost_object;
if (isFirstBody || isSecondBody)
manifold_nr = manifold->getNumContacts();
}
}
nr = ghost_object->getNumOverlappingObjects(); // this allways returns something different from 0
I thank you for your time!
Ok, so i've implemented bullet for rigid body simulation, and it works perfectly. The problem is, that when i add a ghost object to the dynamic world, it shows me that it's always intersecting with something, even when I move it way outside of other objects aabb's.
For start, I do this initialisation:
broadphase = new btDbvtBroadphase();
broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
collision_config = new btDefaultCollisionConfiguration();
collision_dispatcher = new btCollisionDispatcher(collision_config);
dispatcher_info= new btDispatcherInfo();
constraint_solver = new btSequentialImpulseConstraintSolver;
dynamics_world = new btDiscreteDynamicsWorld(collision_dispatcher,broadphase,constraint_solver,collision_config);
the ghost object is created as follows:
ghost_object[0] = new btPairCachingGhostObject();
collision_shape= new btBoxShape(half_extents);
ghost_object[0]->setCollisionShape(collision_shape);
btTransform bullet_matrix;
bullet_matrix.setOrigin(btVector3(5,5,0));
ghost_object[0]->setWorldTransform(bullet_matrix);
ghost_object[0]->setCollisionFlags(ghost_object[0]->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE );
ghost_object[0]->setUserIndex(33); dynamics_world->addCollisionObject(ghost_object[0],btBroadphaseProxy::SensorTrigger,btBroadphaseProxy::StaticFilter);
It doesn't matter if the collision shape is bigger or smaller, it always detects that it is in collision with all the objects of the given filter (static objects in this case).
I tried implementing the static objects, as boxes, static planes, and triangle meshes, i get the same result.
What I found strange, is that if I look at the proxy of the ghost object, it's aabbMin and aabbMax are very, very large negative and positive values respectively.
Also, I tried:
dynamics_world->updateAabbs();
dynamics_world->getBroadphase()->calculateOverlappingPairs(dynamics_world->getDispatcher());
but sadly, with the same result.
What I need is a ghost object that I can move with the character so that it will detect when a wall is in front of him, but for starters, I need to know how to set up the ghost object so that it only detects what is colliding with it's aabb.
Also, if I use only a collision object (no ghost) i get the exact same results.
if I move the collision object with the character, it detects collision propperly the first time, only that after that is says that it's colliding continously, until I exit the aabb of the static object.
The character is a dynamic rigid body which I control with forces and impulses. After each physics tic, I update the collision object's transform acordingly
The tick callback:
btManifoldArray manifoldArray;
btBroadphasePairArray& pairArray =
ghost_object->getOverlappingPairCache()->getOverlappingPairArray();
int numPairs = pairArray.size();
for (int i = 0; i < numPairs; ++i)
{
manifoldArray.clear();
const btBroadphasePair& pair = pairArray;
btBroadphasePair* collisionPair =
dynamics_world->getPairCache()->findPair(
pair.m_pProxy0,pair.m_pProxy1);
if (!collisionPair) continue;
if (collisionPair->m_algorithm)
collisionPair->m_algorithm->getAllContactManifolds(manifoldArray);
for (int j=0;j<manifoldArray.size();j++)
{
btPersistentManifold* manifold = manifoldArray[j];
bool isFirstBody = manifold->getBody0() == ghost_object;
bool isSecondBody = manifold->getBody1() == ghost_object;
if (isFirstBody || isSecondBody)
manifold_nr = manifold->getNumContacts();
}
}
nr = ghost_object->getNumOverlappingObjects(); // this allways returns something different from 0
I thank you for your time!