开发者

Adding Local Rotation to Global Rotation

开发者 https://www.devze.com 2023-03-10 12:32 出处:网络
I\'ve tried many formulas and conversions, but nothing gave me the result I expect. The scenario is very simple:

I've tried many formulas and conversions, but nothing gave me the result I expect.

The scenario is very simple:

How the 3DS Max and other 3D softwares make the "transformation" of an increment in local rotation to the global absolute rotation?

An example can help you to understand: 3DS Max - Maya - Modo (all three gave me the same resu开发者_JS百科lt, so I'm inclined to believe that this result is correct.) Assuming Absolute rotation order as XYZ.

1. World Rotation Y = 35.0;
2. Local Rotation X = 35.0;

After these transformations, in that order, I look at the World Absolute rotation and what I see is X:40.524 Y:-28.024 Z:-21.881

How they achieve that result? What kind of formula? Using matrix, Euler angles or quaternions, whatever, how can I get the same result?

Thank you.

PS: A simple solution could be use of a quaternion or a matrix, add the local rotation into the global and then retrieve the absolute result. But this doesn't work well, because at this way we don't have control over the rotation order, the result always come using the order of the formula to retrieve the values.


You want to multiply the rotation matrices in order dependent on the order in which the rotations are applied, if the local rotation is to be applied first (which I suspect it is) then:

WorldMat * LocalMat [* column vector]

(provided you are pre-multiplying column vectors to apply your transformations, just take the transpose of the whole expression if you're doing it the other way round)

Similarly, if you are working with quaternions you should be multiplying your quaternions (not adding them).


The rotation matrices look like this (assuming column vector representation):

[   1      0       0   ]
[   0    cos(a)  sin(a)] = Rx(a)
[   0   -sin(a)  cos(a)] 

[ cos(a)   0    -sin(a)]
[   0      1       0   ] = Ry(a)
[ sin(a)   0     cos(a)]

[ cos(a) sin(a)   0    ]
[-sin(a) cos(a)   0    ] = Rz(a)
[   0      0      1    ]

Multiplying 'local' means that the matrix goes on the right. Multiplying 'global' means the matrix goes on the left. So your rotation is Ry(35°)*Rx(35°). Or approximately:

[ .819  .329 -.469 ]
[  0    .019  .574 ]
[ .574 -.470  .671 ]

The Euler rotation order XYZ means Rx(ax)*Ry(ay)*Rz(az). So, if you plug in the numbers Rx(40.524°)*Ry(-28.024°)*Rz(-21.881), you get approximately (within round-off error) the same matrix (I did try it, just to make sure).

0

精彩评论

暂无评论...
验证码 换一张
取 消