Align fixture with the body

General discussion about the R.U.B.E editor
Post Reply
kazeno
Posts: 8
Joined: Sat Feb 21, 2015 1:46 am

Align fixture with the body

Post by kazeno »

How can I get the center of the fixture and align to the body center?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Align fixture with the body

Post by iforce2d »

Firstly, only circles and edge fixtures have a true center. For polygons the center of mass will be used, and for lines the average of the vertices will be used. In each case this 'center' is shown by the white cross when the fixture is selected.

Bodies also do not really have a center, so I'll assume you mean the body position (where the gray faded circle thing is shown).

To move a fixture 'center' to the body position, you can do this:
- select the body
- do C, S (cursor to selection)
- select the fixture
- do S, C (selection to cursor)

Let me know if this is not what you meant.
kazeno
Posts: 8
Joined: Sat Feb 21, 2015 1:46 am

Re: Align fixture with the body

Post by kazeno »

Perfect!
But what is the blue cross?

How can I get the center of mass by script?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Align fixture with the body

Post by iforce2d »

The blue cross is the true center of mass of each body, and is only shown in body edit mode.

You can get the center of mass of a body with the getWorldCenter() function. This name may seem a bit strange but it's because RUBE follows the same function names as Box2D, if there was an equivalent in Box2D already.

Currently there is no script function to return the white cross position ("center of selection"), so you could not automate the process I mentioned above by using script if the selection includes line fixtures, or if you have more than one fixture selected. I can add it in the next version if you like. Keep in mind though, as I said above the white cross is a bit arbitrary and does not accurately describe anything known about by Box2D, and for fixtures especially the position will vary depending on whether the fixture is a line/polygon etc. The white cross position will also vary depending on how many items you have selected, because it is "center of selection" so when you have say, five items selected the white cross will be the average of where the white cross for each of those items would be. So because this behavior is a bit strange, was the reason I didn't include a script function to access the white cross position originally.
kazeno
Posts: 8
Joined: Sat Feb 21, 2015 1:46 am

Re: Align fixture with the body

Post by kazeno »

This is not a information that Box2D use but is useful for edition and scripting just like getSelected...()
Would be great to get it by script because the centroid/median point of a polygon or a selection is something I use a lot when editing.
Post Reply