Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gluLookAt explanation?

Tags:

opengl

Trying to understand gluLookAt, especially the last 3 parameters.

Can someone please explain ?

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.

like image 311
Johnnt Jazz Avatar asked Apr 19 '11 14:04

Johnnt Jazz


4 Answers

Sketchup to the rescue!

GluLookAt params

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).

like image 135
JCooper Avatar answered Nov 19 '22 04:11

JCooper


first 3 parameters are camera position next 3 parameters are target position the last 3 parameters represent the rolling of camera.

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.

like image 34
Fennekin Avatar answered Nov 19 '22 02:11

Fennekin


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 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.

like image 5
User 12692182 Avatar answered Nov 19 '22 02:11

User 12692182


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.

by changing it from (0,1,0) you can do sideways rolling.

like image 2
clamp Avatar answered Nov 19 '22 03:11

clamp