public FSCollisionBox setHeight(float height) { _height = height; _verts = PolygonTools.createRectangle(FSConvert.displayToSim * _width / 2, FSConvert.displayToSim * _height / 2); recreateFixture(); return(this); }
public FSCollisionBox setSize(float width, float height) { _width = width; _height = height; _verts = PolygonTools.createRectangle(FSConvert.displayToSim * _width / 2, FSConvert.displayToSim * _height / 2); _areVertsDirty = true; recreateFixture(); return(this); }
public static Fixture AttachRectangle(float width, float height, float density, Vector2 offset, Body body, object userData = null) { var rectangleVertices = PolygonTools.createRectangle(width / 2, height / 2); rectangleVertices.translate(ref offset); var rectangleShape = new PolygonShape(rectangleVertices, density); return(body.createFixture(rectangleShape, userData)); }
public static Body createCapsule(World world, float height, float endRadius, float density, Vector2 position = new Vector2(), float rotation = 0, BodyType bodyType = BodyType.Static, object userData = null) { //Create the middle rectangle var rectangle = PolygonTools.createRectangle(endRadius, height / 2); var list = new List <Vertices>(); list.Add(rectangle); var body = createCompoundPolygon(world, list, density, position, rotation, bodyType, userData); //Create the two circles FixtureFactory.attachCircle(endRadius, density, body, new Vector2(0, height / 2)); FixtureFactory.attachCircle(endRadius, density, body, new Vector2(0, -(height / 2))); return(body); }
/// <summary> /// Creates the chain. /// </summary> /// <returns>The chain.</returns> /// <param name="world">World.</param> /// <param name="start">Start.</param> /// <param name="end">End.</param> /// <param name="linkWidth">Link width.</param> /// <param name="linkHeight">Link height.</param> /// <param name="numberOfLinks">Number of links.</param> /// <param name="linkDensity">Link density.</param> /// <param name="attachRopeJoint">Creates a rope joint between start and end. This enforces the length of the rope. Said in another way: it makes the rope less bouncy.</param> /// <param name="fixStart">If set to <c>true</c> fix start.</param> /// <param name="fixEnd">If set to <c>true</c> fix end.</param> public static List <Body> CreateChain(World world, Vector2 start, Vector2 end, float linkWidth, float linkHeight, int numberOfLinks, float linkDensity, bool attachRopeJoint, bool fixStart = false, bool fixEnd = false) { Debug.Assert(numberOfLinks >= 2); // Chain start / end var path = new Path(); path.add(start); path.add(end); // A single chainlink var shape = new PolygonShape(PolygonTools.createRectangle(linkWidth, linkHeight), linkDensity); // Use PathManager to create all the chainlinks based on the chainlink created before. var chainLinks = PathManager.evenlyDistributeShapesAlongPath(world, path, shape, BodyType.Dynamic, numberOfLinks); if (fixStart) { // Fix the first chainlink to the world var axle = BodyFactory.CreateCircle(world, 0.1f, 1, chainLinks[0].position); JointFactory.CreateRevoluteJoint(world, chainLinks[0], axle, new Vector2(0, -(linkHeight / 2)), Vector2.Zero); } if (fixEnd) { // Fix the last chainlink to the world var lastIndex = chainLinks.Count - 1; var axle = BodyFactory.CreateCircle(world, 0.1f, 1, chainLinks[lastIndex].position); JointFactory.CreateRevoluteJoint(world, chainLinks[lastIndex], axle, new Vector2(0, -(linkHeight / 2)), Vector2.Zero); } // Attach all the chainlinks together with a revolute joint PathManager.attachBodiesWithRevoluteJoint(world, chainLinks, new Vector2(0, -linkHeight), new Vector2(0, linkHeight), false, false); if (attachRopeJoint) { JointFactory.CreateRopeJoint(world, chainLinks[0], chainLinks[chainLinks.Count - 1], Vector2.Zero, Vector2.Zero); } return(chainLinks); }
public static Body CreateRectangle(World world, float width, float height, float density, Vector2 position = new Vector2(), float rotation = 0, BodyType bodyType = BodyType.Static, object userData = null) { if (width <= 0) { throw new ArgumentOutOfRangeException(nameof(width), "Width must be more than 0 meters"); } if (height <= 0) { throw new ArgumentOutOfRangeException(nameof(height), "Height must be more than 0 meters"); } var newBody = CreateBody(world, position, rotation, bodyType); newBody.userData = userData; var rectangleVertices = PolygonTools.createRectangle(width / 2, height / 2); var rectangleShape = new PolygonShape(rectangleVertices, density); newBody.createFixture(rectangleShape); return(newBody); }
public FSCollisionBox(float width, float height) { _width = width; _height = height; _verts = PolygonTools.createRectangle(FSConvert.displayToSim * _width / 2, FSConvert.displayToSim * _height / 2); }
public FSBoxBody(Subtexture subtexture) : base(subtexture, PolygonTools.createRectangle(subtexture.sourceRect.Width / 2, subtexture.sourceRect.Height / 2)) { }