Пример #1
0
        public void StepTest9()
        {
            Scene scene = new Scene();

            Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(4, 1));
            actor.SetVelocity(Transform2.CreateVelocity(new Vector2(0.1f, 0)));

            FloatPortal enter = new FloatPortal(scene);
            enter.SetTransform(new Transform2(new Vector2(2, 0)));
            FixturePortal exit = new FixturePortal(scene, actor, new PolygonCoord(0, 0.5f));

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

            Assert.IsTrue(PortalCommon.GetWorldTransform(exit) == exit.WorldTransform);
        }
Пример #2
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);
        }
Пример #3
0
        public void StepTest8()
        {
            Scene scene = new Scene();

            Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(2, 2));
            actor.SetTransform(new Transform2(new Vector2(1, 1)));
            Transform2 velocity = Transform2.CreateVelocity(new Vector2(0, 3));
            actor.SetVelocity(velocity);
            FixturePortal fixture = new FixturePortal(scene, actor, new PolygonCoord(0, 0.5f));

            /*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);

            Transform2 transformPrevious = fixture.WorldTransform.ShallowClone();
            Transform2 actorPrevious = actor.WorldTransform.ShallowClone();

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

            Transform2 expected = transformPrevious.Add(velocity);
            Assert.IsTrue(expected.AlmostEqual(fixture.WorldTransform));
        }
Пример #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));
        }