コード例 #1
0
ファイル: Bullet.cs プロジェクト: AyyTee/Aventyr
 private void Bullet_OnCollision(Actor collidingWith, bool firstEvent)
 {
     if (collidingWith is Wall)
     {
         Remove();
     }
 }
コード例 #2
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);
        }
コード例 #3
0
ファイル: BodyExt.cs プロジェクト: AyyTee/Aventyr
 /// <summary>
 /// Create body and assign it to an Actor instance.
 /// </summary>
 public static Body CreateBody(World world, Actor actor)
 {
     Debug.Assert(actor != null);
     Debug.Assert(actor.Body == null);
     Debug.Assert(world != null);
     Body body = CreateBody(world);
     SetData(body, actor);
     return body;
 }
コード例 #4
0
ファイル: Player.cs プロジェクト: AyyTee/Aventyr
 public void SetActor(Actor actor)
 {
     if (Actor != null)
     {
         Actor.EnterPortal -= EnterPortal;
     }
     Actor = actor;
     Actor.EnterPortal += EnterPortal;
 }
コード例 #5
0
ファイル: BodyExtTests.cs プロジェクト: AyyTee/Aventyr
        public void GetLocalMassDataTest0()
        {
            Scene scene = new Scene();
            scene.Gravity = new Vector2();
            Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(4, 1));

            MassData result = GetLocalMassData(actor.Body);

            Assert.AreEqual(actor.GetMass(), result.Mass);
            Assert.AreEqual(new Vector2(), result.Centroid);
        }
コード例 #6
0
ファイル: FixtureExtTests.cs プロジェクト: AyyTee/Aventyr
        public void GetFixtureEdgeCoordTest3()
        {
            Scene scene = new Scene();
            Vector2[] vertices = GetVertices();
            Actor actor = new Actor(scene, vertices);
            actor.SetTransform(new Transform2(new Vector2(), 1, 0, true));
            PolygonCoord polyCoord = new PolygonCoord(4, 0.4f);
            FixtureCoord fixtureCoord = FixtureExt.GetFixtureEdgeCoord(actor, polyCoord);

            Assert.IsTrue(PolygonExt.GetTransform(vertices, polyCoord) == PolygonExt.GetTransform(fixtureCoord));
        }
コード例 #7
0
        public Vector2[][] GetPortalFixtures(Actor ground)
        {
            FixtureData userData = FixtureExt.GetData(ground.Body.FixtureList[0]);
            userData.ProcessChanges();

            Vector2[][] verticeArray = new Vector2[userData.FixtureChildren.Count][];
            for (int i = 0; i < verticeArray.Length; i++)
            {
                verticeArray[i] = Vector2Ext.ToOtk(((PolygonShape)userData.FixtureChildren[i].Shape).Vertices);
            }
            return verticeArray;
        }
コード例 #8
0
ファイル: ActorTests.cs プロジェクト: AyyTee/Aventyr
        public void GetCentroidTest0()
        {
            Scene scene = new Scene();
            Actor actor = new Actor(scene, PolygonFactory.CreateRectangle(0.5f, 3f));
            Vector2 centroid = actor.GetCentroid();
            foreach (BodyData data in Tree<BodyData>.GetAll(BodyExt.GetData(actor.Body)))
            {
                data.Body.LocalCenter = actor.Body.GetLocalPoint((Xna.Vector2)centroid);
            }

            //LocalCenter and centroid should be the same since the actor is on the origin with no rotation.
            Assert.IsTrue((Xna.Vector2)actor.Body.LocalCenter == (Xna.Vector2)centroid);
            Assert.IsTrue(centroid == new Vector2());
        }
コード例 #9
0
 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;
 }
コード例 #10
0
ファイル: FixtureExtTests.cs プロジェクト: AyyTee/Aventyr
        public void GetFixtureEdgeCoordTest0()
        {
            Scene scene = new Scene();
            Vector2[] vertices = new Vector2[] {
                new Vector2(-1, -1),
                new Vector2(1, -1),
                new Vector2(1, 1),
                new Vector2(-1, 1)
            };
            Actor actor = new Actor(scene, vertices);
            PolygonCoord polyCoord = new PolygonCoord(3, 0.4f);
            FixtureCoord fixtureCoord = FixtureExt.GetFixtureEdgeCoord(actor, polyCoord);

            Assert.IsTrue(fixtureCoord.EdgeT == polyCoord.EdgeT);
            Assert.IsTrue(PolygonExt.GetTransform(vertices, polyCoord) == PolygonExt.GetTransform(fixtureCoord));
        }
