更新iPad Retina的OpenGL ES触摸检测(光线追踪)?

我有下面的代码,我正在使用光线追踪。 该代码可以在非视网膜iPad上成功运行,但不能在视网膜iPad上运行。 触摸被检测到,但是转换后的点在左边,在下面。 任何人都可以build议如何更新下面以适应视网膜屏幕?

- (void)handleTap: (UITapGestureRecognizer *)recognizer { CGPoint tapLoc = [recognizer locationInView:self.view]; bool testResult; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); float uiKitOffset = 113; //Need to factor in the height of the nav bar + the height of the tab bar at the bottom in the storyboard. GLKVector3 nearPt = GLKMathUnproject(GLKVector3Make(tapLoc.x, (tapLoc.y-1024+uiKitOffset)*-1, 0.0), modelViewMatrix, projectionMatrix, &viewport[0] , &testResult); GLKVector3 farPt = GLKMathUnproject(GLKVector3Make(tapLoc.x, (tapLoc.y-1024+uiKitOffset)*-1, 1.0), modelViewMatrix, projectionMatrix, &viewport[0] , &testResult); farPt = GLKVector3Subtract(farPt, nearPt); for (Object * Object in self.objectArray) { ... } 

只需将[UIScreen mainScreen] .scale和1024 * [UIScreen mainScreen] .scale中的tapLoc的x和y相乘,或者用viewport [3]replace即可。

我觉得像这样:

 - (void)handleTap: (UITapGestureRecognizer *)recognizer { CGPoint tapLoc = [recognizer locationInView:self.view]; tapLoc.x *= [UIScreen mainScreen].scale; tapLoc.y *= [UIScreen mainScreen].scale; bool testResult; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); float uiKitOffset = 113; //Need to factor in the height of the nav bar + the height of the tab bar at the bottom in the storyboard. GLKVector3 nearPt = GLKMathUnproject(GLKVector3Make(tapLoc.x, (tapLoc.y-viewport[3]+uiKitOffset)*-1, 0.0), modelViewMatrix, projectionMatrix, &viewport[0] , &testResult); GLKVector3 farPt = GLKMathUnproject(GLKVector3Make(tapLoc.x, (tapLoc.y-viewport[3]+uiKitOffset)*-1, 1.0), modelViewMatrix, projectionMatrix, &viewport[0] , &testResult); farPt = GLKVector3Subtract(farPt, nearPt); .... }