View Full Version : Camera rotation from vector

07-30-2012, 02:53 AM
To start off, i am NOT talking about gluLookAt() to specify the camera rotation,
so dont suggest i use it. I'm using glRotatef to alter
camera rotation.

So far i'v been using angle xrot,yrot,zrot (in degrees)
to specify the camera rotation.


problem, say i have a unit vector (0.3433, 0.4243, 0.242) and i want to find the
appropriate xrot,yrot,zrot to get the camera rotation according the given

I was thinking to solve, say the xrot, i could take do
->angleBetween( (0.3433,0,0), (1,0,0) ) would give the xrot, and so on for
the yrot,zrot.

Alfonse Reinheart
07-30-2012, 03:51 AM
So let me make sure I understand this correctly. You ditched gluLookAt for specifying your camera in favor of Euler angles. And now you want to use Euler angles to basically do the exact same thing that gluLookAt could do far easier.

Why are you making everything so difficult for yourself? Use the right tool for the right job. And Euler angles are almost never the right job for anything.

Basically, the best way to answer your question is to look at the implementation of gluLookAt and do what it does (http://www.opengl.org/sdk/docs/man/xhtml/gluLookAt.xml).

07-30-2012, 05:26 AM
But bare with me here,

Given an up-vector of always (0,1,0) and a nonzero direction vector (x,y,z), how do i get the rotation angles for the camera to point in the direction of the given vector?