I want to draw a sphere using VBO for vertex coordinates, colors and UV for texture. My problem is that the sphere is not "closed", there is a hole at the origin. I know this is because my code depends on (1 / segments) the distance between each vertex; I work with segments = 40. I know that if I raise this value, the hole will be lower, but the program will be slower. I do not know if there is a way to eliminate the hole without raising the variable.
Here is the code:
for(int i = 0; i <= segments; i++){
double lat0 = pi * (-0.5 + (double)(i - 1) / segments);
double z0 = sin(lat0);
double zr0 = cos(lat0);
double lat1 = pi * (-0.5 + (double)i / segments);
double z1 = sin(lat1);
double zr1 = cos(lat1);
for (int j = 0; j <= segments; j++){
double lng = 2 * pi * (double)(j - 1) / segments;
double x = cos(lng);
double y = sin(lng);
ballVerts.push_back(x * zr0);
ballVerts.push_back(y * zr0);
ballVerts.push_back(z0);
ballVerts.push_back(0.0f);
ballVerts.push_back(0.0f);
ballVerts.push_back(0.0f);
ballVerts.push_back(1.0f);
texX = abs(1 - (0.5f + atan2(z0, x * zr0) / (2.0 * pi)));
texY = 0.5f - asin(y * zr0) / pi;
ballVerts.push_back(texX);
ballVerts.push_back(texY);
ballVerts.push_back(x * zr1);
ballVerts.push_back(y * zr1);
ballVerts.push_back(z1);
ballVerts.push_back(0.0f);
ballVerts.push_back(0.0f);
ballVerts.push_back(1.0f);
ballVerts.push_back(1.0f);
texX = abs(1 - (0.5f + atan2(z1, x * zr1) / (2.0 * pi)));
texY = 0.5f - asin(y * zr1) / pi;
ballVerts.push_back(texX);
ballVerts.push_back(texY);
}
}
And this is the result that I have:

source
share