OpenGL: How do I get the coordinates of a specific point after transformation?

人走茶凉 提交于 2019-12-07 14:49:33

问题


Suppose I have a point at (250,125,-20). After the following transformation,

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(100.0, 50.0, 0.0);
glRotatef(-25.0, 0.0, 1.0, 0.0);    

How can I get the value of current coordinates of that point? Need I write a subroutine to multiply a matrix to a vector? Are there any built-in solutions?


回答1:


You can't get the coordinates for a specific vertex (point) after a transformation, however for this particular case you can get the ModelViewMatrix after the translate/rotate is applied.

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(100.0, 50.0, 0.0);
glRotatef(-25.0, 0.0, 1.0, 0.0);  

glGetFloatv(GL_MODELVIEW_MATRIX , *your_matrix*);
//print your matrix to check if that is the desired transformation coordinates

There is no magic tape in OpenGL, you will have to write your own framework e.g: for every objects in your world a class where you hold the vertices and what data you find relevant.



来源:https://stackoverflow.com/questions/5596054/opengl-how-do-i-get-the-coordinates-of-a-specific-point-after-transformation

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