Hey,
does anyone know or maybe have a formula for drawing sphere?Like, I need quads vertices. Other stuff I bet I can work out.
I tried getting vertices data from sphere using blender, but I cant figure it out how.
// Input arguments
// in - VERTEX center : defines the center of the sphere, all points will be offset from this
// in - double r : defines the radius of the sphere
// out - vector<VERTEX> & spherePoints : vector containing the points of the sphere
void make_Sphere(VERTEX center, double r, std::vector<VERTEX> &spherePoints)
{
constdouble PI = 3.141592653589793238462643383279502884197;
spherePoints.clear();
// Iterate through phi, theta then convert r,theta,phi to XYZ
for (double phi = 0.; phi < 2*PI; phi += PI/10.) // Azimuth [0, 2PI]
{
for (double theta = 0.; theta < PI; theta += PI/10.) // Elevation [0, PI]
{
VERTEX point;
point.x = r * cos(phi) * sin(theta) + center.x;
point.y = r * sin(phi) * sin(theta) + center.y;
point.z = r * cos(theta) + center.z;
spherePoints.push_back(point);
}
}
return;
}
Here I linearly just go through all of angles for phi and theta. You'll find that points at the top and bottom will be super concentrated so there is certainly room to make the iterators more efficient to avoid this.