I came across spherical coordinates and had attempted to create a beginning sphere on my own, and with some help in the end.
I have converted the degrees to radians and plugged them into glVertex3f, but get a what looks like, pie slice.
I understand the naming convention is bad (degrees should be radians) please bear with me, but if requested a rename for better help, i will do so.
//GLRendering.h
void SetUp_OpenGL() {
glViewport(0, 0, 1024, 768);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, 1024.0f / 768.0f, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
}
void RenderProgramScene() { // Where problem to be more then likely located
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glTranslatef(0.0f, 0.0f, -4.0f);
//glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
//glDisable (GL_CULL_FACE);
glBegin(GL_LINE_LOOP);
degrees_per_plot_YZ = 0.0f;
degrees_per_plot_YZ = (two *= 3.14) /= dots_per_axis_YZ;
two = 2.0f;
current_degrees_Z = 0.0f;
for (zcounter = 0.0f; zcounter < dots_per_axis_YZ; zcounter++) { //Begin drawing of Z axis, within the for loop
if (firstrun_Z == 1) { //if running the first time, set to 0, and do not add anything to the current degrees
firstrun_Z = 0;
} else { //other wise
current_degrees_Z += degrees_per_plot_YZ; //(virtually) rotate axis of drawing y axis by adding degrees per plot, to current degress to get angle to next plot
firstrun_Y = 1; //in this part, we assume the circle from the last loop has run once, and we can set it again
current_degrees_Y = 0.0f; //reset degrees
}
for(ycounter = 0.0f; ycounter < dots_per_axis_YZ; ycounter++) { //draw loop for y axis
if (firstrun_Y == 1) { //if first run, set all to zero, and print
firstrun_Y = 0; //then set to 0 because we have run this once already.
//glvertex prints using the spherical to cartesian convertion. The book says y is r * sin(angle z) cos (angle z) then the degree to radian convertion. was corrected from help to be sin sin, and not sin cos
glVertex3f((radian*cos(current_degrees_Y*((3.14f) / 180.0f))*sin(current_degrees_Z*((3.14f) / 180.0f))),(radian*sin(current_degrees_Y*((3.14f) / 180.0f))*sin(current_degrees_Z*((3.14f) / 180.0f))),(radian*cos(current_degrees_Z*((3.14f) / 180.0f))));
} else {
current_degrees_Y += degrees_per_plot_YZ; //ran the second time, add degrees to next plot
glVertex3f((radian*cos(current_degrees_Y*((3.14f) / 180.0f))*sin(current_degrees_Z*((3.14f) / 180.0f))),(radian*sin(current_degrees_Y*((3.14f) / 180.0f))*sin(current_degrees_Z*((3.14f) / 180.0f))),(radian*cos(current_degrees_Z*((3.14f) / 180.0f))));
}
}
}
//object is done be drawn, now draw it to screen
glEnd();
SwapBuffers(hDC);
//the number you see at the top right of the screen
sprintf(titlebuf, "%i", frame++);
wintitle = (LPCSTR)titlebuf;
SetWindowText(hwnd, wintitle);
}
void End_OpenGL() {
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
}
The image of the sphere at the moment with the code above compiled:
http://i55.tinypic.com/35c24ad.png
To the top right is the frames drawn since execution. Can anyone please tell me what my problem may be?
Edit: i hope this is better, if still a little difficult or messy, please let me know and i will fix it