Get Collisions

Cookiezzz

28-07-2011 16:16:26

Hi,
I use a simple kinematic body for a my Player. Is there a way to find out if there is a collision between the Player and other Objects?

Cookiezzz

JohnBoyManbullet

29-07-2011 04:07:38

Im so glad i have what your looking for, this will be so easy to implement




const unsigned int numManifolds = dispatcher->getNumManifolds();



// Go through every manifold.
for (unsigned int i=0; i < numManifolds; i++)
{

// Get current manifold.
btPersistentManifold* contactManifold = dispatcher->getManifoldByIndexInternal(i);

// Get collisionpair.
obA =
static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB =
static_cast<btCollisionObject*>(contactManifold->getBody1());

// raycallback.addSingleResult(obA,true);
// Check if the two colliding objects are the boxes.

if ( (body3 == obA && body4 == obB)
|| (body4 == obA && body3 == obB) ) // is the ground touching the unit
{

StepUpRay(evt);
// StepDownRay( );

}
// Refresh contact points.
contactManifold->refreshContactPoints(obA->getWorldTransform(), obB->getWorldTransform());

// Get number of contact points of these two objects.
const unsigned int numContacts = contactManifold->getNumContacts();

// Go through every contact point.
for (unsigned int j = 0;j < numContacts; j++)
{
// Get current manifold point.
btManifoldPoint& pt = contactManifold->getContactPoint(j);

// Get positions.
btVector3 ptA = pt.getPositionWorldOnA();
btVector3 ptB = pt.getPositionWorldOnB();

// Transform to ogre.
Vector3 aPoint = Vector3(ptA.x(), ptA.y(), ptA.z());
Vector3 bPoint = Vector3(ptB.x(), ptB.y(), ptB.z());

// Your code here if need to check the collision by contact points.
}
}



Cookiezzz

29-07-2011 13:30:16

Thanks very much,
but is there a way with OgreBullet?

cookiezzz

JohnBoyManbullet

29-07-2011 22:16:30

Thats bullet with ogre, this forum should be called just bullet.

Cookiezzz

30-07-2011 16:04:35

Ok,
i tried your code. Just one question :
What is StepUpRay(evt);?

JohnBoyManbullet

30-07-2011 23:21:33

its nothing relevant.

Cookiezzz

02-08-2011 17:11:00

Hi again,
it works so far, but the Ogre Object and the collision don't match. Any Ideas?



Ogre::AxisAlignedBox boundingB = Player.Entity->getBoundingBox();
size = boundingB.getSize();
size *= (Player.node->getScale()); // only the half needed
size /= 2;
size *= 0.96f; // Bullet margin is a bit bigger so we need a smaller size
// after that create the Bullet shape with the calculated size
OgreBulletCollisions::BoxCollisionShape *sceneBoxShape = new OgreBulletCollisions::BoxCollisionShape(size);
Player.Body = new OgreBulletDynamics::RigidBody("PlayerPhys" ,mWorld);
Player.Body->setShape( Player.node,sceneBoxShape,
0.0f, // dynamic body restitution
0.0f,0.1f, // dynamic body friction
Ogre::Vector3(0,0,0), // starting position of the box
Ogre::Quaternion(1,0,0,0));// orientation of the box
Player.Body->setPosition(0,900,0);
Player.Body->setKinematicObject(true);
Player.Body->showDebugShape(true);



boundingB = Floor.Entity->getBoundingBox();
size = boundingB.getSize();
size *= (Floor.node->getScale());
size /=2;// only the half needed
size *= 0.96f; // Bullet margin is a bit bigger so we need a smaller size
// after that create the Bullet shape with the calculated size
Floor.Shape = new OgreBulletCollisions::BoxCollisionShape(size);
Floor.Body = new OgreBulletDynamics::RigidBody("FloorPhys" ,mWorld);
Floor.Body->setStaticShape(Floor.Shape,0.1f,0.0f,Ogre::Vector3(0,0,0));

JohnBoyManbullet

04-08-2011 11:27:45

I think i know whats wrong. You need to use motion states. I always have and heard you always wana move yer shapes with motion states. http://bulletphysics.org/mediawiki-1.5. ... tionStates . Add the shape to yer motion state, then compare the motion state to the collision object. That what i do and it works like a charm.

Cookiezzz

05-08-2011 11:04:22

i use OgreBUllet and i think it uses motionstates.

Cookiezzz

05-08-2011 18:35:27

OK,

when there is one collision there is no more :| .
And the collisionshapes have a wrong figure :(

JohnBoyManbullet

05-08-2011 22:59:49

k well i havent gone too far into it my self. at least you have learned how the contact manafolds work. Here, this is the bullet wikis explanations with variations on what i showd you. http://www.bulletphysics.org/mediawiki- ... d_Triggers