Jump to content
  • Advertisement
Sign in to follow this  
broady

Untitled

This topic is 3768 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);
	glEnable(GL_DEPTH_TEST);
}

void display(void)
{
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //glPushMatrix();
	glColor3f(1.0, 1.0, 1.0);
	
	GLint teta=90.0;
	
	glBegin(GL_LINE_LOOP);
	
	for (int phi=0; phi <= 360; phi=phi+90)
			
		glVertex3f(r*sin(phi)*sin(teta), r*cos(teta), r*cos(phi)*sin(teta));

	glEnd();
	


    //glPopMatrix();
    glFlush();
}

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);
    else
       glOrtho (-1.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);*/
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
	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 ();
   glutDisplayFunc(display); 
   glutReshapeFunc(reshape);
   glutMainLoop();
   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
Advertisement
Quote:
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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!