Esempio n. 1
0
        public void AsymmetricPortalSizeBugTest()
        {
            Scene scene = new Scene();
            scene.Gravity = new Vector2();
            FloatPortal portal0 = new FloatPortal(scene);
            FloatPortal portal1 = new FloatPortal(scene);
            portal0.SetTransform(new Transform2(new Vector2(0, 0), 1, (float)Math.PI / 2));
            portal1.SetTransform(new Transform2(new Vector2(10, 0), 2, (float)Math.PI / 2, true));
            Portal.SetLinked(portal0, portal1);
            PortalCommon.UpdateWorldTransform(scene);

            Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(1, 4));
            Vector2 startPos = new Vector2(0, 1);
            actor.SetTransform(new Transform2(startPos));

            for (int i = 0; i < 10; i++)
            {
                scene.Step(1 / (float)60);
                Assert.IsTrue((actor.GetTransform().Position - startPos).Length < 0.001f);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Returns polygon that is the local polygon with only the local transforms Scale component applied. 
 /// This is useful because the vertices should match up with vertices in the physics fixtures for this Actor's body (within rounding errors).
 /// </summary>
 public static List<Vector2> GetFixtureContour(Actor actor)
 {
     return GetFixtureContour(actor.Vertices, actor.GetTransform().Scale);
 }
Esempio n. 3
0
        public void StepTest7()
        {
            Scene scene = new Scene();

            Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(2, 2));
            actor.SetTransform(new Transform2(new Vector2(1, 1)));
            actor.SetVelocity(Transform2.CreateVelocity(new Vector2(0, 3)));
            Entity entity = new Entity(scene);
            entity.SetParent(actor);

            FloatPortal enter = new FloatPortal(scene);
            enter.SetTransform(new Transform2(new Vector2(1, 2), 1, (float)Math.PI / 2));
            //enter.SetVelocity(Transform2.CreateVelocity(new Vector2(1, 0)));

            FloatPortal exit = new FloatPortal(scene);
            exit.SetTransform(new Transform2(new Vector2(10, 10)));
            exit.SetVelocity(Transform2.CreateVelocity(new Vector2(10, 0)));

            enter.Linked = exit;
            exit.Linked = enter;

            PortalCommon.UpdateWorldTransform(scene);
            SimulationStep.Step(scene.GetAll().OfType<IPortalCommon>(), scene.GetAll().OfType<IPortal>(), 1, null);

            Assert.IsTrue(entity.GetTransform() == new Transform2());
            Assert.IsTrue(entity.GetVelocity() == Transform2.CreateVelocity());

            Assert.IsTrue(actor.GetTransform() == actor.WorldTransform);
            Assert.IsTrue(actor.GetVelocity() == actor.WorldVelocity);
        }
Esempio n. 4
0
        public void StepTest5()
        {
            Scene scene = new Scene();

            Actor p = new Actor(scene, PolygonFactory.CreateRectangle(2, 2));
            Transform2 start = new Transform2(new Vector2(0, 0));
            Transform2 velocity = Transform2.CreateVelocity(new Vector2(3, 0));
            p.SetTransform(start);
            p.SetVelocity(velocity);

            FloatPortal enter = new FloatPortal(scene);
            enter.SetTransform(new Transform2(new Vector2(1, 0)));
            enter.SetVelocity(Transform2.CreateVelocity(new Vector2(1, 0)));

            FloatPortal exit = new FloatPortal(scene);
            exit.SetTransform(new Transform2(new Vector2(10, 10)));
            exit.SetVelocity(Transform2.CreateVelocity(new Vector2(10, 0)));

            enter.Linked = exit;
            exit.Linked = enter;

            FixturePortal child = new FixturePortal(scene, p, new PolygonCoord(0, 0.5f));

            PortalCommon.UpdateWorldTransform(new IPortalCommon[] { p, enter, exit, child });
            SimulationStep.Step(scene.GetAll().OfType<IPortalCommon>(), scene.GetAll().OfType<IPortal>(), 1, null);

            Assert.IsTrue(p.GetTransform().Position == new Vector2(19, 10));
            Assert.IsTrue(p.GetVelocity().Position == new Vector2(8, 0));
        }
Esempio n. 5
0
 public static Model CreateActorDebug(Actor actor)
 {
     Model model = new Model();
     Mesh mesh = new Mesh();
     foreach (FarseerPhysics.Dynamics.Fixture f in actor.Body.FixtureList)
     {
         PolygonShape polygon = (PolygonShape)f.Shape;
         var vertices = Vector2Ext.ToOtk(polygon.Vertices);
         AddLineStripWidth(mesh, vertices, 0.05f, true);
     }
     model.Mesh = mesh;
     Vector2 scale = actor.GetTransform().Scale;
     scale.X = 1 / scale.X;
     scale.Y = 1 / scale.Y;
     model.Transform = new Transform3(new Vector3(), new Vector3(scale));
     return model;
 }
Esempio n. 6
0
        public void SetTransformTest0()
        {
            Scene scene = new Scene();
            Vector2[] vertices = new Vector2[] {
                new Vector2(-1, -1),
                new Vector2(1, -1),
                new Vector2(1, 1),
            };
            Actor actor = new Actor(scene, vertices);
            Transform2 t = new Transform2(new Vector2(1, 2), 2, 4.23f, true);
            actor.SetTransform(t);

            Assert.IsTrue(actor.GetTransform() == t);
        }