Euler Direction Vector Rotation

I defined an object in three-dimensional space with position, rotary and scale values ​​(they are all defined as 3D vectors). It also has up and forward direction vectors. When I rotate an object, I need these direction vectors to rotate with it.

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

+4
source share
2 answers

You can multiply the current vector by the rotation matrix ( Wikipedia entry under "main rotations"). If the rotation is on 2 or more axes, just multiply the corresponding matrices. For example, if you rotate 30 degrees on the X axis and 60 on the Y axis, multiply by

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

and then

 | cos(pi/3) 0 sin(pi/3) | | 0 1 0 | | -sin(pi/3) 0 cos(pi/3) | 
+4
source

Just rotate each of these vectors at the same angle your object rotates. Let's say you rotate around the z axis (i.e. (0, 0, 1))

The equations will be:

 x' = x cos(angle) + y sin(angle) y' = -x sin(angle) + y cos(angle) z' = z 

Your up vector is (0, 1, 0), thus;

 x' = 0 * cos(angle) + 1 * sin(angle) = sin(angle) y' = -0 * sin(angle) + 1 * cos(angle) = cos(angle) z' = 0 

Forward vector (0, 0, 1), like this:

 x' = 0 y' = 0 z' = 1 

It will not rotate, since we rotated around the z axis, which is the parellel for your vector forward

+1
source

Source: https://habr.com/ru/post/1311315/


All Articles