public static Tuple <List <Voxel>, List <Voxel> > SelectVoxels(Saves save, Vector3 center, float radius, float ymin, float ymax) { List <Voxel> selectedvoxels = new List <Voxel>(); List <Voxel> floorvoxels = new List <Voxel>(); List <Asteroid> chunks = save.GetChunks(); List <Asteroid> filteredchunks = new List <Asteroid>(); foreach (Asteroid chunk in chunks) { Vector3 pos = chunk.Position; if ((pos.WithinX(center.x - radius - ChunkSize, center.x + radius + ChunkSize)) && (pos.WithinZ(center.z - radius - ChunkSize, center.z + radius + ChunkSize))) { filteredchunks.Add(chunk); } } Dictionary <Voxel, Vector3> preselected = PreselectVoxels(filteredchunks); foreach (var item in preselected) { Voxel vox = item.Key; Vector3 voxpos = item.Value; if (voxpos.GetDistanceTo(center) <= radius && voxpos.y >= ymin && voxpos.y <= ymax) { selectedvoxels.Add(vox); } else if (voxpos.GetDistanceTo(center) <= radius && voxpos.y == ymin - 1) { floorvoxels.Add(vox); } Console.SetCursorPosition(0, 2); Console.Write("Found: {0} Voxels", selectedvoxels.Count); } return(Tuple.Create(selectedvoxels, floorvoxels)); }
public static Tuple <List <Voxel>, List <Voxel> > SelectVoxels(Saves save, Vector3 min, Vector3 max) { List <Voxel> selectedvoxels = new List <Voxel>(); List <Voxel> floorvoxels = new List <Voxel>(); List <Asteroid> chunks = save.GetChunks(); List <Asteroid> filteredchunks = new List <Asteroid>(); foreach (Asteroid chunk in chunks) { Vector3 pos = chunk.Position; if ((pos.WithinX(min.x - 10, max.x + 10)) && (pos.WithinZ(min.z - 10, max.z + 10))) { filteredchunks.Add(chunk); } } Dictionary <Voxel, Vector3> preselected = PreselectVoxels(filteredchunks); foreach (var item in preselected) { Voxel vox = item.Key; Vector3 voxpos = item.Value; if (voxpos.WithinX(min.x, max.x) && voxpos.WithinY(min.y, max.y) && voxpos.WithinZ(min.z, max.z)) { selectedvoxels.Add(vox); } else if (voxpos.WithinX(min.x, max.x) && voxpos.y == min.y - 1 && voxpos.WithinZ(min.z, max.z)) { floorvoxels.Add(vox); } Console.SetCursorPosition(0, 2); Console.Write("Found: {0} Voxels", selectedvoxels.Count); } return(Tuple.Create(selectedvoxels, floorvoxels)); }