Skip to main content
GameDev.net gamedev.net
🔒 Locked

funky quadric coordinates

Started by Jean-Luc Pikachu Jan 3, 2002 at 1:42 AM 7 replies 1k views
Original Post
Jean-Luc Pikachu
Jean-Luc Pikachu
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
Lang Fox
Lang Fox
I think the last two lines should be like this:
...
glPushMatrix();
glTranslatef(...);
glutSphere(...);
glPopMatrix();
...
Maybe you can try it.
as31415rin
as31415rin
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
Jean-Luc Pikachu
Jean-Luc Pikachu
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
Shag
Shag
Have you used glLoadIdentity()?
Jean-Luc Pikachu
Jean-Luc Pikachu
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
Dwarf with Axe
Dwarf with Axe
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
Jean-Luc Pikachu
Jean-Luc Pikachu
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.