check collision masks when colliding
Posted: Fri Jun 16, 2017 8:53 am
Hi!
I have a spaceship an cubes. I am adding those to the dynamicsWorld like so:
Now i want to check for collisions between the ship and the cube. Currently I am iterating over manifolds (wich does not seem to work perfectly yet because sometimes my ship collides even though there is nothing to collide with). How can I read the group/mask to see if it collided with a cube? Or is there generally a better way to do this?
Thanks in advance!
Cheers
I have a spaceship an cubes. I am adding those to the dynamicsWorld like so:
Code: Select all
#define BIT(x) (1<<(x))
enum collisiontypes {
COL_NOTHING = 0, //<Collide with nothing
COL_GROUND = BIT(0), //<Collide with ground
COL_WALL = BIT(1), //<Collide with walls
COL_CUBE = BIT(2), //<Collide with powerups
COL_SHIP = BIT(3) //<Collide with ship
};
int shipCollidesWith = COL_WALL | COL_CUBE;
int wallCollidesWith = COL_SHIP;
int cubeCollidesWith = COL_SHIP;
int groundCollidesWith = COL_NOTHING;
Code: Select all
colShapeCube = new btBoxShape(btVector3(edge_length, edge_length, edge_length));
Physics::addCollisionShape(colShapeCube, px, py, pz, mass, COL_CUBE, cubeCollidesWith);
Code: Select all
btRigidBody* Physics::addCollisionShape(btCollisionShape* colShape, float px, float py, float pz, float mass, int group, int mask)
{
btTransform startTransform;
startTransform.setIdentity();
btScalar tMass(mass);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (tMass != 0.f);
btVector3 localInertia(0, 0, 0);
if (isDynamic)
colShape->calculateLocalInertia(tMass, localInertia);
startTransform.setOrigin(btVector3(px, py, pz));
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(tMass, myMotionState, colShape, localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
dynamicsWorld->addRigidBody(body,group,mask);
//collision
return body;
}
Thanks in advance!
Cheers