哪里指向OpenGL z轴? [英] Where points OpenGL z-axis?

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

问题描述

我正在尝试了解 OpenGL 坐标系.我在任何地方看到它都被描述为右手,但这与我的经验不符.我尝试绘制一些形状和 3-d 对象,我看到 z 轴显然指向屏幕"(而 x 指向右侧,y 向上 - 这是对左手坐标系的描述).我错过了什么?

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?

例如:
http://img576.imageshack.us/img576/9234/triangles.jpg
如果+Z指向观察者,为什么z坐标较大的绿色三角形在红色三角形后面?

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?

初始化GL:

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

调整GL:

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();

推荐答案

最后 2 个参数 glOrtho 参考:

Last 2 parameters glOrtho reference:

nearVal, farVal
指定到更近和更远深度剪裁平面的距离.如果飞机在观察者后面,这些值为负.

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.

较近的剪切平面在查看者的前面,而较远的在后面.它将翻转 Z 轴.

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

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

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