Rotate Body Around Non-Zero Origin?

Topics: User Forum
Oct 23, 2009 at 7:19 PM
Edited Oct 24, 2009 at 2:59 AM

Terribly sorry if this has been discussed.

Is there an easy way to rotate a body around a non-zero origin?

EDIT: I know that you can offset the geometry, but that only helps if that offset can be modified after the geom is created.

Further Details:

I built a character editor based on a system of bones. Farseer doesn't really have much to do with it, but I am using Farseer for the physics in my project. Currently the character's are a collection of sprites with custom keyframed movement data. They are represented by a single square body/geom which is OK, but I'd like something better. All I really want to do at this point is have each body part represented by its own body/geom, and not really use Farseer for anything but collision detection (and maybe activate the bodies for a ragdoll if the guy is dead). The problem is that in the editor, I use a non-zero origins to rotate bones at say, their tips, instead of their centers. Any ideas?

Oct 25, 2009 at 4:50 AM

Hi Ordonator,

As far as I know the only way to do what you're talking about is using that rotation offset when you create the geom.

You could try exposing the _rotationOffset with a getter and setter, but it may yield some unusual results at collision detection time.

Since the geom position is relative to the body position, you could also try sliding the geom's LocalVertices around until the part that you want to rotate is over the body position.  I had to do something like this to get the puzzle pieces in my game to flip over the x axis.


----------   Move the         ----------
|        |   geom verts       |        |
|        |   down relative    |    X   |
|        |   to body          |        |
|        |   ----------       |        |
|        |   |        |       |        |
|   X    |   |   X    |       |        |
|        |   |        |       |        |
|        |   |        |       |        |
|        |   |        |       |        |
|        |   |        |       |        |
|        |   |        |       |        |
----------   |        |       ----------
             |        |        Then move the
             |        |        body back up
             |        |        to match the geom's
             ----------        original position


If you can figure out a way to make this work on the existing Farseer objects, other people would probably be able to use it.


Oct 25, 2009 at 5:10 AM

Thanks for the input. I'll try exposing the _rotationOffset field in the morning and report back. For now, I've just gone to creating a new geom each time it moves. Since its just for an editor, it doesn't really matter too much. The only bad thing is that the skeletons wouldn't support any sliding between the bones.

Also, I've tried a joint-based solution. But joints in Farseer are terribly intolerant of manual changes to the bodies, as discussed in some of the threads about character animation.

Oct 25, 2009 at 9:51 AM

What I do is to rotate the body around its center and then recalculate manually the position.

Oct 27, 2009 at 8:22 AM

Another option (maybe not the best, but should work): Attach a new body in the point you want to rotate it with a fixed angle joint. Then rotate this body.