3
votes

I'm having a bit of trouble with rotating a Fixture in the Farseer Physics Engine (using XNA). Basically, i have a fixture, set up as such:

 private void setUpPhysics(World gWorld, Vector2 position)
    {
        body = new Body(gWorld);
        body.BodyType = BodyType.Dynamic;
        carFixture = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(21f), ConvertUnits.ToSimUnits(35f), 5f, ConvertUnits.ToSimUnits(position), body);
        carFixture.Restitution = 4f;
        carFixture.Friction = 5f;
        carFixture.Body.AngularDamping = 1f; 
        carFixture.Body.LinearDamping = 1f;
    }

Which i then rotate using the code

carFixture.Body.Rotation -= 0.01f;

Which works fine. The problem is, it always rotates around the top left corner of the rectangle, and i need it to rotate round the center. How would i go about rotating the fixture around it's center? (I apologize for my stupidity - i'm new to Farseer / Box2D and i have no doubt it is the major cause of this problem, but i've been searching the internet for a good few hours now and have found nothing.)

1
A body rotates around its origin so you will need to place the fixture so that the fixture is centered at (0,0). This AttachRectangle function appears to take an offset which looks like it is for this purpose.iforce2d

1 Answers

1
votes

Solved this myself - turned out the body was rotating around its center, but the texture that was attached to it was rotating around its corner