Euler rotation of direction vector

3drotationvector

I have defined an object in 3D space with position, rotation and scale values (all defined as 3D vectors). It also has upwards and forwards direction vectors. When I rotate the object, I need these direction vectors to rotate with it.

Assuming my up vector is (0, 1, 0) and my forwards vector is (0, 0, 1) at zero rotation, how might I achieve this?

Best Answer

You can multiply the current vector with the rotation matrix (Wikipedia entry, under 'basic rotations'). If the rotation is in 2 or more axis, just multiply by the appropriate matrices. For example, if you rotate by 30 degrees in the X axis and 60 in the Y axis, multiply by

|    1         0          0     |
|    0    cos(pi/6)  -sin(pi/6) |
|    0    sin(pi/6)   cos(pi/6) |

and then by

| cos(pi/3)    0      sin(pi/3) |
|    0         1          0     |
| -sin(pi/3)   0      cos(pi/3) |