public IEnumerable <TItem> ElementsIn(Rectangle bounds) { if (_index == null) { _index = new SpatialQuadTreeIndex <TItem> { BoundsOf = item => new Rectangle(this.GetLocation(item), this.GetSize(item)), HasBounds = item => this.HasLocation(item) && this.HasSize(item) }; _index.AddRange(this.changedLocations.Keys); } var result = _index.Query(bounds); return(result); }
public World(ISpatialIndex <Rigidbody> tree) { _addToTempList = AddToTempList; var bodies = new List <Rigidbody>() { new Rigidbody() { fixture = new Capsule() { p0 = new Vec2(-1900, -300), p1 = new Vec2(0, 300), radius = 10, }, }, new Rigidbody() { fixture = new Capsule() { p0 = new Vec2(1900, -300), p1 = new Vec2(0, 300), radius = 10, }, }, }; for (var i = 0; i < PARTICLE_COUNT; i++) { bodies.Add(new Rigidbody { type = BodyType.Dynamic, position = new Vec2(-50 + 15 * (i % 8), 0 - 5 * i), fixture = new Capsule() { p0 = new Vec2(-particleSize, 0), p1 = new Vec2(+particleSize, 0), radius = particleSize, }, invMass = 1, invAngularMass = 0.03f, angle = 1, }); } bodies[bodies.Count - 2].invMass *= 0.1f; bodies[bodies.Count - 2].invAngularMass *= 0.1f; bodies[bodies.Count - 2].fixture.radius *= 2f; bodies[bodies.Count - 2].fixture.p0 *= 2f; bodies[bodies.Count - 2].fixture.p1 *= 2f; // bodies[bodies.Count - 1].invMass = 0f; // bodies[bodies.Count - 1].invAngularMass = 0.00005f; // bodies[bodies.Count - 1].fixture.radius = 120f; // bodies[bodies.Count - 1].fixture.p0 = new Vec2(-100, 0); // bodies[bodies.Count - 1].fixture.p1 = new Vec2(100, 0); this.tree = tree; var counter = 0; foreach (var body in bodies) { body.index = counter++; UpdateBodyCache(body); } tree.AddRange(bodies); }