我正在使用OpenGL来制作一点应用程序,我不知道如何获得触摸的x , y
和z
坐标
例如:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:[self view]];
float X = touchPoint.x;
float Y = touchPoint.y;
}
这样,我只得到x
和y
坐标,但是我还需要z
您无法在OpenGL ES上读取Z Buffer。当我需要进行这种3D命中测试时,我已经投射了一条3D线,并自己进行了命中测试。
对于视网膜设备上的OpenGL,您需要将x和y乘以刻度。要支持iPhone 6 ,您需要在可用的情况下使用AntictCale。
// Do this when setting up view controller and remember theScale.
if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)])
theScale = [[UIScreen mainScreen] nativeScale];
else if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
theScale = [[UIScreen mainScreen] scale];
else
theScale = 1.0;