funky quadric coordinates

Started by
7 comments, last by Jean-Luc Pikachu 22 years, 3 months ago
Let''s say I had a quadric and a line I drew it like this:
  
glColor3f(1.0, 1.0, 1.0);
glBegin (GL_LINES);
  glVertex3f (x, y, z);
  glVertex3f (0.0, 0.0, 0.0);
glEnd();
glColor3f (1.0, 0.0, 0.0);
glTranslatef (x, y, z);
gluSphere (sphere, 1.0, 12, 12);
  
Theoretically, the sphere should be drawn to the end of the line that isn''t at the origin, right? But when I actually try this code the sphere ends up in lala land flying around the screen. What am I doing wrong? Major thanks in advance -- Peace, Capt. Jean-Luc Pikachu
--Peace,Capt. Jean-Luc Pikachu
Advertisement
I think the last two lines should be like this:
...
glPushMatrix();
glTranslatef(...);
glutSphere(...);
glPopMatrix();
...
Maybe you can try it.
quote:Original post by Lang Fox
I think the last two lines should be like this:
...
glPushMatrix();
glTranslatef(...);
glutSphere(...);
glPopMatrix();
...
Maybe you can try it.


that may be just useful if you wanna draw something after this code, but the sphere itself shouldn''t be affected .... dunno why this doesn''t work, but i dunno glut well, so that may be the point for me

@$3.1415rin
Thanks for trying to reply. I tried AuxSphere, gluSphere, and glutSphere, but no go on any of them =( Saving the matrix before & restoring after doesn''t change anything.

--
Peace,
Capt. Jean-Luc Pikachu
--Peace,Capt. Jean-Luc Pikachu
Have you used glLoadIdentity()?
Finally got it!

  glColor3f(1.0, 1.0, 1.0);glBegin (GL_LINES);  glVertex3f (x, y, z);  glVertex3f (0.0, 0.0, 0.0);glEnd();glMatrixMode (GL_PROJECTION);glPushMatrix();  glLoadIdentity();  glOrtho (-150, 150, -50, 50, -50, 350);  glMatrixMode (GL_MODELVIEW);  glPushMatrix();    glLoadIdentity();    gluLookAt (70, 20, -70, 0, 0, 0, 0, 1, 0);    glColor3f (1.0, 0.0, 0.0);    glTranslatef (x, y, z);    gluSphere (sphere, 1.0, 12, 12);    glMatrixMode (GL_MODELVIEW);  glPopMatrix();  glMatrixMode (GL_PROJECTION);glPopMatrix();  


The glOrtho & gluLookAt calls are for the viewing volume that I normally use. I mean, it works like this, but it''s strange that I have to reload my viewing preferences... I guess they''re getting messed up somewhere, but calls to glBegin/glEnd don''t seem to mind. Weird.

Thanks for the help =)

--
Peace,
Capt. Jean-Luc Pikachu
--Peace,Capt. Jean-Luc Pikachu
quote:Original post by Jean-Luc Pikachu
The glOrtho & gluLookAt calls are for the viewing volume that I normally use. I mean, it works like this, but it''s strange that I have to reload my viewing preferences... I guess they''re getting messed up somewhere, but calls to glBegin/glEnd don''t seem to mind. Weird.


Look around in your code and check to see if you surpassing the available stack depth with the push and pops in the GL_PROJECTION stack? I believe the OpenGL Spec for the projection stack only calls for a depth of 2 ( your results may vary )
You only have to call your projection calls once.

Your problem originally was that you were translating every time a new frame was swapped. You need a call to glLoadIdentity(); to stop that. Try something like this:

  int PreRender(){glMatrixMode (GL_PROJECTION);glLoadIdentity();glOrtho (-150, 150, -50, 50, -50, 350);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt (70, 20, -70, 0, 0, 0, 0, 1, 0);}int RenderScene(){glPushMatrix();glColor3f(1.0f, 1.0f, 1.0f);glBegin (GL_LINES);  glVertex3f (float(x), float(y), float(z));  glVertex3f (0.0f, 0.0f, 0.0f);glEnd();glPopMatrix();glPushMatrix();glColor3f (1.0f, 0.0f, 0.0f);glLoadIdentity();glTranslatef (float(x), float(y), float(z));gluSphere (sphere, 1.0, 12, 12);glPopMatrix();}  


This should be sufficient enough to produce the results that you originally intended.

~Dwarf
----------[Development Journal]
Actually you''re both semi right. Seems one of the routines I wrote that I was calling before time left the matrix mode as GL_PROJECTION. Once I fixed that, I just had to take your advice on loading identity and POW, everything worked.

I''m a dumbass, thanks for sticking with me!

--
Peace,
Capt. Jean-Luc Pikachu
--Peace,Capt. Jean-Luc Pikachu

This topic is closed to new replies.

Advertisement