Bullet Physics - Weird collision

Started by
8 comments, last by jpetrie 7 years, 7 months ago

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?

Advertisement

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)

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?

How do you apply physics transformation to your graphical object?

How do you apply physics transformation to your graphical object?

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

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?

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 -.-"

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement