I wanted to create a function that would draw me a sphere. When I wrote the code, the system failed to show anything.
This code has an error somewhere:
#define TAU 6.2832
//function to create a sphere
void spherel(double r, double x=0, double y=0, double z=0)
{
short i=30,j=15;
double theta = 0, tau = TAU/30, phi=0;
double a[30][30][3];
//this loop creates an array to save all the points
while(i)
{
j=15;
theta = 0;
while(j)
{
a[i][j][0]=r*cos(theta)*cos(phi);
a[i][j][1]=r*sin(theta);
a[i][j][2]=r*cos(theta)*sin(phi);
a[29-i][29-j][0]=a[i][j][0];
a[29-i][29-j][1]=-a[i][j][1];
a[29-i][29-j][2]=a[i][j][2];
theta += tau;
j--;
}
phi += tau;
i--;
}
//drawing
glBegin(GL_TRIANGLES);
i=30;
while(i)
{
j=30;
while(j)
{
//all the vertex to make a rectangle
glVertex3d(x+a[i][j][0],y+a[i][j][1],z+a[i][j][2]);
glVertex3d(x+a[i][j+1][0],y+a[i][j+1][1],z+a[i][j+1][2]);
glVertex3d(x+a[i+1][j][0],y+a[i+1][j][1],z+a[i+1][j][2]);
glVertex3d(x+a[i+1][j+1][0],y+a[i+1][j+1][1],z+a[i+1][j+1][2]);
glVertex3d(x+a[i][j+1][0],y+a[i][j+1][1],z+a[i][j+1][2]);
glVertex3d(x+a[i+1][j][0],y+a[i+1][j][1],z+a[i+1][j][2]);
j--;
}
i--;
}
glEnd();
}