Пример #1
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);
        }
Пример #2
0
        public void StepTest3()
        {
            Scene scene = new Scene();
            Portalable p = new Portalable(scene);
            Transform2 start = new Transform2(new Vector2(0, 0));
            Transform2 velocity = Transform2.CreateVelocity(new Vector2(3, 0));
            p.SetTransform(start);
            p.SetVelocity(velocity);

            //Scene scene = new Scene();
            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)));

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

            PortalCommon.UpdateWorldTransform(new IPortalCommon[] { p, enter, exit });
            SimulationStep.Step(new IPortalCommon[] { p, enter, exit }, new IPortal[] { enter, exit }, 1, null);

            /*Assert.IsTrue(p.WorldTransform.Position == new Vector2(9, 10));
            Assert.IsTrue(p.WorldVelocity.Position == new Vector2(-2, 0));*/
            Assert.IsTrue(p.GetTransform().Position == new Vector2(9, 10));
            Assert.IsTrue(p.GetVelocity().Position == new Vector2(-2, 0));
        }
Пример #3
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));
        }