我试图找出为什么我的缩放在我的OpenGL相机上表现得非常奇怪。 它的目的是放大和缩小,但它的缩放非常随机。
继承我的代码:
- (void)pinchDetected:(UIPinchGestureRecognizer *)pinchRecognizer
{
NSLog (@"%@", @"Pinching");
if (pinchRecognizer.state == UIGestureRecognizerStateBegan ||
pinchRecognizer.state == UIGestureRecognizerStateChanged ||
pinchRecognizer.state == UIGestureRecognizerStateEnded) {
currentScale = pinchRecognizer.scale;
}
if(lastScale < currentScale) {
_camera.z += currentScale * 0.01f;
lastScale = currentScale;
}
if (lastScale > currentScale)
{
_camera.z -= currentScale * 0.01f;
lastScale = currentScale;
}
}
答案 0 :(得分:1)
如果你有一些可以乘法的东西,你想让它成为加法,你需要记录日志:
- (void)pinchDetected:(UIPinchGestureRecognizer *)pinchRecognizer
{
if ((gesture.state == UIGestureRecognizerStateBegan) ||
(gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
_camera.z += log(gesture.scale); // you'll probably want to multiply this by some constant
gesture.scale = 1.0;
}
}