Update mesh positions/rotations

S_W
Posts: 1
Joined: Sat Jul 26, 2008 1:28 am

Update mesh positions/rotations

Post by S_W »

Hi!

I'm quite new to game physics, still I got Bullet up and running (for now I have a rigid body and a visual mesh).
The position and quaternation of the mesh is adapted to the rigid body's center of mass and rotation after every simulation step.

This works fine for one single object, but how would I deal with many objects in an easy yet efficient way?
Would be the best way to hold a linked list of structs like the following one and iterate it after every simulation step?

struct
{
btRigidBody * body;
MyMesh * mesh_id;
};

Does anybody know a better solution?

Any help would be appreciated :)
Thanks!

EDIT: just found out about the setUserPointer() procedure. Still my question: Do I have to iterate all rigid body's after the update step or is there a better way?
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Update mesh positions/rotations

Post by chunky »

Sounds like a job for a custom btMotionState. That way, bullet will trigger an update for every body that has moved, for you. Motionstates inherently include the interpolation, though, so you should keep that in mind in case it matters.

Gary (-;
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Update mesh positions/rotations

Post by Erwin Coumans »

Indeed, you can derive your own version of btMotionState to synchronize the world transform.
Would be the best way to hold a linked list of structs like the following one and iterate it after every simulation step?
You don't need to keep a separate mapping. It is better to assign a pointer to your graphics objects as user pointer of the rigid body. Use setUserPointer/getUserPointer methods for that.

Hope this helps,
Erwin