10-12-2022, 11:21 AM
If anyone needs to know how to create a physics object that connects to your game objects this might help
PhysicsObj* Game::CreatePhysicsObj(btCollisionShape* pShape,
const float &mass,
const btVector3 &aPosition,
const btQuaternion &aRotation,
int mask) // mask defaults to 1
{
// create a new game object
PhysicsObj* pPhysicsObject = new PhysicsObj(pShape, mass, aPosition, aRotation);
float currentm = pShape->getMargin();
pShape->setMargin(0.09f); // I make it a tiny bit smaller
if (DynamicPhysicsWorld)
{
DynamicPhysicsWorld->addRigidBody(pPhysicsObject->GetRigidBody(), 1, 1); // group 1, mask 1;
// the group and mask are accessable using these functions but don't need them till you do collision responses
// pPhysicsObject->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterGroup;
// pPhysicsObject->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterMask;
} else {
printf("Attempting to add to a Dynamic world that does not exist\n"); }
ListOfPObjects.push_back(pPhysicsObject); // need this to clear the world at times does physics not have this?0
return pPhysicsObject; // return to place in the objects data or in another list
}
PhysicsObj* Game::CreatePhysicsObj(btCollisionShape* pShape,
const float &mass,
const btVector3 &aPosition,
const btQuaternion &aRotation,
int mask) // mask defaults to 1
{
// create a new game object
PhysicsObj* pPhysicsObject = new PhysicsObj(pShape, mass, aPosition, aRotation);
float currentm = pShape->getMargin();
pShape->setMargin(0.09f); // I make it a tiny bit smaller
if (DynamicPhysicsWorld)
{
DynamicPhysicsWorld->addRigidBody(pPhysicsObject->GetRigidBody(), 1, 1); // group 1, mask 1;
// the group and mask are accessable using these functions but don't need them till you do collision responses
// pPhysicsObject->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterGroup;
// pPhysicsObject->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterMask;
} else {
printf("Attempting to add to a Dynamic world that does not exist\n"); }
ListOfPObjects.push_back(pPhysicsObject); // need this to clear the world at times does physics not have this?0
return pPhysicsObject; // return to place in the objects data or in another list
}
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's