So I've implemented the Bullet SDK into my project, following the instructions in the User Manual. I've also created a wrapper for the Bullet Physics system.
Now I'm creating a sphere with btSphereShape as one collision shape and a box with btBoxShape as another collision shape. I then set all the properties of these and create btRigidBody for both of them and then add them to the world. When I run my program I see the ball falling, falling and falling...it doesn't collide with the box at all. Is anyone able to suggest why this might be? Am I doing something wrong?
Thanks in advance,
Tom
Collision between Sphere and Box not working
-
- Posts: 4
- Joined: Tue Jan 29, 2013 4:45 pm
-
- Posts: 9
- Joined: Fri Jan 25, 2013 1:46 pm
Re: Collision between Sphere and Box not working
make it collide with the box? lol i mean can you bring down the code dude cuz no one will help u this way...
-
- Posts: 4
- Joined: Tue Jan 29, 2013 4:45 pm
Re: Collision between Sphere and Box not working
Adding a sphere:
Adding a box:
The add shape function:
And then the call to Bullet to update the physics comes from my main loop with a call to:
I think that the problem is in there somewhere, maybe with how I'm creating the shapes but I'm not 100% sure. The box is getting created with 0 mass and the sphere with around 19 depending on the material I use. If anyone needs any more code shout, I just didn't want to post 000's of lines of it!
T
Code: Select all
//Function for adding a sphere to the physics system
void
BulletPhysics::VAddSphere(float radius, Actor* actor, float specificGravity, PhysicsMaterial mat)
{
//Create the collision body, specifying the shape
//btSphereShape* const collisionShape = new btSphereShape(btScalar(radius));
btSphereShape* const collisionShape = new btSphereShape(1.);
//Calculate mass from specific gravity
float const volume = (4.f / 3.f) * PI * radius * radius * radius;
btScalar const mass = volume * specificGravity;
AddShape(actor, collisionShape, mass, mat);
}
Code: Select all
//Function for adding a box to the physics system
void
BulletPhysics::VAddBox(const Vector3D &dimensions, Actor* actor, float specificGravity, PhysicsMaterial mat)
{
//Create the collision body, specifying the shape
btBoxShape* const collisionShape = new btBoxShape(GetBulletVector3(dimensions));
//Calculate mass from specific gravity
float const volume = dimensions.x * dimensions.y * dimensions.z;
btScalar const mass = volume * specificGravity;
AddShape(actor, collisionShape, mass, mat);
}
Code: Select all
//General function for adding shapes to the physics system
void
BulletPhysics::AddShape(Actor* actor, btCollisionShape* shape, btScalar mass, PhysicsMaterial mat)
{
//Set up the local inertia
btVector3 localInertia(0.f, 0.f, 0.f);
if(mass > 0.f)
shape->calculateLocalInertia(mass, localInertia);
btTransform trans;
trans.setIdentity();
trans.setOrigin(GetBulletVector3(actor->VGetPosition()));
btDefaultMotionState * const myMotionState = new btDefaultMotionState(trans);
//Set up the body's info
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, shape, localInertia);
//Create the rigidBody
btRigidBody * const body = new btRigidBody(rbInfo);
//body->setWorldTransform(trans);
//body->setFriction(15.0f);
m_dynamicsWorld->addRigidBody(body);
//Calls back the actor class to set the body up with this actor
actor->VSetActorBody(body);
//Set up an ID for this actor to be associated with
ActorId nextId = 0;
for(ActorIdToActorMap::const_iterator it = m_actors.begin();
it != m_actors.end();
++it)
{
++nextId;
}
//Sets the Actor's value of ActorId
actor->VSetActorId(nextId);
//Sets up and inserts the Actor into the list
m_actors.insert(std::pair<ActorId, Actor*>(nextId, actor));
}
Code: Select all
//Function for updating the physics system
void
BulletPhysics::VOnUpdate(float elapsedTime)
{
//Pass in 4 so BulletPhysics carries out 4 substeps and will run simulation
//in terms of elapsedTime
m_dynamicsWorld->stepSimulation(elapsedTime, 4);
}
T
-
- Posts: 4
- Joined: Tue Jan 29, 2013 4:45 pm
Re: Collision between Sphere and Box not working
I seem to have a new problem now - the btSphereShape falls down and goes slightly through the btBoxShape before stopping. So I can then move it about (through applying force to it) but it is stuck inside the box whereas I want it to be on top of it - any ideas why this would be?
T
T
-
- Posts: 25
- Joined: Sat Dec 29, 2012 7:20 pm
Re: Collision between Sphere and Box not working
Perhaps the size is a bit off?
-
- Posts: 9
- Joined: Fri Jan 25, 2013 1:46 pm
Re: Collision between Sphere and Box not working
lol i feel sleepy n i read ur script half eye opened so this is what i found i dnt even know what it is http://www.bulletphysics.org/Bullet/php ... 72&p=27984