示例#1
0
        /// <summary>
        /// Duplicates the given Body along the given path for approximatly the given copies.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="path">The path.</param>
        /// <param name="shapes">The shapes.</param>
        /// <param name="type">The type.</param>
        /// <param name="copies">The copies.</param>
        /// <param name="userData"></param>
        /// <returns></returns>
        public static List <FSBody> EvenlyDistributeShapesAlongPath(FSWorld world, Path path, IEnumerable <Shape> shapes,
                                                                    BodyType type, int copies, object userData)
        {
            List <FVector3> centers  = path.SubdivideEvenly(copies);
            List <FSBody>   bodyList = new List <FSBody>();

            for (int i = 0; i < centers.Count; i++)
            {
                FSBody b = new FSBody(world);

                // copy the type from original body
                b.BodyType = type;
                b.Position = new FVector2(centers[i].X, centers[i].Y);
                b.Rotation = centers[i].Z;

                foreach (Shape shape in shapes)
                {
                    b.CreateFixture(shape, userData);
                }

                bodyList.Add(b);
            }

            return(bodyList);
        }
示例#2
0
        /// <summary>
        /// Creates a Wheel Joint and adds it to the world
        /// </summary>
        /// <param name="world"></param>
        /// <param name="bodyA"></param>
        /// <param name="bodyB"></param>
        /// <param name="localanchorB"></param>
        /// <param name="axis"></param>
        /// <returns></returns>
        public static FSWheelJoint CreateWheelJoint(FSWorld world, FSBody bodyA, FSBody bodyB, FVector2 localanchorB, FVector2 axis)
        {
            FSWheelJoint joint = CreateWheelJoint(bodyA, bodyB, localanchorB, axis);

            world.AddJoint(joint);
            return(joint);
        }
示例#3
0
        /// <summary>
        /// Creates a weld joint and adds it to the world
        /// </summary>
        /// <param name="world"></param>
        /// <param name="bodyA"></param>
        /// <param name="bodyB"></param>
        /// <param name="worldAnchor">World space coordinates of weld joint</param>
        /// <returns></returns>
        public static FSWeldJoint CreateWeldJoint(FSWorld world, FSBody bodyA, FSBody bodyB, FVector2 worldAnchor)
        {
            FSWeldJoint joint = CreateWeldJoint(bodyA, bodyB, worldAnchor);

            world.AddJoint(joint);
            return(joint);
        }
示例#4
0
        public static FSBody CreateBody(FSWorld world, FVector2 position, object userData)
        {
            FSBody body = CreateBody(world, userData);

            body.Position = position;
            return(body);
        }
示例#5
0
        public static FSBody CreateEdge(FSWorld world, FVector2 start, FVector2 end, object userData)
        {
            FSBody body = CreateBody(world);

            FixtureFactory.AttachEdge(start, end, body, userData);
            return(body);
        }
示例#6
0
        public static FSBody CreateCircle(FSWorld world, float radius, float density, FVector2 position, object userData)
        {
            FSBody body = CreateBody(world, position);

            FixtureFactory.AttachCircle(radius, density, body, userData);
            return(body);
        }
示例#7
0
        /// <summary>
        /// Creates a revolute joint and adds it to the world
        /// </summary>
        /// <param name="world"></param>
        /// <param name="bodyA"></param>
        /// <param name="bodyB"></param>
        /// <param name="anchor"></param>
        /// <returns></returns>
        public static FSRevoluteJoint CreateRevoluteJoint(FSWorld world, FSBody bodyA, FSBody bodyB, FVector2 anchor)
        {
            FSRevoluteJoint joint = CreateRevoluteJoint(bodyA, bodyB, anchor);

            world.AddJoint(joint);
            return(joint);
        }
示例#8
0
 public FSExplosion(FSWorld world)
     : base(world, PhysicsLogicType.Explosion)
 {
     _exploded = new Dictionary <FSFixture, List <FVector2> >();
     _rdc      = new RayDataComparer();
     _data     = new List <ShapeData>();
 }
