/// <summary>
        /// Draws an outline of a collision shape
        /// </summary>
        /// <param name="shape">shape to draw</param>
        /// <param name="g">Graphics object</param>
        /// <param name="transform">shape camera transform</param>
        /// <param name="p">pen</param>
        private static void DrawShape(this Shape shape, Graphics g, FarseerPhysics.Common.Transform transform, Pen p)
        {
            switch (shape.ShapeType)
            {
            case ShapeType.Circle:
                CircleShape circle = shape as CircleShape;
                g.DrawEllipse(p,
                              circle.Position.X - circle.Radius,
                              circle.Position.Y - circle.Radius,
                              circle.Position.X + circle.Radius,
                              circle.Position.Y + circle.Radius);
                break;

            case ShapeType.Chain:
                ChainShape            chain = shape as ChainShape;
                IEnumerable <Vector2> verts = chain.Vertices;
                g.DrawLines(
                    p,
                    chain.Vertices.Select((v) => v.Transform(transform)).ToDrawingPoints().ToArray()
                    );
                break;

            case ShapeType.Edge:
                EdgeShape edge = shape as EdgeShape;
                PointF    p1   = edge.Vertex1.Transform(transform).ToDrawingPoint();
                PointF    p2   = edge.Vertex2.Transform(transform).ToDrawingPoint();
                g.DrawLine(p, p1, p2);
                break;

            case ShapeType.Polygon:
                PolygonShape poly = shape as PolygonShape;
                g.DrawPolygon(p, poly.Vertices.Select((v) => v.Transform(transform)).ToDrawingPoints().ToArray());
                break;
            }
        }
Ejemplo n.º 2
0
        public override Atom.Math.RectangleF GetBounds()
        {
            if (this.fixtures == null)
            {
                return(new Atom.Math.RectangleF());
            }

            var     trans   = new FarseerPhysics.Common.Transform();
            Fixture fixture = this.fixtures[0];

            fixture.Body.GetTransform(out trans);

            FarseerPhysics.Collision.AABB fullAabb;
            fixture.Shape.ComputeAABB(out fullAabb, ref trans, 0);

            for (int i = 1; i < this.fixtures.Count; ++i)
            {
                fixture = this.fixtures[i];
                fixture.Body.GetTransform(out trans);

                FarseerPhysics.Collision.AABB aabb;
                fixture.Shape.ComputeAABB(out aabb, ref trans, 0);

                fullAabb.Combine(ref aabb);
            }

            var corner  = fullAabb.LowerBound;
            var extends = fullAabb.Extents;

            return(new Atom.Math.RectangleF(corner.X, corner.Y, extends.X * 2.0f, extends.Y * 2.0f));
        }
Ejemplo n.º 3
0
 // v2 = A.R' * (B.R * v1 + B.p - A.p) = (A.R' * B.R) * v1 + (B.p - A.p)
 public static void MultiplyT(ref Transform A, ref Transform B, out Transform C)
 {
     C = new Transform();
     MultiplyT(ref A.R, ref B.R, out C.R);
     C.Position.x = B.Position.x - A.Position.x;
     C.Position.y = B.Position.y - A.Position.y;
 }
Ejemplo n.º 4
0
        public static Vector2 MultiplyT(ref Transform T, ref Vector2 v)
        {
            Vector2 tmp = Vector2.zero;

            tmp.x = v.x - T.Position.x;
            tmp.y = v.y - T.Position.y;
            return(MultiplyT(ref T.R, ref tmp));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get the interpolated transform at a specific time.
        /// </summary>
        /// <param name="xf">The transform.</param>
        /// <param name="beta">beta is a factor in [0,1], where 0 indicates alpha0.</param>
        public void GetTransform(out Transform xf, float beta)
        {
            xf            = new Transform();
            xf.Position.x = (1.0f - beta) * C0.x + beta * C.x;
            xf.Position.y = (1.0f - beta) * C0.y + beta * C.y;
            float angle = (1.0f - beta) * A0 + beta * A;

            xf.R.Set(angle);

            // Shift to origin
            xf.Position -= MathUtils.Multiply(ref xf.R, ref LocalCenter);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Build vertices to represent an oriented box.
        /// </summary>
        /// <param name="hx">the half-width.</param>
        /// <param name="hy">the half-height.</param>
        /// <param name="center">the center of the box in local coordinates.</param>
        /// <param name="angle">the rotation of the box in local coordinates.</param>
        public static Vertices CreateRectangle(float hx, float hy, Vector2 center, float angle)
        {
            Vertices vertices = CreateRectangle(hx, hy);

            Transform xf = new Transform();

            xf.Position = center;
            xf.R.Set(angle);

            // Transform vertices
            for (int i = 0; i < 4; ++i)
            {
                vertices[i] = MathUtils.Multiply(ref xf, vertices[i]);
            }

            return(vertices);
        }
Ejemplo n.º 7
0
        public override Atom.Math.RectangleF GetBounds()
        {
            if (this.fixture == null)
            {
                return(new Atom.Math.RectangleF());
            }

            var trans = new FarseerPhysics.Common.Transform();

            fixture.Body.GetTransform(out trans);

            FarseerPhysics.Collision.AABB aabb;
            fixture.Shape.ComputeAABB(out aabb, ref trans, 0);

            var corner  = aabb.LowerBound;
            var extends = aabb.Extents;

            return(new Atom.Math.RectangleF(corner.X, corner.Y, extends.X * 2.0f, extends.Y * 2.0f));
        }
Ejemplo n.º 8
0
 public override void DrawTransform(ref Transform transform)
 {
     // TODO: implement
 }
Ejemplo n.º 9
0
 public static Vector2 MultiplyT(ref Transform T, Vector2 v)
 {
     return(MultiplyT(ref T, ref v));
 }
Ejemplo n.º 10
0
 public static Vector2 Multiply(ref Transform T, ref Vector2 v)
 {
     return(new Vector2(T.Position.x + T.R.Col1.x * v.x + T.R.Col2.x * v.y,
                        T.Position.y + T.R.Col1.y * v.x + T.R.Col2.y * v.y));
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Build vertices to represent an oriented box.
        /// </summary>
        /// <param name="hx">the half-width.</param>
        /// <param name="hy">the half-height.</param>
        /// <param name="center">the center of the box in local coordinates.</param>
        /// <param name="angle">the rotation of the box in local coordinates.</param>
        public static Vertices CreateRectangle(float hx, float hy, Vector2 center, float angle)
        {
            Vertices vertices = CreateRectangle(hx, hy);

            Transform xf = new Transform();
            xf.Position = center;
            xf.R.Set(angle);

            // Transform vertices
            for (int i = 0; i < 4; ++i)
            {
                vertices[i] = MathUtils.Multiply(ref xf, vertices[i]);
            }

            return vertices;
        }