奇怪的Scenekit相机旋转和平移

时间:2018-11-25 11:40:54

标签: 3d rotation scenekit

我正在尝试使用“视点”节点在两个相机位置之间进行动画处理。

我希望动画模仿我单击并拖动轨道弧球摄像机控制器时得到的动画,这在大多数情况下是一条非常短的路线。

正如您在下面的电影中看到的那样,动画看起来很奇怪。绕道而行。有时不在视口中。

是否有万向节锁定情况?无论我使用的是rotationeulerAngles还是只是设置转换,都得到相同的结果。您可以在下面的代码中看到我的各种尝试已被注释掉

enter image description here

这是完整的代码:

import Cocoa
import SceneKit
class ViewController: NSViewController {

@IBOutlet weak var scnView: SCNView!
@IBOutlet weak var button: NSButton!

var secondaryPov : SCNNode!

var phoneNode : SCNNode!

var destination : SCNNode!

override func viewDidLoad() {
    super.viewDidLoad()

    guard let scn = SCNScene(named: "TestScene.scnassets/TestScene.scn") else {
        print("couldnt load the scene")
        fatalError()
    }

    scnView.scene = scn

    phoneNode = scn.rootNode.childNode(withName: "box", recursively: true)

    scnView.allowsCameraControl = true
    scnView.defaultCameraController.interactionMode = .orbitArcball

    print(scnView.pointOfView)
}

@IBAction func button(_ sender: Any) {
    print("bushed")
    print("point of view is now ")
    print(scnView.pointOfView)

    destination = SCNNode()
    destination.position = scnView.pointOfView!.position
    destination.rotation = scnView.pointOfView!.rotation

}

@IBAction func play(_ sender: Any) {
    let pov = scnView.pointOfView!

    SCNTransaction.begin()
    SCNTransaction.animationDuration = 3
    pov.transform = destination.transform
    SCNTransaction.commit()


    // A few other things I've tried


    // Also tried this. Rotation still weird, and I don't want to lock the object in the middle
    //        let lookAt = SCNLookAtConstraint(target: phoneNode)
    //        lookAt.isGimbalLockEnabled = false
    //        pov.constraints = [lookAt]


    //  This seems to produce the same results
    //        let rotationAction = SCNAction.rotateTo(x: destination.eulerAngles.x, y: destination.eulerAngles.y, z: destination.eulerAngles.z,  duration: 1, usesShortestUnitArc: true)
    //        let positionAction = SCNAction.move(to: destination.position, duration: 1)
    //        let group = SCNAction.group([rotationAction, positionAction])
    //        pov.runAction(group)



    // Same weird rotation
    //        SCNTransaction.begin()
    //        pov.pivot = phoneNode.pivot
    //        SCNTransaction.animationDuration = 3
    //        pov.position = destination.position
    //        pov.rotation = destination.rotation
    //        SCNTransaction.commit()


}

}

0 个答案:

没有答案
相关问题