OpenGL gluLookAt why the up vector instead of an angle

Tag: opengl , graphics , camera , glulookat Author: treaton Date: 2014-02-07

I understand that in OpenGL, we use the gluLookAt to place the camera relative to the world and thus define the image that would be drawn.

The "eye" specifies the position of the camera and the "center" specifies the point the camera is pointing towards. Once we know these two, we can draw a straight line from the eye to the center. The camera plane would be normal to this line.

Since we know this plane, the up vector specifies the top of the camera - basically which direction in this plane is upwards. Thus the up vector is always orthogonal to the vector joining the center and the eye.

My question is why do we need the full vector, when we just want to know the angle of rotation about the line joining "center" and "eye". Is the reason behind this a computational advantage that I am not aware of? And what if someone specifies a wrong up vector, which is not orthogonal to the direction of sight?

Best Answer

The up vector you pass in is used to indicate the up direction, but this is used with a cross product. I think the purpose of gluLookAt is to simplify the calculations needed by the user, so for example you would just pass (0,1,0) to indicate that the up direction you desire is along the positive Y-axis.

If you want better efficiency you could avoid gluLookAt entirely

comments:

I agree that it is used to simplify the calculations, but then it could just that 1 angle instead of requiring the entire vector. This question shows the cross product () which crosses the normal with the up vector, and then crosses it again with the normal. That seems redundant. I don't understand why?
The original up vector is not meant to be orthogonal to the view direction - it simply determines the general direction that is up, for example the y axis. If you cross the orthogonal up vector with the view, or the approximate up vector with the view, you'll get the same side vector. Since gluLookAt doesn't expect the orthogonal up vector it crosses the side vector with the view to get the orthogonal up vector. If you used an angle which axis would you be rotating against? The view direction? This would require you to adjust the angle based on the view direction