我试图弄清楚为什么我的缩放比例在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;
    }

}

最佳答案

如果您有可乘的东西并且想要使其加法,则需要记录以下日志:

- (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;
    }
}

10-08 03:33