2012-12-14 4 views

답변

2
더이 일에 내장,하지만 여기에 터치가 그 지점 근처에 있다면 당신이 볼 수 있도록, 화면 좌표에서 개체에서 점을 넣어 것입니다 gluProject 기능의 포팅 버전입니다

:

GLKVector3 gluProject(GLKVector3 position, 
        GLKMatrix4 projMatrix, 
        GLKMatrix4 modelMatrix, 
        CGRect viewport 
       ) 
{ 
GLKVector4 in; 
GLKVector4 out; 

in = GLKVector4Make(position.x, position.y, position.z, 1.0); 

out = GLKMatrix4MultiplyVector4(modelMatrix, in); 
in = GLKMatrix4MultiplyVector4(projMatrix, out); 

if (in.w == 0.0) NSLog(@"W = 0 in project function\n"); 
in.x /= in.w; 
in.y /= in.w; 
in.z /= in.w; 
/* Map x, y and z to range 0-1 */ 
in.x = in.x * 0.5 + 0.5; 
in.y = in.y * 0.5 + 0.5; 
in.z = in.z * 0.5 + 0.5; 

/* Map x,y to viewport */ 
in.x = in.x * (viewport.size.width) + viewport.origin.x; 
in.y = in.y * (viewport.size.height) + viewport.origin.y; 

return GLKVector3Make(in.x, in.y, in.z); 

} 

- (GLKVector2) getScreenCoordOfPoint { 

GLKVector3 out = gluProject(self.point, modelMatrix, projMatrix, view.frame); 

GLKVector2 point = GLKVector2Make(out.x, view.frame.size.height - out.y); 

return point; 
} 
+1

대단히 감사합니다. – J0k3R