# Camera rotation from vector

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

glRotatef(xrot,1.0,0.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glRotatef(zrot,0.0,0.0,1.0);

My
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
vector?

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.

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.

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?

[QUOTE=shawn619;1240902]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?[/QUOTE] A while ago I posted a demo that shows how to draw a tube from point A to point B. Part of the demo is orienting the tube along the vector B-A. Two angles are computed which are what you need. See the lines of code with atan2 and asin in them.