SceneKit node camera resets pinch gesture

I try to scale the pinch gesture, but every time I clamp it a second time, the model resets itself.

func zoom(scale: Double){

    self.cameraNode.camera!.xFov = scale
    self.cameraNode.camera!.yFov = scale

}

func handlePinch(gestureRecognize: UIPinchGestureRecognizer) {

    if gestureRecognize.numberOfTouches() == 2 {

                let zoom = gestureRecognize.scale
                if (gestureRecognize.state == UIGestureRecognizerState.Began){
                    startScale = lastScale
                    bimScene.zoom(startScale)
                }
                if (gestureRecognize.state == UIGestureRecognizerState.Changed){
                    startScale = Double(100/zoom)
                    bimScene.zoom(startScale)
                }
                if (gestureRecognize.state == UIGestureRecognizerState.Ended){
                    lastScale = startScale
                }

    }
}

I'm still new to scenekit, so I find this weird. Can anyone explain the reason for this?

+4
source share
2 answers

You are close, the logic is not working a bit.

The initial case is good, you need to “remember” the scale at which the pinch was started, and this is probably the scale that was set the last time you zoomed in.

There are two problems in your changed case.

  • , startScale = Double(100/zoom), , (, ). GR, "" .
  • reset startScale . ""; .

, , . , startScale = startScale * zoom .

, , , . , zoom, , , . FOV 30-60 , 0,1 - 10 ( ).

func handlePinch(gestureRecognize: UIPinchGestureRecognizer) {

    if gestureRecognize.numberOfTouches() == 2 {

        let zoom = gestureRecognize.scale
        if (gestureRecognize.state == UIGestureRecognizerState.Began){
            startScale = lastScale
        } else if (gestureRecognize.state == UIGestureRecognizerState.Changed){
            let fov = Double(100/(startScale * zoom))
            bimScene.zoom(fov)
        } else {
            lastScale = startScale * zoom
        }
    }
}
+4

ZOOM- node, .

-(void)handlePinch:(UIPinchGestureRecognizer*)gestureRecognizer {
    if (gestureRecognizer.numberOfTouches == 2) {
        CGFloat zoom = gestureRecognizer.scale;
        if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
            lastScale = yourNode.scale.x;
        } else if (gestureRecognizer.state == UIGestureRecognizerStateChanged) {
            double final = lastScale * zoom;
            yourNode.scale = SCNVector3Make(final, final, final);
        }
    }
}
0

Source: https://habr.com/ru/post/1649214/


All Articles