コード例 #11
0
ファイル: MoveAction.cs プロジェクト: Blecki/GnomeColony
        public override void Update(Actor Actor, float StepPercentage)
        {
            if (!Done)
            {
                if (StepPercentage >= 1.0f)
                    Actor.PositionOffset = Vector3.Zero;
                else
                {
                    var realPosition = Vector3.Zero;
                    if (StepPercentage < 0.5f)
                        realPosition = SplinePoints[0] + ((SplinePoints[1] - SplinePoints[0]) * (StepPercentage / 0.5f));
                    else
                        realPosition = SplinePoints[1] + ((SplinePoints[2] - SplinePoints[1]) * ((StepPercentage - 0.5f) / 0.5f));

                    Actor.PositionOffset = realPosition - SplinePoints[2];
                }
            }
        }
コード例 #12
0
ファイル: FixtureExtTests.cs プロジェクト: AyyTee/Aventyr
        public void GetFixtureEdgeCoordTest2()
        {
            Scene scene = new Scene();
            Vector2[] vertices = new Vector2[] {
                new Vector2(0, 0),
                new Vector2(1, 0),
                new Vector2(1, 1),
                new Vector2(0, 1)
            };
            Actor actor = new Actor(scene, vertices);
            actor.SetTransform(new Transform2(new Vector2(), 1, 0, true));
            PolygonCoord polyCoord = new PolygonCoord(0, 0f);
            FixtureCoord fixtureCoord = FixtureExt.GetFixtureEdgeCoord(actor, polyCoord);

            Transform2 expected = PolygonExt.GetTransform(actor.GetWorldVertices(), polyCoord);
            Transform2 result = PolygonExt.GetTransform(fixtureCoord);
            Assert.IsTrue(expected.AlmostEqual(result));
        }
コード例 #13
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);
        }
コード例 #14
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);
            }
        }
コード例 #15
0
ファイル: ActorEventSource.cs プロジェクト: yiminhao/cloud
 public void ActorMessage(Actor actor, string message, params object[] args)
 {
     if (this.IsEnabled()
         && actor.Id != null
         && actor.ActorService != null
         && actor.ActorService.Context != null
         && actor.ActorService.Context.CodePackageActivationContext != null)
     {
         string finalMessage = string.Format(message, args);
         ActorMessage(
             actor.GetType().ToString(),
             actor.Id.ToString(),
             actor.ActorService.Context.CodePackageActivationContext.ApplicationTypeName,
             actor.ActorService.Context.CodePackageActivationContext.ApplicationName,
             actor.ActorService.Context.ServiceTypeName,
             actor.ActorService.Context.ServiceName.ToString(),
             actor.ActorService.Context.PartitionId,
             actor.ActorService.Context.ReplicaId,
             actor.ActorService.Context.NodeContext.NodeName,
             finalMessage);
     }
 }
コード例 #16
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);
        }
コード例 #17
0
ファイル: MoveAction.cs プロジェクト: Blecki/GnomeColony
 public override bool Step(Actor Actor)
 {
     Done = true;
     return true;
 }
コード例 #18
0
ファイル: SimulationStepTests.cs プロジェクト: AyyTee/Aventyr
        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);
        }
コード例 #19
0
ファイル: Actor.cs プロジェクト: AyyTee/Aventyr
 public override IDeepClone ShallowClone()
 {
     Actor clone = new Actor(Scene, Vertices, GetTransform());
     ShallowClone(clone);
     return clone;
 }
コード例 #20
0
ファイル: Actor.cs プロジェクト: AyyTee/Aventyr
 /// <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);
 }
