修改OpenGL轴系

发布于 2024-09-02 06:47:20 字数 71 浏览 2 评论 0原文

我正在将 OpenGL 与 gluPerspective 结合使用,我需要做什么才能使其使用原点位于左上角而不是左下角的轴系统?

I'm using OpenGL with gluPerspective, what would I need to do to make it use an axis-system which the origin is top left instead of bottom left?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柏拉图鍀咏恒 2024-09-09 06:47:20

我想说,直接对投影矩阵进行操作是这种操作的一种简洁方法。但如果万一您需要替代方案:

您可以使用 glScalef(1.f, -1.f, 1.f) 来翻转轴。

这也只是对 GL_MODELVIEW 或 GL_PROJECTION 矩阵(无论当前处于活动状态)的操作。

I would say direct operating on the projection matrix is a clean way for this operation. But if by any chance you need an alternative:

You can just use glScalef(1.f, -1.f, 1.f) to flip the axis.

This is also just an operation on the GL_MODELVIEW or GL_PROJECTION matrix (whatever is currently active).

枕梦 2024-09-09 06:47:20

您可以通过翻转投影矩阵的 y 轴来完成此操作。所以:

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrix( [1  0  0  0; 
               0 -1  0  0; 
               0  0  1  0; 
               0  0  0  1] ); 
            // ^ pseudo-code, replace with actual matrix

应该可以了。

您还可以使用具有相同矩阵的 glMultMatrix 调用(而不是 Push 然后 Load),但这种方式更容易逆转(只需稍后在 GL_PROJECTION 堆栈上调用 glPopMatrix)。

您还可以使用相同的技术来翻转任何其他轴;只需在适当的位置添加减号即可。

You can do this by flipping the y-axis of the projection matrix. So:

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrix( [1  0  0  0; 
               0 -1  0  0; 
               0  0  1  0; 
               0  0  0  1] ); 
            // ^ pseudo-code, replace with actual matrix

That ought to do it.

You could also use a glMultMatrix call with the same matrix (instead of Push and then Load), but this way is more easily reversed (just call glPopMatrix on the GL_PROJECTION stack later).

You can also use the same technique to flip any of the other axes; just put minus signs in the appropriate locations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文