Page 1 of 1

Is it possible to change center of mass in rube?

Posted: Thu Mar 20, 2014 7:17 pm
by Androidacct
Hi there. When I create a body it seems that it places the center of mass (white mark) in the middle of the shape, but when I transform the vertices/add more vertices the center of mass does not change. Is it possible to change it?

Also, another quick question not directly related to rube. In some sample scenes your ground has one body and one fixture in the items f6 list... e.g. getting started has a leftground body and only 1 leftground fixture(well that you can access) and then the same for right ground, but then in other scenes you have one static body and many fixtures that go with it and you can access each individual fixture. I've been creating 1 body/1 fixture for each section of the ground, but maybe I should just make one body and add all fixtures to this body. Which method should I use? When should I use each method? If this isn't clear I'll take screenshots for you. Cheers.

Re: Is it possible to change center of mass in rube?

Posted: Fri Mar 21, 2014 5:37 am
by iforce2d
The center of mass of a body is the blue cross shown when the body is selected, eg:
Selection_003.png
Selection_003.png (7.57 KiB) Viewed 7292 times
In fixtures mode the 'center of selection' is also determined by the center of mass of each fixture, so in the case when only a single fixture is selected the white cross will be in the same place:
Selection_004.png
Selection_004.png (5.23 KiB) Viewed 7292 times
When more than one fixture is selected the 'center of selection' will be the average of all selected fixtures:
Selection_005.png
Selection_005.png (5.96 KiB) Viewed 7292 times
By default the center of mass of a body is determined by the fixtures attached to it. One trick I have found very useful to set the CoM to a different location is:
- add an extra circle fixture to the body, and set it as a sensor fixture so it does not collide with anything
- set the density to zero for all other fixtures on the body
Now you can place the newly added circle fixture to wherever you want the CoM to be. For example, let's say I want the CoM in the previous example to be at the bottom right corner of the shape:
Selection_007.png
Selection_007.png (8.77 KiB) Viewed 7292 times
About your other question, if the ground will never move or be changed, eg. no parts of it need to be deleted/replaced, then one body with all fixtures on it would be fine.

Re: Is it possible to change center of mass in rube?

Posted: Fri Mar 21, 2014 12:06 pm
by Androidacct
Perfect, thanks.