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); }
public void ChangeCentroidTest0() { Scene scene = new Scene(); 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)); Portal.SetLinked(portal0, portal1); PortalCommon.UpdateWorldTransform(scene); World world = new World(new Xna.Vector2(0, 0f)); Body body0 = Factory.CreateBox(world, new Vector2(1, 2)); Body body1 = Factory.CreateBox(world, new Vector2(1, 2)); Xna.Vector2 startPos = new Xna.Vector2(0, 1); body0.Position = startPos; body1.Position = startPos; Portal.Enter(portal0, body1); PortalJoint portalJoint = Factory.CreatePortalJoint(world, body0, body1, portal0); for (int i = 0; i < 10; i++) { body0.LocalCenter += new Xna.Vector2(0, 0.1f); body1.LocalCenter += new Xna.Vector2(0, 0.1f); world.Step(1 / (float)60); Assert.IsTrue(body0.Position == startPos); } }
public void UpdateWorldTransformTest0() { /*Scene scene = new Scene(); NodePortalable parent = new NodePortalable(scene); FloatPortal p0 = new FloatPortal(scene); p0.SetParent(parent); FloatPortal p1 = new FloatPortal(scene); FloatPortal p2 = new FloatPortal(scene); p0.SetTransform(new Transform2(new Vector2(5, 0))); p1.SetTransform(new Transform2(new Vector2(-5, 0))); p2.SetTransform(new Transform2(new Vector2(0, 5))); Portal.SetLinked(p1, p2); PortalCommon.UpdateWorldTransform(scene);*/ Scene scene = new Scene(); Actor ground = CreateGround(scene); FloatPortal portal = new FloatPortal(scene); portal.Name = "enter"; portal.SetTransform(new Transform2(new Vector2(3, 0))); portal.SetParent(ground); FloatPortal portalExit = new FloatPortal(scene); portalExit.Name = "exit"; portalExit.Linked = portal; portal.Linked = portal; PortalCommon.UpdateWorldTransform(scene); //Assert.IsTrue() }
public void GetPortalTransformTest2() { Scene scene = new Scene(); FloatPortal p0 = new FloatPortal(scene); p0.SetTransform(new Transform2(new Vector2(1, 2), 4, 23)); FloatPortal p1 = new FloatPortal(scene); p1.SetTransform(new Transform2(new Vector2(4, -1), 1.4f, -3, true)); PortalCommon.UpdateWorldTransform(scene); Transform2 result = Portal.GetLinkedTransform(p0, p1); Assert.IsTrue(Matrix4Ext.AlmostEqual(result.GetMatrix(), Portal.GetLinkedMatrix(p0, p1))); }
public Scene CreateSceneWithPortal(out Actor ground) { Scene scene = new Scene(); ground = CreateGround(scene); scene.World.ProcessChanges(); Fixture fixture = ground.Body.FixtureList[0]; FixturePortal portal = new FixturePortal(scene, ground, new PolygonCoord(0, 0.3f)); FloatPortal portalExit = new FloatPortal(scene); portalExit.Linked = portal; portal.Linked = portal; PortalCommon.UpdateWorldTransform(scene); FixtureExt.GetData(fixture).ProcessChanges(); return scene; }
public void GetPortalTransformTest0() { Scene scene = new Scene(); FloatPortal p0 = new FloatPortal(scene); p0.SetTransform(new Transform2(new Vector2(1, 2), 1, 0)); FloatPortal p1 = new FloatPortal(scene); p1.SetTransform(new Transform2(new Vector2(0, 0), 1f, 0)); PortalCommon.UpdateWorldTransform(scene); Transform2 t = Portal.GetLinkedTransform(p0, p1); Matrix4 result = t.GetMatrix(); Matrix4 expected = Portal.GetLinkedMatrix(p0, p1); Assert.IsTrue(Matrix4Ext.AlmostEqual(result, expected)); }
public void StepTest1() { Scene scene = new Scene(); Portalable p = new Portalable(scene); Transform2 start = new Transform2(new Vector2(1, 5), 2.3f, 3.9f); Transform2 velocity = Transform2.CreateVelocity(new Vector2(-3, 4), 23, 0.54f); p.SetTransform(start); p.SetVelocity(velocity); //Scene scene = new Scene(); FloatPortal portal = new FloatPortal(scene); PortalCommon.UpdateWorldTransform(new IPortalCommon[] { p, portal }); SimulationStep.Step(new IPortalCommon[] { p }, new IPortal[] { portal }, 1, null); Assert.IsTrue(p.GetTransform().AlmostEqual(start.Add(velocity))); }
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); }
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); } }
public void PortalJointTest0() { Scene scene = new Scene(); FloatPortal portal0 = new FloatPortal(scene); FloatPortal portal1 = new FloatPortal(scene); portal0.SetTransform(new Transform2(new Vector2(), 1, 0, true)); portal1.SetTransform(new Transform2(new Vector2(), 1, 0)); portal0.Linked = portal1; portal1.Linked = portal0; PortalCommon.UpdateWorldTransform(scene); World world = new World(new Xna.Vector2(0, 0f)); Body body0 = Factory.CreateBox(world, new Vector2(1, 2)); Body body1 = Factory.CreateBox(world, new Vector2(1, 2)); body0.IgnoreCollisionWith(body1); PortalJoint portalJoint = Factory.CreatePortalJoint(world, body0, body1, portal0); body0.ApplyLinearImpulse(new Xna.Vector2(1, 0), new Xna.Vector2(0, 0)); world.Step(1 / (float)60); AssertPortalJoint(body0, body1, portal0); }
public void EnterTest0() { Scene scene = new Scene(); NodePortalable parent = new NodePortalable(scene); FloatPortal portal = new FloatPortal(scene); portal.SetTransform(new Transform2(new Vector2(5, 0))); portal.SetParent(parent); FloatPortal enter = new FloatPortal(scene); FloatPortal exit = new FloatPortal(scene); enter.SetTransform(new Transform2(new Vector2(2, 0))); exit.SetTransform(new Transform2(new Vector2(100, 5))); enter.Linked = exit; exit.Linked = enter; PortalCommon.UpdateWorldTransform(scene); Portal.Enter(enter, parent, 0.5f); PortalCommon.UpdateWorldTransform(scene); Assert.IsTrue(new Transform2(new Vector2(5, 0)).AlmostEqual(portal.WorldTransform)); }
public void StepTest2() { 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))); 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.GetTransform().Position == new Vector2(8, 10)); }
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 PathIntersectionsTest2() { Scene scene = new Scene(); FloatPortal p0 = new FloatPortal(scene); p0.SetTransform(new Transform2(new Vector2(1, 0))); FloatPortal p1 = new FloatPortal(scene); p1.SetTransform(new Transform2(new Vector2(2, 0), 1, (float)Math.PI)); p0.Linked = p1; p1.Linked = p0; FloatPortal p2 = new FloatPortal(scene); p2.SetTransform(new Transform2(new Vector2(3, 0))); FloatPortal p3 = new FloatPortal(scene); p3.SetTransform(new Transform2(new Vector2(6, 3), 1, (float)Math.PI/2)); p2.Linked = p3; p3.Linked = p2; PortalCommon.UpdateWorldTransform(scene); LineF ray = new LineF(new Vector2(0, 0), new Vector2(6, 2)); PortalPath path = new PortalPath(); path.Enter(p0); path.Enter(p2); var intersections = Portal.PathIntersections(path, ray); Assert.AreEqual(2, intersections.Length); Assert.AreEqual(0.5, intersections[0].TFirst, PATH_INTERSECTION_DELTA); Assert.AreEqual(1.0 / 3, intersections[0].TLast, PATH_INTERSECTION_DELTA); Assert.AreEqual(0.5, intersections[1].TFirst, PATH_INTERSECTION_DELTA); Assert.AreEqual(2.0 / 3, intersections[1].TLast, PATH_INTERSECTION_DELTA); }
public void PortalParentTest5() { Actor ground = null; Scene scene = CreateSceneWithPortal(out ground); FixturePortal portal0 = scene.GetPortalList().OfType<FixturePortal>().First(); FixturePortal portal1 = new FixturePortal(scene, ground, new PolygonCoord(0, 0.6f)); FloatPortal portal2 = new FloatPortal(scene); //Make sure portal2 isn't sitting on top of the float portal linked to portal0. portal2.SetTransform(new Transform2(new Vector2(5, 0))); portal1.Linked = portal2; portal2.Linked = portal1; FixtureData userData = FixtureExt.GetData(ground.Body.FixtureList[0]); PortalCommon.UpdateWorldTransform(scene); userData.ProcessChanges(); FixtureData userData0 = FixtureExt.GetData(ground.Body.FixtureList[0]); Assert.IsFalse(userData0.PartOfPortal(portal0)); Assert.IsFalse(userData0.PartOfPortal(portal1)); FixtureData userData1 = FixtureExt.GetData(ground.Body.FixtureList[1]); Assert.IsTrue(userData1.PartOfPortal(portal0)); Assert.IsFalse(userData1.PartOfPortal(portal1)); FixtureData userData2 = FixtureExt.GetData(ground.Body.FixtureList[2]); Assert.IsTrue(userData2.PartOfPortal(portal0)); Assert.IsTrue(userData2.PartOfPortal(portal1)); FixtureData userData3 = FixtureExt.GetData(ground.Body.FixtureList[3]); Assert.IsFalse(userData3.PartOfPortal(portal0)); Assert.IsTrue(userData3.PartOfPortal(portal1)); }
public void PortalJointTest4() { Scene scene = new Scene(); FloatPortal portal0 = new FloatPortal(scene); FloatPortal portal1 = new FloatPortal(scene); portal0.SetTransform(new Transform2(new Vector2(-5, 43), 1.4f, -3f)); portal1.SetTransform(new Transform2(new Vector2(10, 9.3f), -1.9f, 2.5f)); portal0.Linked = portal1; portal1.Linked = portal0; PortalCommon.UpdateWorldTransform(scene); World world = new World(new Xna.Vector2(0, 0f)); Body body0 = Factory.CreateBox(world, new Vector2(1, 2)); Body body1 = Factory.CreateBox(world, new Vector2(1, 2)); Portal.Enter(portal0, body1); PortalJoint portalJoint = Factory.CreatePortalJoint(world, body0, body1, portal0); world.Step(1 / (float)60); AssertPortalJoint(body0, body1, portal0); }
public void PortalParentTest4() { Actor ground = null; Scene scene = CreateSceneWithPortal(out ground); FixturePortal portal0 = scene.GetPortalList().OfType<FixturePortal>().First(); FixturePortal portal1 = new FixturePortal(scene, ground, new PolygonCoord(0, 0.6f)); FloatPortal portal2 = new FloatPortal(scene); //Make sure portal2 isn't sitting on top of the float portal linked to portal0. portal2.SetTransform(new Transform2(new Vector2(5, 0))); portal1.Linked = portal2; portal2.Linked = portal1; FixtureData userData = FixtureExt.GetData(ground.Body.FixtureList[0]); PortalCommon.UpdateWorldTransform(scene); userData.ProcessChanges(); PolygonShape shape; shape = (PolygonShape)ground.Body.FixtureList[0].Shape; Assert.IsTrue(shape.Vertices.Count == 5); shape = (PolygonShape)ground.Body.FixtureList[1].Shape; Assert.IsTrue(shape.Vertices.Count == 3); shape = (PolygonShape)ground.Body.FixtureList[2].Shape; Assert.IsTrue(shape.Vertices.Count == 4); shape = (PolygonShape)ground.Body.FixtureList[3].Shape; Assert.IsTrue(shape.Vertices.Count == 3); }
public override IDeepClone ShallowClone() { FloatPortal clone = new FloatPortal(Scene); ShallowClone(clone); return clone; }
/// <summary> /// Creates a Scene from an EditorScene. Scene is intended for gameplay use. /// </summary> public static Scene Export(EditorScene level, Controller controller) { Scene scene = new Scene(); /*if (level.GetAll().OfType<EditorPlayer>().Count() > 0) { Camera2 camera = new Camera2(scene); camera.SetTransform(new Transform2(new Vector2(), 10, 0)); scene.SetActiveCamera(camera); if (level.ActiveCamera != null) { camera.Aspect = level.ActiveCamera.Aspect; } } else*/ { if (level.ActiveCamera != null) { ControllerCamera camera = level.ActiveCamera.ShallowClone(); camera.Scene = scene; scene.SetActiveCamera(camera); } } #region create background Model background = Game.ModelFactory.CreatePlane(); background.Texture = level.Renderer.GetTexture("grid.png"); background.SetColor(new Vector3(1, 1, 0.5f)); background.Transform.Position = new Vector3(0, 0, -5f); float size = 50; background.Transform.Scale = new Vector3(size, size, size); background.TransformUv.Size = size; Entity back = new Entity(scene, new Vector2(0f, 0f)); back.Name = "Background"; back.AddModel(background); back.IsPortalable = false; #endregion Dictionary<EditorObject, SceneNode> dictionary = new Dictionary<EditorObject, SceneNode>(); AnimationDriver animation = new AnimationDriver(); scene.SceneObjectList.Add(animation); List<EditorObject> editorObjects = level.GetAll().OfType<EditorObject>().ToList(); foreach (EditorObject e in editorObjects) { if (e is EditorPortal) { EditorPortal cast = (EditorPortal)e; Entity entity = new Entity(scene); entity.IsPortalable = false; entity.AddModel(ModelFactory.CreatePortal()); entity.ModelList[0].Transform.Position += new Vector3(0, 0, -2); if (cast.OnEdge) { FixturePortal portal = new FixturePortal(scene); portal.Name = cast.Name; dictionary.Add(cast, portal); entity.SetParent(portal); } else { FloatPortal portal = new FloatPortal(scene); portal.Name = cast.Name; portal.SetTransform(cast.GetTransform()); dictionary.Add(cast, portal); entity.SetParent(portal); if (cast.AnimatedTransform != null) { animation.Add(portal, cast.AnimatedTransform); portal.SetTransform(cast.AnimatedTransform.GetTransform(0)); } else { portal.SetTransform(cast.GetTransform()); } } } else if (e is EditorEntity) { EditorEntity cast = (EditorEntity)e; Entity clone = new Entity(scene); clone.Name = cast.Name; clone.AddModelRange(cast.Models); dictionary.Add(cast, clone); if (cast.AnimatedTransform != null) { animation.Add(clone, cast.AnimatedTransform); clone.SetTransform(cast.AnimatedTransform.GetTransform(0)); } else { clone.SetTransform(cast.GetTransform()); } } else if (e is IWall) { EditorObject cast = e; Transform2 t = cast.GetTransform(); Actor actor = new Actor(scene, ((IWall)e).Vertices, t); actor.Name = cast.Name; Transform2 tEntity = new Transform2(); Entity entity = new Entity(scene, tEntity); entity.Name = cast.Name; entity.SetParent(actor); if (e is EditorWall) { EditorWall castWall = (EditorWall)e; actor.SetBodyType(BodyType.Static); //actor.Vertices = castWall.Vertices; entity.AddModel(Game.ModelFactory.CreatePolygon(castWall.Vertices)); //entity.AddModel(Game.ModelFactory.CreateActorDebug(actor)); dictionary.Add(castWall, actor); } else if (e is EditorActor) { //actor.SetVelocity(new Transform2(new Vector2(0.2f, 0))); EditorActor castActor = (EditorActor)e; //actor.Vertices = castActor.Vertices; entity.AddModel(castActor.GetActorModel(castActor)); //entity.AddModel(Game.ModelFactory.CreateActorDebug(actor)); dictionary.Add(castActor, actor); } else { Debug.Assert(false); } if (cast.AnimatedTransform != null) { animation.Add(actor, cast.AnimatedTransform); actor.SetTransform(cast.AnimatedTransform.GetTransform(0)); actor.SetBodyType(BodyType.Kinematic); } else { actor.SetTransform(cast.GetTransform()); } } else if (e is EditorPlayer) { EditorPlayer cast = (EditorPlayer)e; Player player = new Player(controller); Vector2[] polygon = PolygonFactory.CreateNGon(6, 0.5f, new Vector2()); Actor actor = new Actor(scene, polygon); player.SetActor(actor); actor.SetTransform(new Transform2(cast.GetWorldTransform().Position)); //player.Camera = (Camera2)scene.ActiveCamera; Entity entity = new Entity(scene, new Transform2()); entity.Name = cast.Name; entity.SetParent(actor); entity.AddModel(Game.ModelFactory.CreatePolygon(polygon)); scene.SceneObjectList.Add(player); dictionary.Add(cast, player.Actor); } else { Debug.Assert(false); } } foreach (EditorObject e in editorObjects) { SceneNode parent = e.Parent == null ? null : dictionary[e.Parent]; SceneNode clone = dictionary[e]; clone.SetParent(parent); if (clone is IPortal) { if (clone is FixturePortal) { FixturePortal cast = (FixturePortal)clone; cast.SetPosition((IWall)parent, ((EditorPortal)e).PolygonTransform, e.GetTransform().Size, e.GetTransform().MirrorX); Debug.Assert(((IWall)parent).Vertices.Count > 0); IPortal portalEditor = (IPortal)e; if (portalEditor.Linked != null) { cast.Linked = (IPortal)dictionary[(EditorPortal)portalEditor.Linked]; } } else if (clone is FloatPortal) { FloatPortal cast = (FloatPortal)clone; IPortal portalEditor = (IPortal)e; if (portalEditor.Linked != null) { cast.Linked = (IPortal)dictionary[(EditorPortal)portalEditor.Linked]; } } } } PortalCommon.UpdateWorldTransform(scene); return scene; }
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); }
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)); }
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); }
public void PathIntersectionsTest0() { Scene scene = new Scene(); FloatPortal p0 = new FloatPortal(scene); p0.SetTransform(new Transform2(new Vector2(1, 0))); FloatPortal p1 = new FloatPortal(scene); p1.SetTransform(new Transform2(new Vector2(10, -1))); p0.Linked = p1; p1.Linked = p0; PortalCommon.UpdateWorldTransform(scene); LineF ray = new LineF(new Vector2(0, 0), new Vector2(8, -1)); PortalPath path = new PortalPath(); path.Enter(p0); var intersections = Portal.PathIntersections(path, ray); Assert.AreEqual(1, intersections.Length); Assert.AreEqual(0.5, intersections[0].TFirst, PATH_INTERSECTION_DELTA); Assert.AreEqual(1.0 / 3, intersections[0].TLast, PATH_INTERSECTION_DELTA); }
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); }
public void IsInsideFOVTest7() { float x = 0; float y = 0; for (double i = 0; i < Math.PI * 2; i += Math.PI / 20) { Scene scene = new Scene(); FloatPortal p0 = new FloatPortal(scene); Entity node = new Entity(scene); Transform2.SetPosition(node, new Vector2(x, y)); Transform2.SetRotation(node, (float)(i + Math.PI / 4)); p0.SetParent(node); PortalCommon.UpdateWorldTransform(scene); Vector2 viewPoint = new Vector2(x + (float)Math.Cos(i), y + (float)Math.Sin(i)); Vector2 lookPoint = new Vector2(x + (float)Math.Cos(i) * 2, y + (float)Math.Sin(i) * 2); LineF line = new LineF(Vector2Ext.Transform(Portal.GetVerts(p0), p0.GetWorldTransform().GetMatrix())); Assert.IsFalse(line.IsInsideFOV(viewPoint, lookPoint)); } }
public void PortalParentTest3() { Actor ground = null; Scene scene = CreateSceneWithPortal(out ground); FixturePortal portal0 = scene.GetPortalList().OfType<FixturePortal>().First(); FixturePortal portal1 = new FixturePortal(scene, ground, new PolygonCoord(0, 0.6f)); FloatPortal portal2 = new FloatPortal(scene); //Make sure this portal isn't sitting on top of the float portal linked to portal0. portal2.SetTransform(new Transform2(new Vector2(5, 0))); portal1.Linked = portal2; portal2.Linked = portal1; FixtureData userData = FixtureExt.GetData(ground.Body.FixtureList[0]); PortalCommon.UpdateWorldTransform(scene); userData.ProcessChanges(); int parentCount = 0; foreach (Fixture f in ground.Body.FixtureList) { userData = FixtureExt.GetData(f); if (userData.IsPortalParentless() == false) { parentCount++; } } Assert.IsTrue(parentCount == 3); }