28 lines
828 B
C++
28 lines
828 B
C++
#pragma once
|
|
|
|
#include <glm/glm.hpp>
|
|
#include <vector>
|
|
|
|
/// Interger sphere fill
|
|
struct SphereIterator {
|
|
SphereIterator(const glm::ivec3 ¢er, int radius): center(center), radius(radius) { }
|
|
|
|
glm::ivec3 center;
|
|
int radius;
|
|
|
|
void vector(std::vector<glm::ivec3>& out) {
|
|
int top = center.y - radius, bottom = center.y + radius;
|
|
|
|
for (int y = top; y <= bottom; y++) {
|
|
int dy = y - center.y, dxz = floor(sqrt(radius * radius - dy * dy));
|
|
int minx = center.x - dxz, maxx = center.x + dxz;
|
|
int minz = center.z - dxz, maxz = center.z + dxz;
|
|
out.reserve(out.size() + dxz * dxz);
|
|
for (int z = minz; z <= maxz; z++) {
|
|
for (int x = minx; x <= maxx; x++) {
|
|
out.emplace_back(x, y, z);
|
|
}}
|
|
}
|
|
}
|
|
};
|