Public Group

Untitled

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

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);
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);
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);
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 on other sites
It is in radians.. Also, just a sub-point you are declaring teta as a GLint then assigning it a double, kind of misleading.

Share on other sites
Quote:
 Original post by Split ThumbsIt 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

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 17
• 14
• 10
• 9
• 11
• Forum Statistics

• Total Topics
634094
• Total Posts
3015500
×