iOS 版 GluUnProject

发布于 2025-01-06 01:39:55 字数 1441 浏览 1 评论 0原文

要通过iOS的2D屏幕坐标检测3D世界坐标,除了gluUnProject端口之外还有其他可能的方法吗?

我已经连续几天摆弄这个问题了,但我似乎无法掌握它的窍门。

-(void)receivePoint:(CGPoint)loke
{

GLfloat projectionF[16];
GLfloat modelViewF[16];
GLint viewportI[4];

glGetFloatv(GL_MODELVIEW_MATRIX, modelViewF);
glGetFloatv(GL_PROJECTION_MATRIX, projectionF);
glGetIntegerv(GL_VIEWPORT, viewportI);

loke.y = (float) viewportI[3] - loke.y;

float nearPlanex, nearPlaney, nearPlanez, farPlanex, farPlaney, farPlanez;

gluUnProject(loke.x, loke.y, 0, modelViewF, projectionF, viewportI, &nearPlanex, &nearPlaney, &nearPlanez);
gluUnProject(loke.x, loke.y, 1, modelViewF, projectionF, viewportI, &farPlanex, &farPlaney, &farPlanez);

float rayx = farPlanex - nearPlanex;
float rayy = farPlaney - nearPlaney;
float rayz = farPlanez - nearPlanez;

float rayLength = sqrtf((rayx*rayx)+(rayy*rayy)+(rayz*rayz));

//normalizing rayVector

rayx /= rayLength;
rayy /= rayLength;
rayz /= rayLength;

float collisionPointx, collisionPointy, collisionPointz;

for (int i = 0; i < 50; i++) 
{
    collisionPointx = rayx * rayLength/i*50;
    collisionPointy = rayy * rayLength/i*50;
    collisionPointz = rayz * rayLength/i*50;
}
}

我的代码中有很大一部分。是的,我可以很容易地使用一个结构,但当时我的心理太胖了,无法做到这一点。这是我可以稍后回去修复的问题。

无论如何,重点是,当我在使用 gluUnProject 后使用 NSLog 输出到调试器时,近平面和远平面不会传递结果,甚至接近准确。事实上,它们都传递完全相同的结果,更不用说,第一次单击总是重现 x、y 和 & 。 z 全部等于“nan”。

我是否在这里跳过了一些非常重要的事情?

To detect 3D world coordinates through the 2D screen coordinates of the iOS, is there any other possible way besides the gluUnProject port?

I've been fiddling around with this days on end now, and I can't seemingly get the hang of it.

-(void)receivePoint:(CGPoint)loke
{

GLfloat projectionF[16];
GLfloat modelViewF[16];
GLint viewportI[4];

glGetFloatv(GL_MODELVIEW_MATRIX, modelViewF);
glGetFloatv(GL_PROJECTION_MATRIX, projectionF);
glGetIntegerv(GL_VIEWPORT, viewportI);

loke.y = (float) viewportI[3] - loke.y;

float nearPlanex, nearPlaney, nearPlanez, farPlanex, farPlaney, farPlanez;

gluUnProject(loke.x, loke.y, 0, modelViewF, projectionF, viewportI, &nearPlanex, &nearPlaney, &nearPlanez);
gluUnProject(loke.x, loke.y, 1, modelViewF, projectionF, viewportI, &farPlanex, &farPlaney, &farPlanez);

float rayx = farPlanex - nearPlanex;
float rayy = farPlaney - nearPlaney;
float rayz = farPlanez - nearPlanez;

float rayLength = sqrtf((rayx*rayx)+(rayy*rayy)+(rayz*rayz));

//normalizing rayVector

rayx /= rayLength;
rayy /= rayLength;
rayz /= rayLength;

float collisionPointx, collisionPointy, collisionPointz;

for (int i = 0; i < 50; i++) 
{
    collisionPointx = rayx * rayLength/i*50;
    collisionPointy = rayy * rayLength/i*50;
    collisionPointz = rayz * rayLength/i*50;
}
}

There's a good chunk of my code. Yeah, I could have easily used a struct but I was too mentally fat to do it at the time. That's something I could go back and fix later.

Anywho, the point is that when I output to the debugger using NSLog after I use gluUnProject, the nearplane's and farplane's don't relay results even close to accurate. In fact, they both relay the exact same results, not to mention, the first click always reproduces x, y, & z being all equal to "nan."

Am I skipping over something extraordinarily important here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怕倦 2025-01-13 01:39:55

ES2.0 中没有 gluUnProject 函数,您使用的端口是什么?此外,也没有 GL_MODELVIEW_MATRIXGL_PROJECTION_MATRIX,这很可能是您的问题。

There is no gluUnProject function in ES2.0, what is this port that you are using? Also there is no GL_MODELVIEW_MATRIX or GL_PROJECTION_MATRIX, which is most likely your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文