# Camera rotation in TouchDesigner

I need help on something I'm struggling with very much.

I am working on a TouchDesigner patch where I have a Camera COMP with rotation on x, y and z axes. I need the formulas to convert such rotations in a direction vector, that I am going to use in other programs to define the direction I am looking at. The point is having camera and for instance a microphone pointing in the same direction.

I have implemented the rotation matrix as explained in the "General 3D rotation" section of this Wikipedia article.

With this equations implemented I get the direction vector correctly but only when rotating on a single axe. But when I rotate on multiple axes it gets weird.

Example: the initial camera vector is {0,0,-1} with no rotation. So basically the camera is pointing in the negative-Z axes. With Y-rotate 45° the equation gives me {-0.707, 0, -0.707}, and it looks like the camera is actually pointing in that direction.

Now, if I add an X-rotate 90° the equation gives me {-0.707, -0.707, 0}, which is weird because the camera is now pointing in the negative Y, as if the vector was {0, -1, 0}.