2012-03-13 221 views
0

我試圖找出爲什麼我的縮放在我的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

它隨時改變的,所以它基本上不會以連續因子進行縮放。如果這是有道理的? – JavaCake 2012-03-13 21:10:07

回答

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; 
    } 
} 
+0

你能舉一個更完整的例子嗎?因爲這不能正常工作。 – JavaCake 2012-03-14 13:13:38

+0

這是一個完整的例子。正如我在評論中所說的,唯一需要做的就是將日誌乘以一個常量,例如, '_camera.z + = someConstant * log(gesture.scale);'someConstant是某個數字。 – yuji 2012-03-14 17:54:10

+0

我明白這一點,但捏入和捏出時不會發生如此平滑,並且它不會始終對倒扣發生反應。手勢狀態有問題嗎? – JavaCake 2012-03-14 18:37:40