使用GLM的UnProject [英] Using GLM's UnProject

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

问题描述

我不知道如何使用 Unproject方法 by GLM。

I'm not sure how to use the Unproject method provided by GLM.

具体来说,视口传入的格式是什么?为什么函数不需要视图矩阵以及投影和世界矩阵?

Specifically, in what format is the viewport passed in? And why doesn't the function require a view matrix as well as a projection and world matrix?

推荐答案

需要这里。 GLM的项目实际上或多或少是直接替代 gluUnProject 函数使用不推荐的OpenGL固定函数呈现。在这种模式下,Model和View矩阵实际上在ModelView矩阵中组合。显然,GLM作者在命名中删除了'view'部分,这让事情更加困惑,但它归结为传递 view * model

A bit of history is required here. GLM's unproject is actually a more or less direct replacement for the gluUnProject function that uses deprecated OpenGL fixed-function rendering. In this mode the Model and View matrix were actually combined in the "ModelView" matrix. Apparently, the GLM author dropped the 'view' part in the naming, which confuses thing even more, but it comes down to passing something like view*model.

现在实际使用:


  • win是一个向量,在窗口坐标。这些是您的视口中的坐标'x,y',通常通过读取(x,y)
  • $ b时的深度缓冲区检索的'z' $ b
  • 模型,视图和投影矩阵应该说自己,如果你甚至想使用这个函数。但是一个好的(特定于opengl的)复习可能很有用。

  • 视口在 glViewport 中定义,表示(x ,y,w,h)。 X和Y指定视口的左下角(通常为0,0)。宽度和高度(w,h)。注意,在许多其他系统x,y指定左上角,你必须转换你的y坐标,这显示在NeHe代码我链接到下面。

  • win is a vector that holds three components that have meaning in Window coordinates. These are coordinates 'x,y' in your viewport, the 'z' coordinate you usually retrieve by reading your depth buffer at (x,y)
  • model, view and projection matrices should speak for itself if you're even thinking of using this function. But a good (opengl-specific) refresher can be useful.
  • The viewport is defined as in glViewport, which means (x,y,w,h). X and Y specify the lower left corner of your viewport (usually 0,0). Width and height (w,h). Note that in many other systems x,y specify the upper left corner, you have to transform your y-coordinate then, which is shown in the NeHe code I link to below.

应用时,只需将提供的窗口坐标转换回对象坐标,或多或少地与渲染代码通常所做的相反。

When applied you simply end up by converting the provided window coordinates back to the object coordinates, more or less the inverse of what your render code usually does.

对原始 gluUnProject 的一个半不错的解释可以作为 NeHe文章。但是当然是OpenGL特定的,而glm可以在其他上下文中使用。

A half-decent explanation on the original gluUnProject can be found as a NeHe article. But of course that is OpenGL-specific, while glm can be used in other contexts.

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

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