コード例 #21
0
ファイル: FixtureExtTests.cs プロジェクト: AyyTee/Aventyr
        public void GetWorldPointsTest3()
        {
            Scene scene = new Scene();
            Vector2[] vertices = new Vector2[] {
                new Vector2(0, 0),
                new Vector2(2.2f, 0),
                new Vector2(1, 1),
                new Vector2(0, 1)
            };
            Actor actor = new Actor(scene, vertices);
            actor.SetTransform(new Transform2(new Vector2(4.2f, -5.5f), -2f, -2f, true));
            PortalCommon.UpdateWorldTransform(scene);
            scene.World.ProcessChanges();

            Vector2[] fixtureVertices = FixtureExt.GetWorldPoints(actor.Body.FixtureList[0]);
            Assert.IsTrue(MathExt.IsIsomorphic(actor.GetWorldVertices(), fixtureVertices, (item0, item1) => (item0 - item1).Length < 0.001f));
        }
コード例 #22
0
ファイル: FixtureExtTests.cs プロジェクト: AyyTee/Aventyr
        public void GetWorldPointsTest0()
        {
            Scene scene = new Scene();
            Vector2[] vertices = new Vector2[] {
                new Vector2(0, 0),
                new Vector2(2.2f, 0),
                new Vector2(1, 1),
                new Vector2(0, 1)
            };
            Actor actor = new Actor(scene, vertices);
            PortalCommon.UpdateWorldTransform(scene);

            Vector2[] fixtureVertices = Vector2Ext.ToOtk(((PolygonShape)actor.Body.FixtureList[0].Shape).Vertices);
            Assert.IsTrue(MathExt.IsIsomorphic(actor.GetWorldVertices(), fixtureVertices));
        }
コード例 #23
0
ファイル: Actor.cs プロジェクト: AyyTee/Aventyr
 /// <summary>
 /// Verifies the BodyType for Actor bodies is correct.
 /// </summary>
 /// <returns></returns>
 public static void AssertBodyType(Actor actor)
 {
     if (actor.Body.BodyType != actor.BodyType)
     {
         Debug.Fail("");
     }
     foreach (BodyData data in BodyExt.GetData(actor.Body).Children)
     {
         _assertBodyType(data);
     }
 }
コード例 #24
0
ファイル: ActorAction.cs プロジェクト: Blecki/GnomeColony
 public virtual void Begin(Actor Actor)
 {
 }
コード例 #25
0
ファイル: Actor.cs プロジェクト: AyyTee/Aventyr
        public static void AssertTransform(Actor actor)
        {
            /*Bodies don't have a scale component so we use the default scale when comparing the Actor's
             * scale to that of the child bodies.*/
            Transform2 actorTransform = actor.WorldTransform;
            actorTransform.SetScale(Vector2.One);

            /*foreach (BodyData data in Tree<BodyData>.GetAll(BodyExt.GetData(actor.Body)))
            {
                Transform2 bodyTransform = UndoPortalTransform(data, BodyExt.GetTransform(data.Body));
                bodyTransform.SetScale(Vector2.One);
                Debug.Assert(bodyTransform.AlmostEqual(actorTransform, 0.01f, 0.01f));
            }*/
        }
コード例 #26
0
ファイル: ActorAction.cs プロジェクト: Blecki/GnomeColony
 public virtual bool Step(Actor Actor)
 {
     return true;
 }
コード例 #27
0
ファイル: Actor.cs プロジェクト: AyyTee/Aventyr
 public void CallOnCollision(Actor collidingWith, bool firstEvent)
 {
     OnCollision?.Invoke(collidingWith, firstEvent);
 }
コード例 #28
0
ファイル: ActorAction.cs プロジェクト: Blecki/GnomeColony
 public virtual void Update(Actor Actor, float StepPercentage)
 {
 }
コード例 #29
0
ファイル: Actor.cs プロジェクト: AyyTee/Aventyr
 protected void ShallowClone(Actor destination)
 {
     base.ShallowClone(destination);
     BodyData bodyData = BodyExt.SetData(destination.Body, destination);
     foreach (Fixture f in destination.Body.FixtureList)
     {
         FixtureData fixtureData = FixtureExt.SetData(f);
     }
 }
コード例 #30
0
ファイル: SimulationStepTests.cs プロジェクト: AyyTee/Aventyr
        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));
        }