更新时间:2023-11-21 11:52:40
如果您的欧拉角表示绝对旋转,则可以计算旋转矩阵R
.如何执行此操作取决于Euler角的定义,应在文档中进行描述.可能是:
If your Euler angles represent an absolute rotation, you can calculate a rotation matrix R
. How you do this depends on the definition of the Euler angles, which should be described in the documentation. It might be:
R = rotateY(yaw) * rotateX(pitch) * rotateZ(roll)
同样,这只是一个例子.正确的公式取决于欧拉角的顺序及其解释.
Again, this is just an example. The correct formula depends on the order of Euler angles and their interpretation.
然后可以将相机的模型矩阵计算为:
The camera's model matrix can then be calculated as:
cam = translation(target) * R * translation(0, 0, radius)
(或对于左手坐标系为-radius
). translation()
计算转换矩阵.
(or -radius
for left-handed coordinate systems). translation()
calculates a translation matrix.
这背后的直觉是,将摄像机移至目标,然后根据R
旋转它,然后再将其移回radius
.
The intuition behind this is that you move your camera to the target, then rotate it according to R
, and then move it back by radius
.
如果具有此矩阵,则相机的向上矢量将是其第二列,眼睛矢量将是其第四列.如果只需要视图矩阵,请使用cam
的逆矩阵.
If you have this matrix, the camera's up-vector will be its second column, the eye-vector will be its fourth column. If you just need a view-matrix, use cam
's inverse.
注:上面的解释假定将向量视为列向量.如果将它们视为行向量(例如DirectX中的通用),则必须对计算进行相应的调整.
Note: The explanations above assume that vectors are treated as column vectors. If they are treated as row vectors (e.g. common in DirectX), the calculations have to be adapted accordingly.