-
-
Save aqubi/80be3c269afb3bf9c8ca to your computer and use it in GitHub Desktop.
SceneKit Tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func pinchWithGestureRecognizer(recognizer:UIPinchGestureRecognizer) { | |
if lockCamera { return } | |
SCNTransaction.begin() | |
SCNTransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)) | |
var fov = defaultFov | |
var constraintFactor:CGFloat = 0 | |
if (recognizer.state == UIGestureRecognizerState.Ended || recognizer.state == UIGestureRecognizerState.Cancelled) { | |
SCNTransaction.setAnimationDuration(0.5) | |
} else { | |
SCNTransaction.setAnimationDuration(0.1) | |
var scale:Float = Float(recognizer.scale) | |
if scale < 0.4 { scale = 0.4 } | |
scale = 1.0 + (Float(scale - 1) * 0.75) | |
let zoom = 1.0 / scale | |
fov *= Double(zoom) | |
constraintFactor = min(1,(CGFloat(scale) - 1) * 0.75) | |
} | |
self.pointOfView!.camera!.xFov = fov | |
if let constraints = self.pointOfView!.constraints { | |
constraints[0].influenceFactor = constraintFactor | |
} | |
SCNTransaction.commit() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment