Rigid Bodies

From Physics Simulation Wiki

Jump to: navigation, search

Rigid bodies are the basic building block of all physics simulations. They are represented with the class btRigidBody.

Contents

Creation

For creation, you will need a collision shape. You also need to create a btRigidBodyConstructionInfo object, but that's just temporary.

Take a look at Hello World for a full example of a bouncing ball

Interesting methods

This class has heaps of methods. Here are some of the interesting ones:

getMotionState
Get the motion state object, which is useful for rendering, network, etc.
setLinearVelocity(btVector3)
Makes the rigid body move
setAngularVelocity(btVector3)
Makes the rigid body spin
setRestitution(btScalar)
The spring or bounciness of a rigid body
setLinearFactor(btVector3)
Locks linear movement to specific axis
setAngularFactor(btVector3)
Locks angular movement to specific axis
setDamping(btScalar, btScalar)
?

Examples

This little example makes a ground surface at origin using a btStaticPlaneShape which is just a infinite flat surface.

btCollisionShape* shape = new btStaticPlaneShape(btVector3(0, 1, 0), 1);

btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,-1,0)));
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(
	0,                  // mass
	motionState,        // initial position
	shape,              // collision shape of body
	btVector3(0,0,0)    // local inertia
);

btRigidBody *rigidBody = new btRigidBody(rigidBodyCI);
dynamicsWorld->addRigidBody(rigidBody);

See also

Personal tools