To avoid instability and performance issue, instead of using btConstraint, I have decided to use btCompoundShape to create a new big body.
This is pseudo algorithm.
Glue
● all btRigidBody mask = 0 (remove & readd)
● new btCompoundShape from 400 btRigidBodies (using 400 relative transformation and their shapes)
● enable my custom function to set transformation of 400 btRigidBody to appropriate values, using transformation of btCompoundShape. The function is executed in every time step. (cost only little)
Divide
● remove and delete btCompoundShape
● disable the function
● restore btRigidBody mask (remove & readd)
From the profile, the remove & readd cost a lot (10+ ms in release mode), can I avoid it?
Note that, all 400 boxes are not touching each other, and performance in the other time steps are very nice (<2 ms).
The problem boil down to the performance hit of a single line that called 400 times.
Code: Select all
dynamicsWorld->removeRigidBody(body);