I have the below code which I am using for ray tracing. The code works successfully on non-retina iPads, however does not function on the retina iPads. The touch is detected, however the converted point is off to the left and below where it should be. Can anyone suggest how I can update the below to accommodate the retina screen ?

- (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) {

        ...

} 
有帮助吗?

解决方案

Simply multiply x and y of tapLoc on [UIScreen mainScreen].scale and 1024*[UIScreen mainScreen].scale or replace with viewport[3]

I think something like:

- (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);

    ....
} 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top