0
votes

I am using the Farseer Physics library with MonoGame.

In my game I use compound polygon bodies, created with BodyFactory.CreateCompoundPolygon(...);, but they have problem.

Their origin is in the top left corner, rather then the centroid like most Box2d objects. Since I need to rotate the bodies around a different pivot point than the top left, I found I can change the center of mass of a body (Body.LocalCenter). This works fine and dandy, and I can rotate the body using Body.ApplyAngularImpulse(...); or by changing Body.AngularVelocity, but here comes the problem:

Changing the rotation of the body using the methods I mentioned before works fine, and the pivot point used is the center of mass, but if I try to rotate the body by directly changing it's rotation (Body.Rotation), it rotates around the top left corner rather than the center of mass. So in effect, Body.Rotation += 1; rotates around a different pivot point than with Body.AngularVelocity = 1;

You might be wondering why this is a problem, why I don't just use the methods I mentioned before to rotate the body. The problem is I need to be able to check the current rotation of the body. I can't figure out a way to do this. I can't use Body.Rotation since it returns the rotation around a wrong point.

TL;DR: Body.Rotation doesn't return rotation around center of mass, how to combat this?

1

1 Answers

1
votes

You can have the pivot and mass center correctly set if you create your compound polygon from a list of points relative to the center.

For a 20 units side square : instead of : [0,0][20,0][20,20][-20,20] use : [-10,-10][10,-10][10,10][-10,10]