在xz平面上绘制场景opengl [英] Drawing a scene in xz plane opengl

查看:385
本文介绍了在xz平面上绘制场景opengl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个opengl程序。查看参数是:
eye 0 -4 6
viewup 0 1 0
lookat 0 0 0



背景矩形(具有纹理),使得我将能够从当前眼睛位置看到它。现在,眼睛从-ve Y方向看。我想要能够绘制一个覆盖整个屏幕的矩形。我不知道什么坐标给矩形和如何获得纹理映射。
目前我有这个在我的方法:
什么是同样的代码。我有这个功能:

  glPushMatrix 
glLoadIdentity();
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f);
glVertex2f(-1.0,-1.0);
glVertex2f(-1.0,1.0);
glVertex2f(1.0,1.0);
glVertex2f(1.0,-1.0);
glEnd();
glPopMatrix();


解决方案

绘制独立的背景图片的相机是在标准化设备坐标(NDC)中绘制它,并且不对其执行任何变换/投影。
要覆盖整个屏幕,你必须绘制一个从p = [-1,-1]到[1,1]的四边形。然后可以通过tex =(p + 1)/ 2找到纹理坐标。

标准化的设备坐标是在应用投影和透视除法之后通常得到的坐标。它们跨越从[-1,-1,-1]到[1,1,1]的立方体,其中近平面被映射到z = -1(至少在OpenGL中,在DirectX中,近平面被映射到z = 0)。在你的特殊情况下,深度并不重要,只要你绘制背景平面作为每个帧中的第一个元素,并禁用深度测试。


I am working on an opengl program. The viewing parameters are : eye 0 -4 6 viewup 0 1 0 lookat 0 0 0

I want to draw a background rectangle (with texture) such that I will be able to see it from the current eye location. Right now, the eye is looking from the -ve Y direction. I want to be able to draw a rectangle that covers the entire screen. I am not understanding what coordinates to give to the rectangle and how to get the texture mapping. Currently I have this in my method: What would be the code for the same. I have this in function:

glPushMatrix();
glLoadIdentity();
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-1.0, -1.0);
glVertex2f(-1.0, 1.0);
glVertex2f(1.0, 1.0);
glVertex2f(1.0, -1.0);
glEnd();
glPopMatrix();

解决方案

The easiest option for drawing a background image that is independent of the camera is to draw it in normalized device coordinates (NDC) and do not perform any transformations/projections on it. To cover the whole screen, you have to draw a quad going from p = [-1, -1] to [1,1]. The texture coordinates can then be found by tex = (p + 1)/2

Normalized device coordinates are the coordinates one would normally get after applying projection and the perspective divide. They span a cube from [-1,-1,-1] to [1,1,1] where the near plane is mapped to z = -1 (at least in OpenGL, in DirectX the near plane is mapped to z=0). In your special case, the depth should not matter, as long as you draw the background plane as the first element in each frame and disable the depth-test.

这篇关于在xz平面上绘制场景opengl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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