# Rotate a direction vector with quaternions

Hi. I want to rotate the direction vector of the camera using the quaternions provided by the Camera Comp.

Assuming the initial vector to be [0, 0, -1] since the camera is pointing in the negative z axe, I apply the quaternion [0.9998, 0.0198, 0, 0] that comes from a 90° rotation on the X axe.

If I rotate the vector I get [0., 0.03959208, -0.999208] which is not what I was expecting, since the camera is now pointing in the positive Y axe.

What is going on?

Hi there,

I think it’s better to work in euler angles inside TouchDesigner since you would need to convert them eventually anyways (unless you write your own GLSL material to handle those)

How did you calculate the quaternion? The one you describe looks like hardly any rotation (if the first value represents the real part of the quaternion). Your output vector is almost the same as 0,0,-1… just slightly rotated over the x-axis. I think a 90 degrees rotation on the x-axis would be (sqrt(2)/2, 0, 0, sqrt(2)/2)… (or in decimals: (0.7071, 0, 0, 0.7071)

Last, if you rotate your camera 90 degrees over the x-axis, you would point over y-axis (either up or down depending on the rotation). What were you expecting? (might be that you’re used to a different system where the x,y,z axis are swapped)

Hope this helps!
cheers,
tim

I talk about working with Euler angles in this post:

But I still have troubles there

please don’t duplicate your post. It seems like r-ssek gave you a working tox example. Also perhaps good to research about rotation matrices and how they work. It can get quite tricky with the order and stuff.

I am using the rotation matrix to rotate my vector, only the behavior is quite different when rotating on multiple axes. In the r-ssek example is not quite clear for me how to use those values