GluProject not working… If the object haves Z=-1.0f and it is scaled to (0.01f,0.01f,0.0f) wich parameters i have to pass to GluProject?

痴心易碎 提交于 2019-12-11 18:02:06

问题


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.

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.

But now, I changued 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.

Wich X,Y,Z values I have to pass to gluProject? I'm passing -1,-1,0, and gluProject is giving me erroneal x,y outPutCoords values, (-101.774124,-226.27419)


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/8064805/gluproject-not-working-if-the-object-haves-z-1-0f-and-it-is-scaled-to-0-01f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!