Jump to content
  • Advertisement


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


How to use GluLookAt () ?

This topic is 6105 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

Good day ! I am still new in OpenGL programming. I try to use GluLookAt() to manipulate the view of my scene. Weird enough, I get no effect at all after I add the code inside the Display() function. I wonder what''s wrong with it ? Where should I implement GluLookAt actually ? I mean in which function ? in Init() ? in Display() ? Thanks a lot !

Share this post

Link to post
Share on other sites
gluLookAt(..) takes nine parameters.

the first three are the "camera's" x, y, and z coordinates, the next three are the coordinates that its looking at, and the next three are statically 0,1,0.


gluLookAt(0.0, 0.0, 0.0, 5.0, 5.0, 5.0, 0, 1, 0);

the above line would position the camera at 0,0,0 and you'd be looking at 5,5,5...

If you want everything to be upside down, have the last three be 0,-1,0... The are the camera tilt coords.

Anyway, have fun, and remember that its only the first six that you really want.

BTW, you would use this function somewhere before you draw your code, probably after you stacked a matrix, but I would place it in my rendering function.


Edited by - Zeus_ on October 31, 2001 9:10:59 AM

Share this post

Link to post
Share on other sites
void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz);

eyex, eyey, eyez
The position of the eye point.
centerx, centery, centerz
The position of the reference point.
upx, upy, upz
The direction of the up vector.

The gluLookAt function creates a viewing matrix derived from an eye point, a reference point indicating the center of the scene, and an up vector. The matrix maps the reference point to the negative z-axis and the eye point to the origin, so that when you use a typical projection matrix, the center of the scene maps to the center of the viewport. Similarly, the direction described by the up vector projected onto the viewing plane is mapped to the positive y-axis so that it points upward in the viewport. The up vector must not be parallel to the line of sight from the eye to the reference point.

The matrix generated by gluLookAt postmultiplies the current matrix.

Share this post

Link to post
Share on other sites
one reason it may not have worked is if you put it in your projection matrix.

DO NOT DO THIS. (can''t emphasise it enough - most common mimstake I made when starting out)

You''ll usually want no other transforms in GL_PROJECTION other than glLoadIdentity and gluOrtho2D/gluPerspective.

gluLookAt should most likely be third in rendering function after glClear and glLoadIdentity.

I disagree that you''ll find it after a glPush - that''d be a rare situation. You usually glPush right after setting up the camera position with gluLookAt so you can translate and draw and get back to where you once belonged with glPopMatrix

Brett Porter
PortaLib3D : A portable 3D game/demo libary for OpenGL
Community Service Announcement: Read How to ask questions the smart way before posting!

Share this post

Link to post
Share on other sites
Good day again !

Basically , I found that the matrix stuff in OpenGL really consuging.

I still not sure what''s wrong with my codes.

Below is the code I wish to have the gluLookAt() to implement with.


glTranslatef (-0.8, 0.0, 0.0);
glRotatef ((GLfloat) f1_joint1, 0.0, 0.0, 1.0);
glTranslatef (0.7, 0.0, 0.0);
glutWireCube (1.0);

Where should I implement the gluLookAt() so that I can have camera effects to rotate around in the scene ?

Thanks a lot !


Share this post

Link to post
Share on other sites

  • 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!