OpenGL旋转 [英] OpenGL Rotation

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

问题描述

我想在OpenGL中做一个简单的旋转,但必须缺少的点。
我不是寻找一个特定的解决方案,因为一个快速的解释或链接解释OpenGL旋转更一般。

I'm trying to do a simple rotation in OpenGL but must be missing the point. I'm not looking for a specific fix so much as a quick explanation or link that explains OpenGL rotation more generally.

现在我有代码this:

At the moment I have code like this:

glPushMatrix();
  glRotatef(90.0, 0.0, 1.0, 0.0);
  glBegin(GL_TRIANGLES);        
    glVertex3f( 1.0, 1.0, 0.0 );        
    glVertex3f( 3.0, 2.0, 0.0 );        
    glVertex3f( 3.0, 1.0, 0.0 );        
  glEnd();
glPopMatrix();

但结果不是旋转90度的三角形。

But the result is not a triangle rotated 90 degrees.

编辑
感谢Mike Haboustak - 看来我的代码调用了使用glOrtho的SetCamera函数。我对OpenGL太新了,不知道这是什么意思,但是禁用它和在Z轴旋转产生了想要的结果。

Edit Hmm thanks to Mike Haboustak - it appeared my code was calling a SetCamera function that use glOrtho. I'm too new to OpenGL to have any idea of what this meant but disabling this and rotating in the Z-axis produced the desired result.

推荐答案

你有1个单位直线吗?看来90deg腐。围绕Y会让你看着没有深度的三角形的边。

Do you get a 1 unit straight line? It seems that 90deg rot. around Y is going to have you looking at the side of a triangle with no depth.

你应该尝试围绕Z轴旋转,看看你是否得到了更有意义。

You should try rotating around the Z axis instead and see if you get something that makes more sense.

OpenGL有两个与几何显示,即ModelView和投影相关的矩阵。在数据在屏幕上可见之前,两者都应用于坐标。首先应用ModelView矩阵,将数据从模型空间变换到视图空间。然后应用投影矩阵,将来自视图空间的数据变换为2D监视器上的投影。

OpenGL has two matrices related to the display of geometry, the ModelView and the Projection. Both are applied to coordinates before the data becomes visible on the screen. First the ModelView matrix is applied, transforming the data from model space into view space. Then the Projection matrix is applied with transforms the data from view space for "projection" on your 2D monitor.

ModelView用于将多个对象定位到世界中的位置,Projection用于将对象定位到屏幕上。

ModelView is used to position multiple objects to their locations in the "world", Projection is used to position the objects onto the screen.

您的代码似乎很好,所以我认为从阅读文档,你知道什么glPushMatrix()函数的性质。如果绕Z旋转仍然没有意义,请通过调用glMatrixMode验证您是否正在编辑ModelView矩阵。

Your code seems fine, so I assume from reading the documentation you know what the nature of functions like glPushMatrix() is. If rotating around Z still doesn't make sense, verify that you're editing the ModelView matrix by calling glMatrixMode.

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

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