Question

I am sorry to ask such a basic question about bullet. However, I am having an issue. Here is the setup:

I have a world with no gravity. When I press a key, a 1x1x1 box is created in the center of the world. When I right click, a box of size 0.05*0.05*0.05 is create at the camera position, and is 'shot' in the direction you are looking. Here is where the trouble begins.

When a small cube hits a large cube, the interaction seems wrong. You would expcet a box 1/8000th the size of another to have very little effect. Yet the large cube goes flying, as if it been with a cube of its same size. I assumed it is because I created both objects with the same mass.

To confirm this, I apply an upward force of 1 newton (or whatever unit bullet uses). Both objects accelerate at the same rate.

My code for creating objects is as follows:

btMotionState *state = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
btConvexHullShape* shape = new btConvexHullShape();
for(unsigned int i = 0; i < vertices.size(); ++i) {
    shape->addPoint(toBt(vertices[i]));
}
shape->setMargin(0.01f);

btScalar mass = 1.f;
btVector3 inertia;
shape->calculateLocalInertia(mass, inertia);
shape->setMargin(0.01f);
btRigidBody::btRigidBodyConstructionInfo ci(mass, state, shape, inertia);
body = new btRigidBody(ci);

I expect that the btScalar mass = 1.f; line is the culprit.

Am I expected to calculate the mass of my objects? This is simple enough for a cube, but what about some weird convex shape? Is there any way I can get bullet to do this for me?

Was it helpful?

Solution

Yes, mass is the culprit. Think about your big box being an empty wooden crate and your small box being a solid cube of iron. Huge difference in size but equal mass. Now your physics seem correct, right?

Yes, you are expected to provide the mass. Whether you calculate it or just state "this box weighs 20kg" is up to you. Actually expecting someone else to calculate the mass for you just makes your problem worse, because you'd have to specify materials, material density, and material distribution of your objects besides its geometry. If you want to go that way there are plenty of other tools available to aid you with such calculations. But I'm sure you agree that just stating some mass through trial and error is easier by far.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top