• Advertisement

Archived

This topic is now archived and is closed to further replies.

Question about gluLookAt

This topic is 5860 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! As I animate the "camera" the drawn objects flicker. How''s that? It looks fine if the "camera" is static and I move the object (a simple colored triangle). "A witty and slightly sarcastic quote from an unkown source" -- The generic SIG /trysil

Share this post


Link to post
Share on other sites
Advertisement
I don''t know what exactly do you mean but you have to set the camera position olny at the begining of the rendered frame. S soon as you clear the frame buffer and LoadIdentity();
Be sure that you''ve initialized gluPerspective correctly and if you are using textures use
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
And the frame render would be now with no problems...
.
.
.
void Render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);Clear The glLoadIdentity();
gluLookAt(pPos.x, pPos.y,pPos.z,pLookAt.x,pLookAt.y,pLookAt.z,
pUp.x,pUp.y,pUp.z);

...
nov render the polygons
...

glFinish();
SwapBuffers(hDC);
}
.
.
.

That should work right...it''s a sample of my code that is working with no problems...

Share this post


Link to post
Share on other sites
This can be caused by setting your near Z clipping plane to zero. It should always be greater than zero. It may not be your problem, but I would check if I were you to make sure. This is a bug that frequently catches the unweary.

Share this post


Link to post
Share on other sites
I do all that
Maybe I do it in the wrong order?

I have a Camera class containing an operation MoveDelta:
  
position.posX += x;
position.posY += y;
position.posZ += z;

teVector3D v(lookAt.vectorX+x,lookAt.vectorY+y,lookAt.vectorZ+z);

lookAt = v;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluLookAt(position.posX, position.posY, position.posZ,
lookAt.vectorX, lookAt.vectorY, lookAt.vectorZ,
upDir.vectorX, upDir.vectorY, upDir.vectorZ);


this I use to update the camera position.
I''m testing this using a simple drawing routine:

  
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef(0.0f,0.0f,-6.0f);

glBegin(GL_TRIANGLES);


glColor3f(1.0,0,0);
glVertex3f(-2.0,-1.0,0.0);
glColor3f(0,1.0,0);
glVertex3f(3.0,1.0,0.0);
glColor3f(0,0,1.0);
glVertex3f(0.0,3.0,0.0);
glEnd();
SwapBuffers(TheWindow.hDC);


As I press the up/down arrows I call the moveDelta operation with a delta for the z.

Something wrong with this code?







"A witty and slightly sarcastic quote from an unkown source"
-- The generic SIG

/trysil

Share this post


Link to post
Share on other sites
I''m willing to bet that your problem is due to calling gluLookAt on the projection matrix instead of the model view matrix. The only thing you should ever do to the projection matrix is call gluPerspective or gluOrtho2D. Everything else is done with the model view matrix.

Share this post


Link to post
Share on other sites

  • Advertisement