OpenGL 中的倒置 X 轴 [英] Inverted X axis in OpenGL

查看:33
本文介绍了OpenGL 中的倒置 X 轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

X 轴在我的 OpenGL 测试程序中似乎倒转了...

The X axis seems inverted in my OpenGL test program...

红色立方体位于 (0,0,0),白色立方体位于 (0,0,1),蓝色立方体位于 (1,0,0),但它出现在红色方块.

The red cube is placed at (0,0,0), the white one at (0,0,1) and the blue one at (1,0,0), and yet it appears at the left of the red cube.

我使用了这段代码对于投影/视图矩阵,所以我不认为它来自那里......是否有任何 OpenGL 参数可以做到这一点?

I used this code for the projection/view matrix, so I don't think it comes from there... Is there any OpenGL parameter that might do that?

以下是相机在 (1.57, 4.54, -1.23) 处,水平角为 6.09rad,垂直角为 -0.97rad 时的矩阵示例:

Here is an example of the matrices when the camera is at (1.57, 4.54, -1.23) with 6.09rad as horizontal angle and -0.97rad as vertical angle :

投影矩阵:

 1.34  0     0     0
 0     1.79  0     0
 0     0    -1    -1
 0     0    -0.02   0

视图矩阵:

-0.98  -0.15   0.1    0
-2.14   0.56   0.82   0
-0.18   0.81  -0.55   0
 1.32  -1.31  -4.59   1

推荐答案

这只是您使用的相机位置的自然结果.

This is just a natural result of the camera position you are using.

描绘一个标准的右手坐标系:

Picture a standard right-handed coordinate system:

   |y
   |
   |
   |________x
  /
 /
/z

在这个草图中,x 从左到右,y 从下到上,z 朝向我们.

In this sketch, x goes from left to right, y from bottom to top, and z towards us.

这意味着,如果您使用具有 z 值的相机位置,该相机将看到与此草图对应的方向上的 xy 平面.这反过来意味着具有较大 x 值的点位于具有较小 x 值的点的右侧.

This means that if you used a camera position with a positive z-value, this camera would see the xy-plane in the orientation that corresponds to this sketch. Which in turn means that points with larger x-values are to the right of points with smaller x-values.

现在,如果您使用具有 z 值的相机位置(在您的示例中就是这种情况),整个事情就会发生转变.从相机看到的坐标系现在看起来更像这样:

Now, if you use a camera position with a negative z-value, which is the case in your example, this whole thing turns around. The coordinate system viewed from the camera now looks more like this:

       y|
        |  /z
        | /
x_______|/

如您所见,从这个有利位置,x 轴现在从右到左,这意味着具有较大 x 值的点现在位于具有较小 x 值的点的左侧.

As you can see, from this vantage point, the x-axis now goes from right to left, which means that points with larger x-values are now left of points with smaller x-values.

这正是您的渲染所显示的内容.蓝色立方体的 x 坐标比红色立方体大,因此从这个方向看,它显示在红色立方体的左侧.

This is exactly what your rendering shows. The blue cube has larger x-coordinates than the red cube, so it shows up on the left of the red cube when viewed from this direction.

这篇关于OpenGL 中的倒置 X 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