本文介绍了OpenGL-对象局部旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作类似的东西-让我们使用现代OpenGL将其称为飞行模拟器.我正在尝试使用偏航,俯仰和滚转来旋转我的平面对象.但是似乎对象围绕全局坐标系旋转(我的意思是,如果我的对象面对矢量(0,0,1),则滚动操作应按其应有的方式进行,但如果我将其面向例如(1,0,0),则其行为将类似于俯仰)

I am trying to make something like - lets call it flight simulator using modern OpenGL. I am trying to use yaw, pitch and roll to rotate my plane object. But it seems object rotates around global coordinate system (I mean if my object faces vector (0,0,1) roll operation works like it should but if i turn it to face for example (1,0,0) it behaves like pitch)

我的变换矩阵是这样计算的:

my transformation matrix is calculated like this:

  transformation_matrix = perspective_projection_matrix *
                        camera_rotation_matrix *
                        camera_translation_matrix *
                        translation_matrix *
                        rotation_matrix *
                        scale_matrix;

旋转矩阵为

rotation_matrix = rotation_z * rotation_y * rotation_x;

我尝试在平移矩阵之前添加局部旋转矩阵,但看起来更糟(对象现在围绕着默认默认值在空间中的某个点飞行)

I tried to add local rotation matrix before translation one but it looks even worse (object now flies around some point in space facing always default)

我应该怎么做才能在局部坐标系中使用偏航,俯仰和横滚来旋转像典型平面这样的对象?

What should I do to rotate object like typical plane with yaw, pitch and roll in local coordinates system?

编辑

情况并非如此,我的坏

Not the case, my bad

推荐答案

平面的方向最终将是围绕不同轴的许多离散旋转的串联.这与简单地将各个旋转求和不同.他们不是独立的.

The plane's orientation will ultimately be the concatenation of many discrete rotations around different axes. This is not the same as simply summing the individual rotations. They are not independent.

例如,如果您向上倾斜90度,向下滚动90度,然后向下倾斜90度,则结果方向不是为90度,而是偏航为90度.

For example, if you pitch up 90 degrees, roll 90 degrees, and then pitch down 90 degrees, the resulting orientation will not be a roll of 90 degrees, but instead a yaw of 90 degrees.

相反,请保留一个表示您的平面方向的持久矩阵,然后对其进行适当的滚动,俯仰和偏航旋转.

Instead, keep a persistant matrix which represents the orientation of your plane, and then apply roll, pitch, and yaw rotations to it as appropriate.

这篇关于OpenGL-对象局部旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:11