Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In Farseer 3.3.1 for XNA, how do I change the origin of a Body? For example, when I create a Circle Body, instead of it rotating around its center, I want it to rotate around another specified point.

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

I guess the revoulte joint is what you want. You can use it to pin the circle at a given position and the circle will rotate around that position.

share|improve this answer
add comment

The centroid is necessary for physics calculations. In other words that is not the origin you are trying to move but the center of mass. Unless I'm mistaken you're going to have to do a bit of trig or get fancy with matrices.

share|improve this answer
add comment

Just to give a late answer to the question, answering what the question literally asks (for anyone who comes across it by searching):

You don't so much change the origin of a Body as you place your Fixtures relative to the body's origin (ie: in "Local" body space).

For example, assuming:

float radius = 1f;
float density = 1f;

A centred circle would be this:

Body body = BodyFactory.CreateCircle(world, radius, density);

But a circle offset from the body origin by its radius would be:

Body b = BodyFactory.CreateBody(world);
FixtureFactory.AttachCircle(radius, density, body, new Vector2(0, radius));

(Other shapes have similar offset parameters available. Raw polygons vertices are specified relative to the body's origin.)


Now, even if you do this, the centre of mass will still be at centre of the circle. If you want to move the centre of mass, you can do this:

body.LocalCenter = new Vector2(0, 0);

That is in the case where you've moved the circle centre away from the body's origin (as above), but you want to keep the centre of mass at the origin.

If you don't move the circle fixture, and just want to move the centre of mass, then do something like this:

body.LocalCenter = new Vector2(0, radius);

It is important to note, however, that Farseer normally recalculates the centre of mass! It does so if any of these things happen:

  • You attach or remove a fixture from the Body
  • You set BodyType
  • You set IsStatic
  • You set FixedRotation
  • You call ResetMassData()

So if you do any of those things, you must set LocalCenter afterwards.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.