问题描述
直到现在,我使用了 gluProject
、透视投影和一个以屏幕为中心、左下角顶点 (-1,-1,0) 的可缩放正方形.我缩放正方形调整 Z 轴.
Until now, I worked with gluProject
, perspective projection, and a zoomable square centered on the screen with a lower left vertex (-1,-1,0). I zoom the square adjusting the Z axis.
例如,我将正方形缩放到 Z=-5,并使用 openGL 对象参数 (-1,-1,0) 调用 gluProject
以了解窗口像素 X、Y 位置正方形的那个顶点.它工作正常.
For example, I zoomed the square to Z=-5, and I call gluProject
with the openGL object parameters (-1,-1,0) to know the window pixels X,Y position of that vertex of the square. It works fine.
但是现在,我改变了我的架构,现在我不是使用 Z 来缩放,而是缩放来缩放.我在 Z=-1.0f 处有正方形,最初它被缩放到 (0.01f,0.01f,0.0f),是一个小正方形.
But now, I changed my architecture, and now I'm not using Z to zoom, I'm scaling to zoom. I have the square at Z=-1.0f, and initially it is scaled to (0.01f,0.01f,0.0f), is a small square.
我必须将哪些 X、Y、Z 值传递给 gluProject
?我正在传递 -1,-1,0,并且 gluProject
给了我错误的 x,y outPutCoords 值,(-101.774124,-226.27419)
Which X,Y,Z values do I have to pass to gluProject
? I'm passing -1,-1,0, and gluProject
is giving me erroneous x,y outPutCoords values, (-101.774124,-226.27419)
推荐答案
一次又一次: gluProject
做与 OpenGL 转换管道完全相同的事情(如果当然,使用 OpenGL 的矩阵和视口调用).所以无论你发送给 OpenGL 的顶点是什么,这些都是你必须放入 gluProject
的顶点.
Again and again and again: gluProject
does exactly the same thing like the OpenGL transformation pipeline (if called with OpenGL's matrices and viewport, of course). So whatever vertices you send to OpenGL, these are the vertices you have to put into gluProject
.
如果使用顶点 (-1,-1,0) 渲染多边形,则必须使用该顶点调用 gluProject
.所有其他变换(无论是平移、缩放、旋转还是其他任何变换)都来自变换矩阵.但是如果您确实使用顶点 (0.01, 0.01, 0) 渲染多边形,那么您必须将其放入 gluProject
.
If you render the polygon using the vertex (-1,-1,0), then you have to call gluProject
with this vertex. Every other transformation (be it translation, scaling, rotation, or whatever) comes from the transformation matrices. But if you indeed render the polygon using the vertex (0.01, 0.01, 0), then you have to put this into gluProject
.
确保您完全了解 OpenGL 转换管道(这个问题的答案可能会有所帮助)以及 gluProject
在继续使用它并为您认为给出错误结果的每个小输入发布问题之前.
Make sure you completely understand the OpenGL transformation pipeline (the answers to this question may help) and the workings of gluProject
before continuing to use it and posting questions for every little input that you think gives wrong results.
这篇关于GluProject 不工作...如果对象具有 Z=-1.0f 并且缩放到 (0.01f,0.01f,0.0f) 我必须将哪些参数传递给 GluProject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!