Magnum::BulletIntegration::MotionState class

Bullet Physics motion state.

Encapsulates btMotionState as a SceneGraph feature.


Common usage is to either create a btRigidBody to share transformation with a SceneGraph::Object by passing the motion state in its constructor:

btDynamicsWorld* btWorld = ;
SceneGraph::Object<SceneGraph::MatrixTransformation3D> object;

auto motionState = new BulletIntegration::MotionState{object};
auto collisionShape = new btBoxShape{{0.5f, 0.5f, 0.5f}};
auto rigidBody = new btRigidBody{20.0f, &motionState->btMotionState(), collisionShape};

This way, the scene graph will be affected automatically by the Bullet simulation. It's also possible to attach the motion state afterwards:


Note that in the other direction, the transform is propagated from the scene graph to the rigid body only during the initial creation of the btRigidBody or when you explicitly set the body as kinematic (which however makes it mostly a passive collision object):


In order to update the transformation of a non-kinematic body, set the transform directly on the btRigidBody:


Keep in mind that changes to a rigid body using btRigidBody::setWorldTransform() may only update the motion state of non-static objects and while btDynamicsWorld::stepSimulation() is called.

Base classes

template<UnsignedInt dimensions, class T>
class Magnum::SceneGraph::AbstractFeature<btScalar>
Base for object features.

Constructors, destructors, conversion operators

template<class T>
MotionState(T& object)

Public functions

auto btMotionState() -> btMotionState&
Motion state.

Protected functions

void getWorldTransform(btTransform& worldTrans) const override
Get world transformation.
void setWorldTransform(const btTransform& worldTrans) override
Set world transformation.

Function documentation

template<class T>
Magnum::BulletIntegration::MotionState::MotionState(T& object)


object Object this motion state belongs to

void Magnum::BulletIntegration::MotionState::getWorldTransform(btTransform& worldTrans) const override protected

Get world transformation.

Updates worldTrans with relative object rotation and translation.

void Magnum::BulletIntegration::MotionState::setWorldTransform(const btTransform& worldTrans) override protected

Set world transformation.

Updates object translation and rotation with worldTrans.