OpenGL gluProject() - 奇怪的结果
我正在使用 gluProject 函数,在“渲染”后获取二维窗口中的点坐标。问题是,我得到了奇怪的结果。例如:我有一个 x=16.5 的点。当我在其上使用 gluProject 时,我得到 x= -6200.0。
如果我理解 gluProject 好的,我应该在“渲染”后获得屏幕上该点的像素位置 - 我对吗?如何将这个奇怪的结果转换为屏幕上的像素坐标?
感谢您的帮助!
我使用的代码(通过“sum1stolemyname”):
GLdouble modelview[16], projection[16]
GLint viewport[4];
glGetDoublev(GL_MODELVIEW_MATRIX, *modelView);
glGetDoublev(GL_PROJECTION_MATRIX, *projection);
glGetIntegerv(GL_VIEWPORT, *viewport);
double tx, ty, tz;
for(i = 0; i < VertexCount; i++)
{
gluProject(vertices[i].x, vertices[i].y, vertices[i].z,
modelview, projection, viewport,
&tx, &ty, &tz)
}
I'm tying to use gluProject
function, to get point coordinates in 2d window after "rendering". The problem is, that I get strange results. For example: I've got a point with x=16.5. When I use gluProject
on it I get x= -6200.0.
If I understand gluProject
OK, I should get a pixel position of that point on my screen after "rendering" - am I right? How can I convert that strange result into on-screen pixel coordinates?
Thank you for any help!
Code I use (by "sum1stolemyname"):
GLdouble modelview[16], projection[16]
GLint viewport[4];
glGetDoublev(GL_MODELVIEW_MATRIX, *modelView);
glGetDoublev(GL_PROJECTION_MATRIX, *projection);
glGetIntegerv(GL_VIEWPORT, *viewport);
double tx, ty, tz;
for(i = 0; i < VertexCount; i++)
{
gluProject(vertices[i].x, vertices[i].y, vertices[i].z,
modelview, projection, viewport,
&tx, &ty, &tz)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,不幸的是它确实做到了远平面,这样你就可以构建一条进入世界的“射线”。它不会提供您在 3D 空间中绘制的像素的实际位置。您可以做的是从屏幕到从 gluProject 获得的点画一条线,然后使用它来查找与几何体的交点,以获取 3D 空间中的点。或者另一种选择是修改输入矩阵和视口,使远平面成为更合理的距离。
Yeah it does unfortunately it does it as far as the far plane so you can construct a 'ray' into the world. It does not give you the actual position of the pixel you are drawing in 3D space. What you can do is make a line from the screen to your point you get from the gluProject then use that to find the intersection point with your geometry to get the point in 3D space. Or another option is to modify your input matrices and viewport so the far plane is a more reasonable distance.