我有一个关于在SceneKit中使用平移手势上下左右移动相机而不旋转的问题。我已经找到了很多关于旋转相机的讨论,这些讨论对我的旋转非常有用。但是我无法弄清楚如何在不旋转相机的情况下移动相机。我正在尝试模仿allowsCameraControl,用户可以用两个手指平移来改变相机的x和y位置。这是我的平移手势识别器的代码,任何帮助将不胜感激,谢谢!
func handlePan(gestureRecognize: UIPanGestureRecognizer) {
let numberOfTouches = gestureRecognize.numberOfTouches
var translation = gestureRecognize.translation(in: gestureRecognize.view!)
var widthRatio = Float(translation.x) / Float(gestureRecognize.view!.frame.size.width) + lastWidthRatio
var heightRatio = Float(translation.y) / Float(gestureRecognize.view!.frame.size.height) + lastHeightRatio
if (numberOfTouches==fingersNeededToPan) {
self.cameraOrbit.eulerAngles.y = Float(-2 * M_PI) * widthRatio
self.cameraOrbit.eulerAngles.x = Float(-M_PI) * heightRatio
//for final check on fingers number
lastFingersNumber = fingersNeededToPan
}
if numberOfTouches == 2 {
self.cameraNode.position.x = -(Float(translation.x) / Float(gestureRecognize.view!.frame.size.width) + lastWidthRatio)
self.cameraNode.position.y = -(Float(translation.y) / Float(gestureRecognize.view!.frame.size.height) + lastHeightRatio)
}
lastFingersNumber = (numberOfTouches>0 ? numberOfTouches : lastFingersNumber)
if (gestureRecognize.state == .ended && lastFingersNumber==fingersNeededToPan) {
lastWidthRatio = widthRatio
lastHeightRatio = heightRatio
}
}