/// <summary> /// Creates the fixed revolute joint. /// </summary> /// <param name="world">The world.</param> /// <param name="body">The body.</param> /// <param name="bodyAnchor">The body anchor.</param> /// <param name="worldAnchor">The world anchor.</param> /// <returns></returns> public static FixedRevoluteJoint CreateFixedRevoluteJoint(PhysicsWorld world, PhysicsBody body, Vector2 bodyAnchor, Vector2 worldAnchor) { FixedRevoluteJoint fixedRevoluteJoint = new FixedRevoluteJoint(body, bodyAnchor, worldAnchor); world.AddJoint(fixedRevoluteJoint); return fixedRevoluteJoint; }
public static FixedDistanceJoint CreateFixedDistanceJoint(PhysicsWorld world, PhysicsBody body, Vector2 localAnchor, Vector2 worldAnchor) { FixedDistanceJoint distanceJoint = new FixedDistanceJoint(body, localAnchor, worldAnchor); world.AddJoint(distanceJoint); return distanceJoint; }
public static FixedPrismaticJoint CreateFixedPrismaticJoint(PhysicsWorld world, PhysicsBody body, Vector2 worldAnchor, Vector2 axis) { FixedPrismaticJoint joint = new FixedPrismaticJoint(body, worldAnchor, axis); world.AddJoint(joint); return joint; }
/// <summary> /// Creates a fixed angle joint. /// </summary> /// <param name="world">The world.</param> /// <param name="body">The body.</param> /// <returns></returns> public static FixedAngleJoint CreateFixedAngleJoint(PhysicsWorld world, PhysicsBody body) { FixedAngleJoint angleJoint = new FixedAngleJoint(body); world.AddJoint(angleJoint); return angleJoint; }
public static DistanceJoint CreateDistanceJoint(PhysicsWorld world, PhysicsBody bodyA, PhysicsBody bodyB, Vector2 anchorA, Vector2 anchorB) { DistanceJoint distanceJoint = new DistanceJoint(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 AngleJoint CreateAngleJoint(PhysicsWorld world, PhysicsBody bodyA, PhysicsBody bodyB) { AngleJoint angleJoint = new AngleJoint(bodyA, bodyB); world.AddJoint(angleJoint); return angleJoint; }
public override bool IsActiveOn(PhysicsBody body) { if (body.PhysicsLogicFilter.IsPhysicsLogicIgnored(_type)) return false; return base.IsActiveOn(body); }
public override bool IsActiveOn(PhysicsBody body) { if (body.ControllerFilter.IsControllerIgnored(_type)) return false; return base.IsActiveOn(body); }
public static Fixture AttachCircle(float radius, float density, PhysicsBody body, object userData) { if (radius <= 0) throw new ArgumentOutOfRangeException("radius", "Radius must be more than 0 meters"); CircleShape circleShape = new CircleShape(radius, density); return body.CreateFixture(circleShape, userData); }
public Entity ClosestEntity(Vector2 location, PhysicsBody[] list) { PhysicsBody closest = list[0]; foreach (PhysicsBody pb in list) if (Vector2.Distance(location, pb.Position) < Vector2.Distance(location, closest.Position)) closest = pb; return closest.UserData as Entity; }
public PhysicsBreakableBody(IEnumerable<Vertices> vertices, PhysicsWorld world, float density, object userData) { _world = world; _world.ContactManager.PostSolve += PostSolve; MainBody = new PhysicsBody(_world); MainBody.BodyType = BodyType.Dynamic; foreach (Vertices part in vertices) { PolygonShape polygonShape = new PolygonShape(part, density); Fixture fixture = MainBody.CreateFixture(polygonShape, userData); Parts.Add(fixture); } }
public Entity StrongestEntity(PhysicsBody[] list) { Entity strongest = default(Entity); double mostHealth = 0.0; foreach (PhysicsBody b in list) { Entity e = b.UserData as Entity; if (e.HasComponent<Health>()) { double health = e.GetComponent<Health>().CurrentHealth; if (health > mostHealth) { mostHealth = health; strongest = e; } } } return strongest; }
public static Vector2 CalculateOrigin(PhysicsBody b) { Vector2 lBound = new Vector2(float.MaxValue); AABB bounds; Transform trans; b.GetTransform(out trans); for (int i = 0; i < b.FixtureList.Count; ++i) { for (int j = 0; j < b.FixtureList[i].Shape.ChildCount; ++j) { b.FixtureList[i].Shape.ComputeAABB(out bounds, ref trans, j); Vector2.Min(ref lBound, ref bounds.LowerBound, out lBound); } } // calculate body offset from its center and add a 1 pixel border // because we generate the textures a little bigger than the actual body's fixtures return ConvertUnits.ToDisplayUnits(b.Position - lBound) + new Vector2(1f); }
public static List<Fixture> AttachCompoundPolygon(List<Vertices> list, float density, PhysicsBody body, object userData) { List<Fixture> res = new List<Fixture>(list.Count); //Then we create several fixtures using the body foreach (Vertices vertices in list) { if (vertices.Count == 2) { EdgeShape shape = new EdgeShape(vertices[0], vertices[1]); res.Add(body.CreateFixture(shape, userData)); } else { PolygonShape shape = new PolygonShape(vertices, density); res.Add(body.CreateFixture(shape, userData)); } } return res; }
public static Fixture AttachEdge(Vector2 start, Vector2 end, PhysicsBody body, object userData) { EdgeShape edgeShape = new EdgeShape(start, end); return body.CreateFixture(edgeShape, userData); }
public static Fixture AttachEdge(Vector2 start, Vector2 end, PhysicsBody body) { return AttachEdge(start, end, body, null); }
public static List<Fixture> AttachCompoundPolygon(List<Vertices> list, float density, PhysicsBody body) { return AttachCompoundPolygon(list, density, body, null); }
public static Fixture AttachCircle(float radius, float density, PhysicsBody body, Vector2 offset) { return AttachCircle(radius, density, body, offset, null); }
public static Fixture AttachLoopShape(Vertices vertices, PhysicsBody body) { return AttachLoopShape(vertices, body, null); }
public void Add(PhysicsBody body) { Debug.Assert(BodyCount < _bodyCapacity); Bodies[BodyCount++] = body; }
public static List<Fixture> AttachSolidArc(float density, float radians, int sides, float radius, Vector2 position, float angle, PhysicsBody body) { Vertices arc = PolygonTools.CreateArc(radians, sides, radius); arc.Rotate((MathHelper.Pi - radians) / 2 + angle); arc.Translate(ref position); //Close the arc arc.Add(arc[0]); List<Vertices> triangles = EarclipDecomposer.ConvexPartition(arc); return AttachCompoundPolygon(triangles, density, body); }
public static Fixture AttachRectangle(float width, float height, float density, Vector2 offset, PhysicsBody body) { return AttachRectangle(width, height, density, offset, body, null); }
public static Fixture AttachRectangle(float width, float height, float density, Vector2 offset, PhysicsBody body, object userData) { Vertices rectangleVertices = PolygonTools.CreateRectangle(width / 2, height / 2); rectangleVertices.Translate(ref offset); PolygonShape rectangleShape = new PolygonShape(rectangleVertices, density); return body.CreateFixture(rectangleShape, userData); }
public static Fixture AttachPolygon(Vertices vertices, float density, PhysicsBody body) { return AttachPolygon(vertices, density, body, null); }
public static Fixture AttachLoopShape(Vertices vertices, PhysicsBody body, object userData) { LoopShape shape = new LoopShape(vertices); return body.CreateFixture(shape, userData); }
public static Fixture AttachEllipse(float xRadius, float yRadius, int edges, float density, PhysicsBody body) { return AttachEllipse(xRadius, yRadius, edges, density, body, null); }
public static Fixture AttachEllipse(float xRadius, float yRadius, int edges, float density, PhysicsBody body, object userData) { if (xRadius <= 0) throw new ArgumentOutOfRangeException("xRadius", "X-radius must be more than 0"); if (yRadius <= 0) throw new ArgumentOutOfRangeException("yRadius", "Y-radius must be more than 0"); Vertices ellipseVertices = PolygonTools.CreateEllipse(xRadius, yRadius, edges); PolygonShape polygonShape = new PolygonShape(ellipseVertices, density); return body.CreateFixture(polygonShape, userData); }
public static Fixture AttachCircle(float radius, float density, PhysicsBody body) { return AttachCircle(radius, density, body, null); }
public static Fixture AttachPolygon(Vertices vertices, float density, PhysicsBody body, object userData) { if (vertices.Count <= 1) throw new ArgumentOutOfRangeException("vertices", "Too few points to be a polygon"); PolygonShape polygon = new PolygonShape(vertices, density); return body.CreateFixture(polygon, userData); }
public static List<Fixture> AttachLineArc(float radians, int sides, float radius, Vector2 position, float angle, bool closed, PhysicsBody body) { Vertices arc = PolygonTools.CreateArc(radians, sides, radius); arc.Rotate((MathHelper.Pi - radians) / 2 + angle); arc.Translate(ref position); List<Fixture> fixtures = new List<Fixture>(arc.Count); if (closed) { fixtures.Add(AttachLoopShape(arc, body)); } for (int i = 1; i < arc.Count; i++) { fixtures.Add(AttachEdge(arc[i], arc[i - 1], body)); } return fixtures; }