gpt4 book ai didi

objective-c - 适用于 iOS 的 GluUnProject

转载 作者:行者123 更新时间:2023-11-28 17:37:46 25 4
gpt4 key购买 nike

通过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”。

我是不是跳过了一些非常重要的东西?

最佳答案

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

关于objective-c - 适用于 iOS 的 GluUnProject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9287972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com