1
要檢測的3D世界,通過了iOS的2D屏幕座標的座標,有沒有除了gluUnProject端口的任何其他可能的方式?GluUnProject爲iOS
我一直在擺弄周圍上到底這天,我不能看到一些它的竅門。
-(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;
}
}
我的代碼很好。是的,我可以很容易地使用一個結構,但當時我太精神上很難做。這是我以後可以回去修理的東西。
Anywho的一點是,使用的NSLog我輸出到調試器時後,我用gluUnProject的nearplane的和farplane的不轉發結果甚至接近準確。事實上,他們都傳達了完全相同的結果,更不用說,第一次點擊總是再現x,y,所有等於「nan」。
難道我跳過一些非常重要的位置?
我知道沒有,這是我在網上找到的一些代碼。這讓我不確定要做什麼。 我應該用什麼來代替'GL_PROJECTION_MATRIX'和'GL_MODELVIEW_MATRIX'? – Fiattarone 2012-04-11 19:28:04