コード例 #1
0
ファイル: BodyExtTests.cs プロジェクト: AyyTee/Aventyr
        public void GetLocalMassDataTest2()
        {
            Scene scene = new Scene();
            scene.Gravity = new Vector2();
            Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(4, 1));

            FloatPortal p0 = new FloatPortal(scene);
            FloatPortal p1 = new FloatPortal(scene);
            Portal.SetLinked(p0, p1);

            p0.SetTransform(new Transform2(new Vector2(1, 0)));
            p1.SetTransform(new Transform2(new Vector2(50, 0)));

            FloatPortal p2 = new FloatPortal(scene);
            FloatPortal p3 = new FloatPortal(scene);
            Portal.SetLinked(p2, p3);

            p2.SetTransform(new Transform2(new Vector2(-1, 0)));
            p3.SetTransform(new Transform2(new Vector2(-50, 0)));

            scene.Step();

            MassData result = GetLocalMassData(actor.Body);

            Assert.AreEqual(actor.GetMass() / 2.0f, result.Mass, Delta);
            Assert.IsTrue((new Vector2() - result.Centroid).Length < Delta);
        }
コード例 #2
0
ファイル: BodyExtTests.cs プロジェクト: AyyTee/Aventyr
        public void GetLocalMassDataTest1()
        {
            Scene scene = new Scene();
            scene.Gravity = new Vector2();
            Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(4, 1));

            FloatPortal enter = new FloatPortal(scene);
            FloatPortal exit = new FloatPortal(scene);
            Portal.SetLinked(enter, exit);

            enter.SetTransform(new Transform2(new Vector2(1, 0)));
            exit.SetTransform(new Transform2(new Vector2(50, 0)));

            scene.Step();

            MassData result = GetLocalMassData(actor.Body);

            Assert.AreEqual(actor.GetMass() * 3.0f / 4.0f, result.Mass, Delta);
            Assert.IsTrue((new Vector2(-0.5f, 0) - result.Centroid).Length < Delta);
        }
コード例 #3
0
ファイル: SceneTests.cs プロジェクト: AyyTee/Aventyr
        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);
            }
        }
コード例 #4
0
ファイル: ActorTests.cs プロジェクト: AyyTee/Aventyr
        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);
        }
コード例 #5
0
ファイル: ActorTests.cs プロジェクト: AyyTee/Aventyr
        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);
        }