OpenGL:转换后如何获取特定点的坐标? [英] OpenGL: How do I get the coordinates of a specific point after transformation?
问题描述
假设我的观点是(250,125,-20). 经过以下转换,
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?
推荐答案
转换后无法获取特定顶点(点)的坐标,但是对于这种特殊情况,您可以获取 ModelViewMatrix 应用平移/旋转后.
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
OpenGL中没有魔幻的磁带,您将不得不编写自己的框架,例如:对于您世界中的每个对象,您都拥有一个拥有顶点的类以及与之相关的数据.
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.
这篇关于OpenGL:转换后如何获取特定点的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!