Ejemplo n.º 1
0
        private PolygonShape CreatePortalShape(FixturePortal portal, bool previousVertex)
        {
            Vector2[] verts = new Vector2[3];

            PolygonShape shape = (PolygonShape)FixtureExt.GetFixtureAttached(portal).Shape;
            int i = 1;
            if (previousVertex)
            {
                i = 0;
            }
            int iNext = (i + 1) % 2;

            Transform2 t = portal.GetTransform();
            t.MirrorX = false;
            t.Size = Math.Abs(t.Size);

            int index = (portal.Position.EdgeIndex + i) % Actor.Vertices.Count;
            verts[0] = Vector2Ext.Transform(Portal.GetVerts(portal)[iNext], t.GetMatrix());
            verts[1] = Actor.GetFixtureContour(Actor)[index];
            verts[2] = Vector2Ext.Transform(Portal.GetVerts(portal)[iNext] + new Vector2(-FixturePortal.EdgeMargin, 0), t.GetMatrix());
            verts = MathExt.SetWinding(verts, false);

            return new PolygonShape(new FarseerPhysics.Common.Vertices(verts.Select(v => (Xna.Framework.Vector2)v)), 0);
        }
Ejemplo n.º 2
0
        private PolygonShape CreatePortalShape(FixturePortal portal, FixturePortal portalNext)
        {
            Debug.Assert(portal.Position.EdgeIndex == portalNext.Position.EdgeIndex);
            Debug.Assert(portal.Position.EdgeT < portalNext.Position.EdgeT);
            Vector2[] verts = new Vector2[4];

            {
                Transform2 t0 = portal.GetTransform();
                t0.MirrorX = false;
                t0.Size = Math.Abs(t0.Size);
                verts[0] = Vector2Ext.Transform(Portal.GetVerts(portal)[0], t0.GetMatrix());
                verts[1] = Vector2Ext.Transform(Portal.GetVerts(portal)[0] + new Vector2(-FixturePortal.EdgeMargin, 0), t0.GetMatrix());
            }

            {
                Transform2 t1 = portalNext.GetTransform();
                t1.MirrorX = false;
                t1.Size = Math.Abs(t1.Size);
                verts[2] = Vector2Ext.Transform(Portal.GetVerts(portalNext)[1] + new Vector2(-FixturePortal.EdgeMargin, 0), t1.GetMatrix());
                verts[3] = Vector2Ext.Transform(Portal.GetVerts(portalNext)[1], t1.GetMatrix());
            }
            verts = MathExt.SetWinding(verts, false);
            return new PolygonShape(new FarseerPhysics.Common.Vertices(verts.Select(v => (Xna.Framework.Vector2)v)), 0);
        }