The goal is to simulate a camera in SceneKit and let users pan the camera's point of view by panning the screen.
The code below simulates the camera panning in the horizontal direction, but how would you account for simultaneous panning in the vertical direction?
Would you just concat another rotation, but altering the X-axis and based on translation.y (to get amount user panned vertically)? Or is there a better way?
func doPan(sender: UIPanGestureRecognizer) {
// Get horizonal pan distance & convert to radians
let translation = sender.translationInView(sender.view!)
var xRadians = GLKMathDegreesToRadians(Float(translation.x))
// Rotate camera
xRadians = (xRadians / 20) + currentAngle
cameraNode.transform = SCNMatrix4MakeRotation(xRadians, 0, 1, 0)
// Update preview block
setPreviewBlock(cameraNode.position)
// Save value for next rotation
if (sender.state == UIGestureRecognizerState.Ended) {
currentAngle = xRadians
}
}