为iPad Retina更新OpenGL ES Touch Detection(光线追踪)? [英] Updating OpenGL ES Touch Detection (Ray Tracing) for iPad Retina?

查看:201
本文介绍了为iPad Retina更新OpenGL ES Touch Detection(光线追踪)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我用于光线追踪。该代码在非视网膜iPad上成功运行,但无法在视网膜iPad上运行。检测到触摸,但是转换的点在其应该的左侧和下方偏离。任何人都可以建议我如何更新以下以适应视网膜屏幕?

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

        ...

} 


推荐答案

在[UIScreen mainScreen]上简单地乘以tapLoc的x和y .scale
和1024 * [ UIScreen mainScreen] .scale或替换为viewport [3]

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

我认为类似于:

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

    ....
} 

这篇关于为iPad Retina更新OpenGL ES Touch Detection(光线追踪)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