示例#9
0
 public static FSBody CreateRoundedRectangle(FSWorld world, float width, float height, float xRadius,
                                             float yRadius,
                                             int segments, float density, object userData)
 {
     return(CreateRoundedRectangle(world, width, height, xRadius, yRadius, segments, density, FVector2.Zero,
                                   userData));
 }
示例#10
0
        public static FSFixedMouseJoint CreateFixedMouseJoint(FSWorld world, FSBody body, FVector2 target)
        {
            FSFixedMouseJoint joint = new FSFixedMouseJoint(body, target);

            world.AddJoint(joint);
            return(joint);
        }
示例#11
0
        /// <summary>
        /// Attaches the bodies with revolute joints.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="bodies">The bodies.</param>
        /// <param name="localAnchorA">The local anchor A.</param>
        /// <param name="localAnchorB">The local anchor B.</param>
        /// <param name="connectFirstAndLast">if set to <c>true</c> [connect first and last].</param>
        /// <param name="collideConnected">if set to <c>true</c> [collide connected].</param>
        /// <param name="minLength">Minimum length of the slider joint.</param>
        /// <param name="maxLength">Maximum length of the slider joint.</param>
        /// <returns></returns>
        public static List <FSSliderJoint> AttachBodiesWithSliderJoint(FSWorld world, List <FSBody> bodies, FVector2 localAnchorA,
                                                                       FVector2 localAnchorB, bool connectFirstAndLast,
                                                                       bool collideConnected, float minLength,
                                                                       float maxLength)
        {
            List <FSSliderJoint> joints = new List <FSSliderJoint>(bodies.Count + 1);

            for (int i = 1; i < bodies.Count; i++)
            {
                FSSliderJoint joint = new FSSliderJoint(bodies[i], bodies[i - 1], localAnchorA, localAnchorB, minLength,
                                                        maxLength);
                joint.CollideConnected = collideConnected;
                world.AddJoint(joint);
                joints.Add(joint);
            }

            if (connectFirstAndLast)
            {
                FSSliderJoint lastjoint = new FSSliderJoint(bodies[0], bodies[bodies.Count - 1], localAnchorA, localAnchorB,
                                                            minLength, maxLength);
                lastjoint.CollideConnected = collideConnected;
                world.AddJoint(lastjoint);
                joints.Add(lastjoint);
            }

            return(joints);
        }
示例#12
0
        //public static FixedFrictionJoint CreateFixedFrictionJoint(World world, Body body, Vector2 bodyAnchor)
        //{
        //    FixedFrictionJoint frictionJoint = new FixedFrictionJoint(body, bodyAnchor);
        //    world.AddJoint(frictionJoint);
        //    return frictionJoint;
        //}

        #endregion

        #region Gear Joint

        public static FSGearJoint CreateGearJoint(FSWorld world, FarseerJoint jointA, FarseerJoint jointB, float ratio)
        {
            FSGearJoint gearJoint = new FSGearJoint(jointA, jointB, ratio);

            world.AddJoint(gearJoint);
            return(gearJoint);
        }
示例#13
0
        public static FSBody CreatePolygon(FSWorld world, Vertices vertices, float density, FVector2 position,
                                           object userData)
        {
            FSBody body = CreateBody(world, position);

            FixtureFactory.AttachPolygon(vertices, density, body, userData);
            return(body);
        }
示例#14
0
        public static FSDistanceJoint CreateDistanceJoint(FSWorld world, FSBody bodyA, FSBody bodyB, FVector2 anchorA,
                                                          FVector2 anchorB)
        {
            FSDistanceJoint distanceJoint = new FSDistanceJoint(bodyA, bodyB, anchorA, anchorB);

            world.AddJoint(distanceJoint);
            return(distanceJoint);
        }
