I implemented a high level components system for my renderer and am curious about the right way to update the transforms components of models that have a physics rigidbody attached. I am using bulletsharp. To clarify. Transformcomponents holds the model matrix that is used for rendering. Rigidbody holds the worldmatrix that is getting modified by step simulation of bulletsharp. I want my rigidbody and transformcomponents matrices to stay synced.
My idea is to do it like this per render loop:
- Always use transformcomponent for rendering
- Execute physics step simulation
- Update all transformcomponents with new matrices from rigidbody
- Whenever transformcomponent gets a matrix update from user input and not physics... Update the matrices recursive for the attached rigidbody and all children
- Render with matrices of transformcomponents
Is there a better way to implement rigidbody physics in a components system for rendering? I use the physics mainly for raycast picking and OBB collision detection.
And when I use the term "better", I mean more efficient in terms of least updates on scene components. Syncing two components matrices seems tedious and I want to know if there is a solution without syncing.