Sign in to follow this  
ReDevilGames

Bullet Physics - Weird collision

Recommended Posts

Hi! I'm trying to integrate the Bullet physics library into engine.
But some collisions are weird. Also, sometimes I get an assertion, because the W component of some objects in the scene become 0. I don't know why -.-"
 

This is how I start the physics simulation:

config = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(config);
broadphase = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver();

world = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, config);
world->setGravity(btVector3(0.0, -9.81, 0.0));

And this is how I create a mesh made of triangles (I know there are other efficient meshes, but it's just to see if it works):

collisionShape = new btConvexHullShape();
const unsigned int size = model->vertices.size();
for (unsigned int i = 0; i != size; i++)
	collisionShape->addPoint(btVector3(model->vertices[i].x, model->vertices[i].y, model->vertices[i].z));

motionstate = new btDefaultMotionState(btTransform(
        btQuaternion(rotation.x, rotation.y, rotation.z, 1.0),
	btVector3(position.x, position.y, position.z)
));

btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(
	mass, // mass, in kg. 0 -> Static object, will never move.
	motionstate,
	collisionShape, // collision shape of body
	btVector3(position.x, position.y, position.z) // local inertia
);
rigidBody = new btRigidBody(rigidBodyCI);

Physics::world->addRigidBody(rigidBody);

And this is what happens:

https://www.youtube.com/embed/sNFf4Gx_CNM

 

I have also tried btBvhTriangleMeshShape, creating the object and giving all the triangles of my mesh, but it doesn't even collide with anything.

I followed the official documentation, but it does not work. Am I missing something?

I am new to physic engine, so I think I'm missing something.

 

I also tried scaling my models, because some people said that physic engine work better with large geometry... but nothing.

 

Any ideas?

Edited by FonzTech

Share this post


Link to post
Share on other sites

btQuaternion(rotation.x, rotation.y, rotation.z, 1.0)

 

In this line, you are probably initalizing the quaternion directly. You should try initializing it with yaw, pitch and roll. So try to use this constructor instead:

 

btQuaternion (const btScalar &yaw, const btScalar &pitch, const btScalar &roll)

Share this post


Link to post
Share on other sites

btQuaternion(rotation.x, rotation.y, rotation.z, 1.0)

 

In this line, you are probably initalizing the quaternion directly. You should try initializing it with yaw, pitch and roll. So try to use this constructor instead:

 

btQuaternion (const btScalar &yaw, const btScalar &pitch, const btScalar &roll)

 

Thanks for the help, but it doesn't change nothing...

Collisions are still incorrect... why?

Share this post


Link to post
Share on other sites

 

How do you apply physics transformation to your graphical object?

 

I call the stepSimulation method on my btDiscreteDynamicsWorld object...

 

 

That's not what I meant, at least not exactly.

After you call stepSimulation you have to get object's new transformation from collision info and set it to your graphical object. How do you do that?

Share this post


Link to post
Share on other sites

From the documentation, I have understood that once you create a rigid body, you must add to the discrete world, by calling the addRigidBody method. So, are new transformations supposed to be updated automatically, once stepSimulation is called? Infact, collision detection sometimes does work, and sometimes does not.

I don't know if it depends on geometry, but I don't think so... Any clue?

 

P.S.: I don't get the meaning of the -1 on my post -.-"

Share this post


Link to post
Share on other sites

P.S.: I don't get the meaning of the -1 on my post -.-"

It means your reply was obnoxious.
If you need more assistance with your problem, say so and provide more information. Your topic will still be bumped and people will be more willing to take a 2nd look.
When asking for help, it is important to indicate to others that you have tried on your own, which means it is also important to give some indication that you have tried things during the days that you waited.


L. Spiro

Share this post


Link to post
Share on other sites

So, are new transformations supposed to be updated automatically, once stepSimulation is called?

stepSimulation will only update your collision transformation, not what you see on the screen. So you have to do something like:

btRigidBody* body = ...;
btTransform trans;
body->getMotionState()->getWorldTransform(trans);
float transValues[16];
trans.getOpenGLMatrix(transValues);
// put transValues into constant buffer

But I do not remember whether you can use transValues directly or you have to transpose it, but making sure this is correct is a first step. It's very unlikely for physics to be wrong.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this