我有一個關於在沒有在SceneKit中旋轉的情況下向上/向下和向左/向右移動攝像頭的問題。我發現了很多關於旋轉相機的討論,我正在使用它來旋轉。但我不知道如何移動相機而不旋轉它。我試圖模仿,允許攝像頭控制,用戶可以用兩根手指平移以改變攝像頭的x和y位置。這裏是我的平底手勢識別器的代碼,任何幫助將不勝感激,謝謝!在Scenekit中移動攝像機
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
}
}
澄清:你是否想橫向移動,而不改變攝像機角度?例如。我面向東北方向,在向東北方向繼續前進的同時,向左側(西北向左側,東南向右側)行進? –
是的,我只是試圖移動相機左/右或上/下旋轉,就像是可能withCameraControl,抱歉的混亂@HalMueller –