/// <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); }
/// <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); }
/// <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); }
public static FSBody CreateBody(FSWorld world, FVector2 position, object userData) { FSBody body = CreateBody(world, userData); body.Position = position; return(body); }
public static FSBody CreateEdge(FSWorld world, FVector2 start, FVector2 end, object userData) { FSBody body = CreateBody(world); FixtureFactory.AttachEdge(start, end, body, userData); return(body); }
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); }
/// <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); }
public FSExplosion(FSWorld world) : base(world, PhysicsLogicType.Explosion) { _exploded = new Dictionary <FSFixture, List <FVector2> >(); _rdc = new RayDataComparer(); _data = new List <ShapeData>(); }
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)); }
public static FSFixedMouseJoint CreateFixedMouseJoint(FSWorld world, FSBody body, FVector2 target) { FSFixedMouseJoint joint = new FSFixedMouseJoint(body, target); world.AddJoint(joint); return(joint); }
/// <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); }
//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); }
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); }
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); }
/// <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); }
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); }
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); }
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); }
//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); }
/// <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); }
public static FSBody CreateChainShape(FSWorld world, Vertices vertices, FVector2 position, object userData) { FSBody body = CreateBody(world, position); FixtureFactory.AttachChainShape(vertices, body, userData); return(body); }
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); }
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); }
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); }
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); }
/// <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)); }
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); }
/// <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); }
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); } }
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)); }