Advertisement Jump to content
Sign in to follow this  


This topic is 3860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i have a problem. I have to draw a sphere using parametric coords. Since i was having some problem, i started to draw just the circle on the plane z-x (the big one).
This is my program (pretty simple):

static int r=1;

void init(void) 
	glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_FLAT);

void display(void)
	glColor3f(1.0, 1.0, 1.0);
	GLint teta=90.0;
	for (int phi=0; phi <= 360; phi=phi+90)
		glVertex3f(r*sin(phi)*sin(teta), r*cos(teta), r*cos(phi)*sin(teta));



void reshape (int w, int h)
   glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
	   /* if (w <= h)
       glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
       glOrtho (-1.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);*/
	gluLookAt(0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
   //glTranslatef (0.0, 0.0, -3.0);

int main(int argc, char** argv)
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize (500, 500); 
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   init ();
   return 0;
teta is 90 since the circle will be in the plane x-z and phi moves from 0 to 360. The problem is that my circle doesn't stay in the plane x-z. Looking from the positive z-axe into the center is should see just a line. I saw that the problem are the cos and the sin functions. For example if i put the y coord to zero without using r*cos(teta) (wich should be zero) it works!!?!!?! Even cosphi and sinphi don't work correctly. Teta and phi need to be of a particual kind? Give an hand guys, thanks in advance :D have a nice day bro

Share this post

Link to post
Share on other sites
Original post by Split Thumbs
It is in radians.. Also, just a sub-point you are declaring teta as a GLint then assigning it a double, kind of misleading.

hey thanks for the replayand for the tip, when ill be back to home i will see. Thanks

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!