我是一名新手,正在学习OpenGL ES。我正在使用以下代码来检测我在GLKView(OpenGL ES 2.0)中点击的位置。我想知道是否触摸到了我的OpenGL绘制对象。这都是2D的。
如何将我获取的坐标转换为OpenGL ES 2.0坐标,它们似乎基于-1.0到1.0?是否已经有内置函数可以实现此功能?
谢谢。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self.view bounds];
UITouch* touch = [[event touchesForView:self.view] anyObject];
CGPoint location = [touch locationInView:self.view];
NSLog(@"x: %f y: %f", location.x, location.y);
}