You are on page 1of 3

gluLookAt explanation?

Asked 12 years, 11 months ago Modified 3 years, 3 months ago Viewed 37k times

Trying to understand gluLookAt, especially the last 3 parameters.

Can someone please explain ?


40
gluLookAt(camera[0], camera[1], camera[2], /* look from camera XYZ */
0, 0, 0, /* look at the origin */
0, 1, 0); /* positive Y up vector */

1. What exactly does it mean by "positive Y up vector" ?

2. Is it possible to have the last up-vector 3 parameters as all 1s, e.g. 1, 1, 1 ? And, if it is possible,
what exactly does it mean ?

3. Is it possible for the up vector to have value more than 1, e.g. 2, 3, 4 ?

Thanks.

opengl

Share Improve this question Follow edited Oct 14, 2016 at 7:27 asked Apr 19, 2011 at 14:07
D A Vincent Johnnt Jazz
364 3 22 401 1 4 3

4 Answers Sorted by: Highest score (default)

Sketchup to the rescue!

74

Your image has an 'up' to it that can be separate from the world's up. The blue window in this image can
be thought of as the 'near-plane' that your imagery is drawn on: your monitor, if you will. If all you supply
is the eye-point and the at-point, that window is free to spin around. You need to give an extra 'up'
direction to pin it down. OpenGL will normalize the vector that you supply if it isn't unit length. OpenGL
will also project it down so that it forms a 90 degree angle with the 'z' vector defined by eye and at
(unless you give an 'up' vector that is in exactly the same direction as the line from 'eye' to 'at'). Once 'in'
(z) and 'up' (y) directions are defined, it's easy to calculate the 'right' or (x) direction from those two.

In this figure, the 'supplied' up vector is (0,1,0) if the blue axis is in the y direction. If you were to give
(1,1,1), it would most likely rotate the image by 45 degrees because that's saying that the top of the blue
window should be pointed toward that direction. Consequently the image of the guy would appear to be
tipped (in the opposite direction).

Share Improve this answer Follow edited Apr 19, 2011 at 19:00 answered Apr 19, 2011 at 18:44
JCooper
6,445 1 26 31

your provided image doesn't show up!maybe the link has expired – Sihat Afnan May 29, 2022 at 3:00

The "up vector" of gluLookAt is just the way the camera is oriented. If you have a camera at a position,
looking directly at an object, there is one source of freedom still remaining: rotation. Imagine a camera
8 pointed directly at an object, fixed in place. But, your camera can still rotate, spinning your image. The
way OpenGL locks this rotation in place is with the "up vector."

Imagine (0, 0, 0) is directly at your camera. Now, the "up vector" is merely a coordinate around your
camera. Once you have the "up vector," though, OpenGL will spin your camera around until directly the
top of your camera is facing the coordinate of the "up vector".

If the "up vector" is at (0, 1, 0), then your camera will point normally, as the up vector is directly above
the camera, so the top of the camera will be at the top, so your camera is oriented correctly. Move the
up vector to (1, 1, 0), though, and in order to point the top of the camera to the "up vector," your camera
will need to rotate be 45 degrees, rotating the entire image by 45 degrees.

This answer was not meant as an in-depth tutorial, but rather as a way to grasp the concept of the "up
vector," to help better understand the other excellent answers to your question.

Share Improve this answer Follow answered Jan 7, 2021 at 20:52


User 12692182
973 6 17

first 3 parameters are camera position next 3 parameters are target position the last 3 parameters
represent the rolling of camera.
6
Very important thing use gluLookAt after "glMatrixMode(GL_MODELVIEW);"

Other useful hint always specify it 0,0,1 for last 3 parameters. In general co-ordinates are written as
x,y,z. z is up vector. the 0,1,0 leads in confusion as x,z,y.

so best thing leave it to 0,0,1.

Share Improve this answer Follow answered Nov 28, 2013 at 15:55
Fennekin
216 3 12
If you are still unable to understand than you can always try experiment with the vector. – Fennekin Oct 15, 2014 at
3:28

the last vector, also known as the cameras up-vector defines the orientation of the camera.

imagine a stick attached to the top of a "real" camera. the stick's direction is the up-vector.
2
by changing it from (0,1,0) you can do sideways rolling.

Share Improve this answer Follow answered Apr 19, 2011 at 14:09
clamp
33.5k 75 206 301

Still don't quite understand. What is the diff between up-vector when the parameters are (1, 0, 0) vs (0, 1,0) vs (0,
0, 1) ? Can't find any picture in the web site to aid my understanding. If anybody know where to find, please let me
know. – Johnnt Jazz Apr 19, 2011 at 14:16

1 @Johnnt: Think about an observer at a particular spot on your floor, looking toward the door. Now, that observer
could be sitting, lying on their left side, or lying on their right side. You need to know the rotation of the observer's
head in addition to their position and the direction they're looking. – Ben Voigt Apr 19, 2011 at 14:36

3 Expanding on Ben's explanation, imagine your camera with an antenna on top. That's camera "up." As a hand-held
video camera, imagine that you ROTATE THE CAMERA while keeping it pointed at your subject! Now camera-up
can point in any direction, even upside down! That's what gluLookAt's up XYZ coordinates are for -- to tell GL which
way the camera is being held. In MOST situations, 0,1,0 works, although there are problems if the camera is
looking straight up or straight down, in which case 0,0,1 is a good starting point, though you may want to
experiment. – Olie May 30, 2011 at 14:45

You might also like