public void GetCentroidTest0() { Scene scene = new Scene(); Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(0.5f, 3f)); Vector2 centroid = actor.GetCentroid(); foreach (BodyData data in Tree<BodyData>.GetAll(BodyExt.GetData(actor.Body))) { data.Body.LocalCenter = actor.Body.GetLocalPoint((Xna.Vector2)centroid); } //LocalCenter and centroid should be the same since the actor is on the origin with no rotation. Assert.IsTrue((Xna.Vector2)actor.Body.LocalCenter == (Xna.Vector2)centroid); Assert.IsTrue(centroid == new Vector2()); }
public void GetCentroidTest2() { Scene scene = new Scene(); scene.Gravity = new Vector2(); Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(0.5f, 3f)); FloatPortal enter = new FloatPortal(scene); FloatPortal exit = new FloatPortal(scene); Portal.SetLinked(enter, exit); enter.SetTransform(new Transform2(new Vector2(0, 1), 1, (float)(Math.PI / 2))); exit.SetTransform(new Transform2(new Vector2(5, 0), 2)); scene.Step(); Vector2 centroid = actor.GetCentroid(); foreach (BodyData data in Tree<BodyData>.GetAll(BodyExt.GetData(actor.Body))) { data.Body.LocalCenter = actor.Body.GetLocalPoint((Xna.Vector2)centroid); } Assert.IsTrue((actor.Body.LocalCenter - (Xna.Vector2)centroid).Length() < 0.0001f); Assert.IsTrue((centroid - new Vector2(0, 1.6959f)).Length < 0.0001f); }
public void GetCentroidTest4() { Scene scene = new Scene(); scene.Gravity = new Vector2(); Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(0.5f, 3f)); Vector2 offset = new Vector2(2, 5); actor.SetTransform(new Transform2(offset)); FloatPortal enter = new FloatPortal(scene); FloatPortal exit = new FloatPortal(scene); Portal.SetLinked(enter, exit); enter.SetTransform(new Transform2(new Vector2(0, 1) + offset, 1, (float)(Math.PI / 2), true)); exit.SetTransform(new Transform2(new Vector2(5, 0) + offset, 2)); scene.Step(); Vector2 centroid = actor.GetCentroid(); Assert.IsTrue((centroid - new Vector2(0, 1.6959f) - offset).Length < 0.001f); }