变换后获取对象在opengl中的位置
我想获取 OpenGL 中对象的坐标。我画了一个四边形。之后我做了一些转换,例如 GL11.glTranslatef() 和 GL11.glRotatef()。
GL11.glBegin(GL11.GL_QUADS); // draw independent triangles
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f(-0.2f, 0.0f, -2.0f); // lower left vertex
GL11.glVertex3f( 0.2f, 0.0f, -2.0f); // upper vertex
GL11.glVertex3f( 0.2f, 0.4f, -2.0f); // lower right verte
GL11.glVertex3f( -0.2f, 0.4f, -2.0f);
GL11.glEnd();
是否可以得到变换后顶点的位置?
I would like to get the coordinates of an object in OpenGL. I draw a quad. And after that I do some transforms like GL11.glTranslatef() and GL11.glRotatef().
GL11.glBegin(GL11.GL_QUADS); // draw independent triangles
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f(-0.2f, 0.0f, -2.0f); // lower left vertex
GL11.glVertex3f( 0.2f, 0.0f, -2.0f); // upper vertex
GL11.glVertex3f( 0.2f, 0.4f, -2.0f); // lower right verte
GL11.glVertex3f( -0.2f, 0.4f, -2.0f);
GL11.glEnd();
Is it possible to get the position of the vertices after the transformation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然。将相同的变换(平移和旋转)应用于保存对象位置的位置向量。结果将是变换后对象的位置。如果您想将 3d 坐标转换为 2d 屏幕坐标,您可能需要在某些时候进行一些缩放。但这是非常可行的。它涉及基于对象的 z 深度的缩放。
编辑:
但您可能只想使用比 LWJGL 更完整的东西。谷歌vecmath,处理,统一。 3D 很棘手,似乎没有真正的捷径,所以只要继续尝试,你就会得到它。
Sure. Apply the same transforms (translations and rotations) to a position vector, that holds the position of your object. The result will be the position of your object after the transform. You may need to do some scaling at some point if you want to convert the 3d co-ords to 2d screen co-ords. But this is very much doable. It involves scaling based on the z-depth of the object.
EDIT:
But you may want to simply use something more complete than LWJGL. Google vecmath, processing, unity. 3D is tricky and it seems there are no real short cuts, so just keep trying, you will get it.
这是不可能的... opengl 将您的顶点数据发送到 GPU,并且只有在 GPU 上您才能在转换后获取它们。
要获得变换后的顶点,您必须将它们乘以矩阵,
一些更高级的方法是使用变换反馈并将这些变换后的顶点存储到缓冲区中(但该缓冲区仍将存储在 GPU 上)。
this is not possible... opengl sends your vertex data to the GPU and only on GPU you can get them after the transformation.
to get transformed vertices you have to multiply them by the matrix
some more advanced ways is to use transform feedback and store those transformed vertices into a buffer (but still this buffer will be stored on the GPU).