示例#15
0
        /// <summary>
        /// Creates an angle joint.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="bodyA">The first body.</param>
        /// <param name="bodyB">The second body.</param>
        /// <returns></returns>
        public static FSAngleJoint CreateAngleJoint(FSWorld world, FSBody bodyA, FSBody bodyB)
        {
            FSAngleJoint angleJoint = new FSAngleJoint(bodyA, bodyB);

            world.AddJoint(angleJoint);

            return(angleJoint);
        }
示例#16
0
        public static FSBody CreateEllipse(FSWorld world, float xRadius, float yRadius, int edges, float density,
                                           FVector2 position, object userData)
        {
            FSBody body = CreateBody(world, position);

            FixtureFactory.AttachEllipse(xRadius, yRadius, edges, density, body, userData);
            return(body);
        }
示例#17
0
        public static FSWeldJoint CreateWeldJoint(FSWorld world, FSBody bodyA, FSBody bodyB, FVector2 localAnchorA,
                                                  FVector2 localAnchorB)
        {
            FSWeldJoint weldJoint = new FSWeldJoint(bodyA, bodyB, localAnchorA, localAnchorB);

            world.AddJoint(weldJoint);
            return(weldJoint);
        }
示例#18
0
        public static FSSliderJoint CreateSliderJoint(FSWorld world, FSBody bodyA, FSBody bodyB, FVector2 anchorA,
                                                      FVector2 anchorB, float minLength, float maxLength)
        {
            FSSliderJoint sliderJoint = new FSSliderJoint(bodyA, bodyB, anchorA, anchorB, minLength, maxLength);

            world.AddJoint(sliderJoint);
            return(sliderJoint);
        }
示例#19
0
        //public static FixedDistanceJoint CreateFixedDistanceJoint(World world, Body body, Vector2 localAnchor,
        //                                                          Vector2 worldAnchor)
        //{
        //    FixedDistanceJoint distanceJoint = new FixedDistanceJoint(body, localAnchor, worldAnchor);
        //    world.AddJoint(distanceJoint);
        //    return distanceJoint;
        //}

        #endregion

        #region Friction Joint

        public static FSFrictionJoint CreateFrictionJoint(FSWorld world, FSBody bodyA, FSBody bodyB, FVector2 anchorA,
                                                          FVector2 anchorB)
        {
            FSFrictionJoint frictionJoint = new FSFrictionJoint(bodyA, bodyB, anchorA, anchorB);

            world.AddJoint(frictionJoint);
            return(frictionJoint);
        }
示例#20
0
        /// <summary>
        /// Creates a fixed angle joint.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="body">The body.</param>
        /// <returns></returns>
        public static FSFixedAngleJoint CreateFixedAngleJoint(FSWorld world, FSBody body)
        {
            FSFixedAngleJoint angleJoint = new FSFixedAngleJoint(body);

            world.AddJoint(angleJoint);

            return(angleJoint);
        }
示例#21
0
        public static FSBody CreateChainShape(FSWorld world, Vertices vertices, FVector2 position,
                                              object userData)
        {
            FSBody body = CreateBody(world, position);

            FixtureFactory.AttachChainShape(vertices, body, userData);
            return(body);
        }
示例#22
0
        public static FSBody CreateSolidArc(FSWorld world, float density, float radians, int sides, float radius,
                                            FVector2 position, float angle)
        {
            FSBody body = CreateBody(world);

            FixtureFactory.AttachSolidArc(density, radians, sides, radius, position, angle, body);
            return(body);
        }
示例#23
0
        public static FSBody CreateLineArc(FSWorld world, float radians, int sides, float radius, FVector2 position,
                                           float angle, bool closed)
        {
            FSBody body = CreateBody(world);

            FixtureFactory.AttachLineArc(radians, sides, radius, position, angle, closed, body);
            return(body);
        }
