这里是OpenGL ES的新手。 我使用下面的代码来检测我在GLKView(OpenGL ES 2.0)中点击的位置。我想知道是否触摸了我的OpenGL绘制的对象。这都是2D。 如何将坐标转换为OpenGL ES 2.0坐标,这些坐标基于-1.0到1.0?有没有建立在这样做的功能?iOS将TouchBegan坐标转换为OpenGL ES坐标
谢谢。
- (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);
}
我可以这样做:* x =((* x /(bounds.size.width))* 2.0) - 1.0; *(((bounds.size.height- * y)/(bounds.size.height))* 2.0) - 1.0;但看到这是一个频繁的任务是否有内置函数? – lppier