This project has moved and is read-only. For the latest updates, please go here.

Recentering Geoms Bug

Jan 11, 2010 at 3:31 AM

I create several Geoms from several polygons, using GeomFactory.CreateSATPolygonGeom. All of these Geoms are part of a single body. Despite this, the geoms were each individually recentered on the body. I looked into the code, and came up with something that works - though it required making a change to the Geom class so that I could set _positionOffset to zero after creating the geom. CreateSATPolygonGeom doesn't have the same offset parameters as the other Geom factories to fix this sort of thing.

PhysicsBody = BodyFactory.Instance.CreateBody(Mass, 1000); //TODO : Magic Number
PhysicsBody.LinearDragCoefficient = Drag;

foreach (Map.Polygon Polygon in Me.Record.AttachedElements.CollisionPolygons)
	Vertices verticies = new Vertices(Polygon);
	List Geoms = GeomFactory.Instance.CreateSATPolygonGeom(PhysicsBody, verticies, 32);
	foreach (Geom piece in Geoms)
		piece.FrictionCoefficient = Friction;
		piece._positionOffset = Vector2.Zero;

PhysicsBody.Position = Me.Position;
This is the working code. You can see that I had to set _positionOffset to zero. It was set to the negative of the centroid of the un-decomposed polygon originally. All of the original polygons are relative the physics body they attach to already, so that's not an issue. With this change, Geoms attached to the same body all remain static relative each other, and stay in their original positions relative each other, like I had expected.