public ParticleLayer(MPos bounds) { this.bounds = new MPos((int)Math.Ceiling(bounds.X / (float)SectorSize), (int)Math.Ceiling(bounds.Y / (float)SectorSize)); sectors = new ParticleSector[this.bounds.X, this.bounds.Y]; for (var x = 0; x < this.bounds.X; x++) { for (var y = 0; y < this.bounds.Y; y++) { sectors[x, y] = new ParticleSector(new MPos(x, y)); } } }
ParticleSector[] getSectors(CPos topleft, CPos botright) { var pos1 = new MPos((int)Math.Clamp(Math.Floor(topleft.X / 4096f), 0, bounds.X - 1), (int)Math.Clamp(Math.Floor(topleft.Y / 4096f), 0, bounds.Y - 1)); var pos2 = new MPos((int)Math.Clamp(Math.Ceiling(botright.X / 4096f), 0, bounds.X - 1), (int)Math.Clamp(Math.Ceiling(botright.Y / 4096f), 0, bounds.Y - 1)); var sectors = new ParticleSector[(pos2.X - pos1.X + 1) * (pos2.Y - pos1.Y + 1)]; var i = 0; for (var x = pos1.X; x < pos2.X + 1; x++) { for (var y = pos1.Y; y < pos2.Y + 1; y++) { sectors[i++] = this.sectors[x, y]; } } return(sectors); }