我希望我的相机围绕一个物体自动旋转,并且只在某些时刻改变它的方向。我看到了一些解决方案,但它们都带有手势识别器......我怎样才能让它以恒定的速度旋转并改变它的方向?
这是我的代码:
class GameViewController: UIViewController {
var gameView:SCNView!
var gameScene:SCNScene!
var cameraNode:SCNNode!
var camera:SCNCamera!
var cameraOrbit:SCNNode!
override func viewDidLoad() {
super.viewDidLoad()
initView()
initScene()
initCamera()
}
func initView() {
gameView = self.view as! SCNView
gameView.allowsCameraControl = false
gameView.autoenablesDefaultLighting = true
}
func initScene() {
gameScene = SCNScene()
gameView.scene = gameScene
gameView.isPlaying = true
}
func initCamera() {
camera.usesOrthographicProjection = true
camera.orthographicScale = 9
camera.zNear = 1
camera.zFar = 100
cameraNode = SCNNode()
cameraNode.camera = camera
cameraNode.position = SCNVector3(x: 0, y: 5, z: 20)
gameScene.rootNode.addChildNode(cameraNode)
cameraOrbit.addChildNode(cameraNode)
cameraOrbit.eulerAngles.y = Float(M_PI)
cameraOrbit.eulerAngles.x = Float(2*M_PI)
gameScene.rootNode.addChildNode(cameraOrbit)
}