Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Box doesn't roll in Bullet Physics

As you can see in the image, The Box doesn't roll but slides on the slope.

enter image description here

Here is how i create the box in code,

config = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(config);
broadphase = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver();
bWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, config);
bWorld->setGravity(btVector3(0, -9.8f, 0));

// ...

btTransform t;
t.setIdentity();
t.setOrigin(btVector3(position.x, position.y, position.z));

btBoxShape* box = new btBoxShape(btVector3(size.x, size.y, size.z));
btVector3 inertia(0, 0, 0);
float mass = 10.f;
box->calculateLocalInertia(mass, inertia);

btMotionState* mState = new btDefaultMotionState(t);
btRigidBody::btRigidBodyConstructionInfo cInfo(mass, mState, box);
//cInfo.m_restitution = 0.4f;
//cInfo.m_friction = 0.5f;
btRigidBody* body = new btRigidBody(cInfo);
//body->setLinearFactor(btVector3(1,1,0));
//body->setAngularFactor(btVector3(0,0,1));
m_impl->bWorld->addRigidBody(body);

I tried with friction and other parameters but result is the same. Let me know what I'm doing wrong here.

like image 568
shan Avatar asked Nov 10 '22 11:11

shan


1 Answers

You need to pass your inertia vector to btRigidBodyConstructionInfo. Check the 4th parameter on btRigidBodyConstructionInfo constructor (the one with default value).

like image 72
Aymar Fisherman Avatar answered Nov 15 '22 05:11

Aymar Fisherman