示例#24
0
        public static FSBody CreateCompoundPolygon(FSWorld world, List <Vertices> list, float density,
                                                   FVector2 position, object userData)
        {
            //We create a single body
            FSBody polygonBody = CreateBody(world, position);

            FixtureFactory.AttachCompoundPolygon(list, density, polygonBody, userData);
            return(polygonBody);
        }
示例#25
0
        public static FSPulleyJoint CreatePulleyJoint(FSWorld world, FSBody bodyA, FSBody bodyB, FVector2 groundAnchorA,
                                                      FVector2 groundAnchorB, FVector2 anchorA, FVector2 anchorB, float ratio)
        {
            FSPulleyJoint pulleyJoint = new FSPulleyJoint(bodyA, bodyB, groundAnchorA, groundAnchorB, anchorA, anchorB,
                                                          ratio);

            world.AddJoint(pulleyJoint);
            return(pulleyJoint);
        }
示例#26
0
        /// <summary>
        /// Duplicates the given Body along the given path for approximatly the given copies.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="path">The path.</param>
        /// <param name="shape">The shape.</param>
        /// <param name="type">The type.</param>
        /// <param name="copies">The copies.</param>
        /// <param name="userData">The user data.</param>
        /// <returns></returns>
        public static List <FSBody> EvenlyDistributeShapesAlongPath(FSWorld world, Path path, Shape shape, BodyType type,
                                                                    int copies, object userData)
        {
            List <Shape> shapes = new List <Shape>(1);

            shapes.Add(shape);

            return(EvenlyDistributeShapesAlongPath(world, path, shapes, type, copies, userData));
        }
示例#27
0
        public FarseerDebugViewUnity(FSWorld world)
            : base(world)
        {
            lineListBatch                  = new List <FDVertex>();
            triangleListBatch              = new List <FDVertex>();
            world.ContactManager.PreSolve += PreSolve;

            //Default flags
            AppendFlags(DebugViewFlags.Shape);
            AppendFlags(DebugViewFlags.Controllers);
            AppendFlags(DebugViewFlags.Joint);
        }
示例#28
0
        /// <summary>
        /// Creates a breakable body. You would want to remove collinear points before using this.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="vertices">The vertices.</param>
        /// <param name="density">The density.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
        public static FSBreakableBody CreateBreakableBody(FSWorld world, Vertices vertices, float density, FVector2 position,
                                                          object userData)
        {
            List <Vertices> triangles = EarclipDecomposer.ConvexPartition(vertices);

            FSBreakableBody breakableBody = new FSBreakableBody(triangles, world, density, userData);

            breakableBody.MainBody.Position = position;
            world.AddBreakableBody(breakableBody);

            return(breakableBody);
        }
示例#29
0
        public FSBreakableBody(IEnumerable <Vertices> vertices, FSWorld world, float density, object userData)
        {
            _world = world;
            _world.ContactManager.PostSolve += PostSolve;
            MainBody          = new FSBody(_world);
            MainBody.BodyType = BodyType.Dynamic;

            foreach (Vertices part in vertices)
            {
                PolygonShape polygonShape = new PolygonShape(part, density);
                FSFixture    fixture      = MainBody.CreateFixture(polygonShape, userData);
                Parts.Add(fixture);
            }
        }
示例#30
0
        public static FSBody CreateGear(FSWorld world, float radius, int numberOfTeeth, float tipPercentage,
                                        float toothHeight, float density, object userData)
        {
            Vertices gearPolygon = PolygonTools.CreateGear(radius, numberOfTeeth, tipPercentage, toothHeight);

            //Gears can in some cases be convex
            if (!gearPolygon.IsConvex())
            {
                //Decompose the gear:
                List <Vertices> list = EarclipDecomposer.ConvexPartition(gearPolygon);

                return(CreateCompoundPolygon(world, list, density, userData));
            }

            return(CreatePolygon(world, gearPolygon, density, userData));
        }