public static FBBody CreateCircle(float radius, Vector2 offset) { var body = new FBBody(); body.collider = new FBCircle(radius, offset); return(body); }
public static FBBody CreatePolygon(List <Vector2> points) { var body = new FBBody(); FBPolygon collider = new FBPolygon(); points.ForEach(x => collider.AddPoint(x.X, x.Y)); body.collider = collider; return(body); }
private FBQuadTreeNode GetValidSubNode(FBBody body) { foreach (var subNode in subNodes) { if (subNode.bounds.Contains(body.AABB)) { return(subNode); } } return(null); }
public static FBBody CreateRectangle(float width, float height, bool centered) { var body = new FBBody(); if (centered) { body.collider = new FBRectangle(-width / 2, -height / 2, width / 2, height / 2); } else { body.collider = new FBRectangle(0, 0, width, height); } return(body); }
private static List <CollisionInfo> GetPairsForBody(FBBody firstBody) { List <CollisionInfo> pairs = new List <CollisionInfo>(); var x = firstBody.AABB.Left; var y = firstBody.AABB.Top; var x2 = firstBody.AABB.Right; var y2 = firstBody.AABB.Bottom; if (firstBody.MovementX >= 0) { x2 += (int)firstBody.MovementX; } else { x -= (int)firstBody.MovementX; } if (firstBody.MovementY >= 0) { y2 += (int)firstBody.MovementY; } else { y -= (int)firstBody.MovementY; } var sweptAABB = new Rectangle(x, y, x2 - x, y2 - y); var potentials = bodiesHash.GetRectangle(sweptAABB); foreach (var p in potentials) { if (p != firstBody) { pairs.Add(new CollisionInfo() { BodyA = firstBody, BodyB = p }); } } return(pairs); }
public void AddBody(FBBody body) { if (subNodes == null) { bodies.Add(body); if (bodies.Count >= capacity && level != maxLevel) { Split(); int i = 0; while (i < bodies.Count) { var subNode = GetValidSubNode(bodies[i]); if (subNode != null) { subNode.AddBody(bodies[i]); bodies.RemoveAt(i); } else { i++; } } } } else { var subnode = GetValidSubNode(body); if (subnode != null) { subnode.AddBody(body); } else { bodies.Add(body); } } }
public static void AddBody(FBBody body) { bodies.Add(body); }
public List <FBBody> Nearby(FBBody body) { return(null); }
public void AddBody(FBBody body) { mainNode.AddBody(body); }