Updating COM every frame?

Post Reply
karantza
Posts: 5
Joined: Sat Feb 27, 2016 5:11 am

Updating COM every frame?

Post by karantza »

Hi,

I've got a simulation where I have a single rigid body representing a collection of sub-objects. Each sub-object individually tracks its mass and collision shape, and together they build a single compound collision shape for the primary rigid body. I calculate the cumulative center of mass, and offset all the sub-objects so that the compound shape is centered, and everything is wonderful.

However, I have to update the simulation when the mass of one of these sub-objects changes, which it can do every single frame. This means that the center of mass of the compound object has to shift, which - I think - means I have to rebuild the compound shape every frame, offsetting all the sub-objects slightly.

Is there any cheaper way to do this than rebuilding the whole compound shape? (There may be many sub-objects!) Are there any tricks I should know about updating compound shapes that might make this easier?
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: Updating COM every frame?

Post by hyyou »

I have the exact same problem. Thank you for posting.

The solution may appear in Scorpion81's fracture source code in http://www.bulletphysics.org/Bullet/php ... 12&t=10883 .
I just skimmed it.

If you would make some progress, I will greatly appreciate if you share the knowledge.

Shouldn't the word in topic be "compound" rather than "COM"? :)
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Updating COM every frame?

Post by benelot »

Hi,

Could you connect all the sub-objects with fixed constraints? This would lead to an automatic update of your COM. I am not sure if you can simply update the fixed constraints, but I would guess it is not that hard to change it every frame.
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: Updating COM every frame?

Post by hyyou »

@benelot
Constraint is easy, but it is too unstable and expensive.

While 1 Compound with 400 simple shapes is reasonably fast (thank developer!),
"400 Simple Body + 399 Constraint" is unusably slow and cause explosion from divergence - even with good mass.

I tested it with btGeneric6DofSpring2Constraint. Did I choose wrong type of constraint?
I don't want the spring affect.

It would be nice if there is "compound HARD constraint" that is really cheap. The constraint would do only one thing - broadcast transformation of a body to other 399 bodies in some ways inside physic iteration.

Roughly speaking, it may be implemented by : all simple bodies has transformation pointer that point to the same address of transformation stored in compound body. It is easier said that done though.

As I skimmed in Bullet's vanilla fracture demo (the official way), it also suffer like OP pointed out.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Updating COM every frame?

Post by benelot »

I would suggest to try fixed constraints, the constraint might be more stable than the generic one. The movements of rigidbody can then be done and the fixed constraint can be adjusted.
Post Reply