【问题标题】:touch object GLKIT or OpenGL any functions?触摸对象 GLKIT 或 OpenGL 有什么功能?
【发布时间】:2012-12-14 14:21:39
【问题描述】:

我正在寻找一个描述来触摸我的 OpenGL 对象或在我触摸它时获取一个事件。 GLKit 或 OpenGL ES 有一些功能可以使用吗? 或者我必须计算我的对象的位置并且必须将它与我的 Touch 的坐标进行比较?

【问题讨论】:

    标签: ios opengl-es glkit


    【解决方案1】:

    没有内置的,但这里是 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-28
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 2020-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多