凡指出OpenGL的z轴? [英] Where points OpenGL z-axis?

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

问题描述

我想了解OpenGL的坐标系。我到处都看到它的描述为右撇子,但它不符合我的经验相一致。我试着画一些形状和三维物体和我看到的,显然z轴点到屏幕(能够在X点向右,而y起来 - 这是左手坐标系的描述)。我在想什么?

编辑: 例如:
<一href="http://img576.imageshack.us/img576/9234/triangles.jpg">http://img576.imageshack.us/img576/9234/triangles.jpg
如果+ Z指向观众,为什么绿色三角形,其中,Z坐标是较大的,背后是红色的?

initializeGL:

  qglClearColor(QT ::深灰);
glClearDepth(1.0);
过glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
过glEnable(GL_COLOR);
 

resizeGL:

  glViewport(0,0,宽度,高度);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0f,50.0f,-50.0f,50.0f,50.0,-50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
 

paintGL:

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(-30.0,1.0,0.0,0.0);
glRotatef(20.0,0.0,1.0,0.0);
glColor3f(1.0,0.0,0.0);
在glBegin(GL_LINES);
glVertex3f(45.0,0.0,0.0);
glVertex3f(-45.0,0.0,0.0);
glVertex3f(0.0,45.0,0.0);
glVertex3f(0.0,-45.0,0.0);
glVertex3f(0.0,0.0,45.0);
glVertex3f(0.0,0.0,-45.0);
glEnd();
在glBegin(GL_TRIANGLES);
//红三角:
glColor3f(1.0,0.0,0.0);
glVertex3f(0.0,0.0,1.0);
glVertex3f(0.0,20.0,1.0);
glVertex3f(20.0,0.0,1.0);
//绿三角:
glColor3f(0.0,1.0,0.0);
glVertex3f(-15.0,0.0,20.0);
glVertex3f(0.0,25.0,20.0);
glVertex3f(15.0,0.0,20.0);
glEnd();
 

解决方案

最后2个参数的 glOrtho 参考:

  

nearVa​​l,farVal
  指定距离的近远深度裁剪平面。 这些值是负的,如果飞机是被观察者的后面。

您更近剪裁平面是在观众面前远,落后。它会翻转Z轴。

I'm trying to understand OpenGL coordinate system. Everywhere I see it's described as right-handed one, but it doesn't correspond with my experience. I tried to draw some shapes and 3-d objects and I see that apparently z-axis points "into the screen" (while x points to right, and y up - which is description of left-handed coordinate system). What am I missing?

edit: For example:
http://img576.imageshack.us/img576/9234/triangles.jpg
If +Z points viewer, why green triangle, which z-coordinate is larger, is behind red one?

initializeGL:

qglClearColor(Qt::darkGray);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc( GL_LEQUAL );    
glEnable(GL_COLOR);  

resizeGL:

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0f, 50.0f, -50.0f, 50.0f, 50.0, -50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

paintGL:

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef (-30.0, 1.0, 0.0, 0.0);
glRotatef (20.0, 0.0, 1.0, 0.0);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex3f(45.0, 0.0, 0.0);
glVertex3f(-45.0, 0.0, 0.0);
glVertex3f(0.0, 45.0,  0.0);
glVertex3f(0.0, -45.0,  0.0);
glVertex3f( 0.0, 0.0, 45.0);
glVertex3f( 0.0, 0.0, -45.0);
glEnd();
glBegin(GL_TRIANGLES);
//Red triangle:
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 20.0, 1.0);
glVertex3f(20.0, 0.0, 1.0);
//Green triangle:    
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-15.0, 0.0, 20.0);
glVertex3f(0.0, 25.0, 20.0);
glVertex3f(15.0, 0.0, 20.0);
glEnd();

解决方案

Last 2 parameters glOrtho reference:

nearVal, farVal
Specify the distances to the nearer and farther depth clipping planes. These values are negative if the plane is to be behind the viewer.

Your nearer clipping plane is in front of the viewer and farther, behind. It'll flip Z axis.

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

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