tunabrain / tungsten

High performance physically based renderer in C++11

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rotation matrix formula inconsistency?

MKimiSH opened this issue · comments

Hi,

I am trying to understand how rotation works in Tungsten. I notice that there are 2 rotation functions in Mat4f, namely rotXYZ() and rotYXZ(). I did not find documentation for the formula so I tried to compose 3 rotation matrices (w.r.t. x, y, and z axes) to reconstruct these 2 functions. However, I found some inconsistency between these 2 functions.

For a certain rotation vector [x_angle, y_angle, z_angle], Assume the rotation matrices are named rot_x(x_angle), rot_y(y_angle) and rot_z(z_angle). Also assume that rot_*.dot(v) is the correct way to rotate a vector v (same convention as in Tungsten). The rotXYZ() function can be reconstructed as rot_z.dot(rot_y).dot(rot_x). However, the rotYXZ() function cannot be reconstructed as rot_z.dot(rot_x).dot(rot_y), as expected, but can be reconstructed by rot_y.transpose().dot(rot_x).dot(rot_z).

Could anyone explain the reason of having 2 different rotation functions that are formulated inconsistently?

Thanks in advance.

Maybe rotYXZ() just want to do rot_y(-y_angle) * rot_x(x_angle) * rot_z(z_angle).

But I don't know why this function is called rotYXZ()...

I know it actually does rot_y(-y_angle) * rot_x(x_angle) * rot_z(z_angle), and it is the method called when reading the scene config files (see src/core/io/JsonPtr.cpp). Probably @tunabrain could give a reason of this design?