0
\$\begingroup\$

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:

  1. Always use transformcomponent for rendering
  2. Execute physics step simulation
  3. Update all transformcomponents with new matrices from rigidbody
  4. Whenever transformcomponent gets a matrix update from user input and not physics... Update the matrices recursive for the attached rigidbody and all children
  5. 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.

\$\endgroup\$
  • \$\begingroup\$ "Better" in what way? What specific aspect of your current solution do you feel is unsatisfactory? What should our answers focus on improving? \$\endgroup\$ – DMGregory Mar 18 at 22:03
  • \$\begingroup\$ Personally I let user input apply forces and impulses to the physics simulations and skip step 4. The "better" way is the one that works for you. \$\endgroup\$ – Jay Mar 19 at 3:20
0
\$\begingroup\$

The approach you suggest seems fine to me.

To be the most optimal, you'll want your transformcomponents and Rigidbody matrices be of the same size and organized the same way, so that you could just copy a memory chunk when you update the transformcomponents from Rigidbody.

But to be honest, updating your components matrices is quite trivial when you compare to the work that Bullet does, or that your renderer does, so I would not worry about that as it really seems premature optimization to me.

That being said, you'll want to profile once in a while, just to make sure you keep your architecture in check.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.