Weird Scenekit camera rotation and translation
I'm trying to animate between two camera positions using the point of view node.
I want the animation to mimic the animation I get when I click and drag the orbit arc ball camera controller, which is a very short route most of the time.
As you can see in the movie below, the animation looks weird. It takes big detours. Sometimes out of the viewport.
Is it a gimbal lock situation? I get the same results whether I'm using rotation
, eulerAngles
or just set the transform. You can see my various attempts commented out in the code below
Here's the entire code :
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()
}
}
3d rotation scenekit
add a comment |
I'm trying to animate between two camera positions using the point of view node.
I want the animation to mimic the animation I get when I click and drag the orbit arc ball camera controller, which is a very short route most of the time.
As you can see in the movie below, the animation looks weird. It takes big detours. Sometimes out of the viewport.
Is it a gimbal lock situation? I get the same results whether I'm using rotation
, eulerAngles
or just set the transform. You can see my various attempts commented out in the code below
Here's the entire code :
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()
}
}
3d rotation scenekit
add a comment |
I'm trying to animate between two camera positions using the point of view node.
I want the animation to mimic the animation I get when I click and drag the orbit arc ball camera controller, which is a very short route most of the time.
As you can see in the movie below, the animation looks weird. It takes big detours. Sometimes out of the viewport.
Is it a gimbal lock situation? I get the same results whether I'm using rotation
, eulerAngles
or just set the transform. You can see my various attempts commented out in the code below
Here's the entire code :
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()
}
}
3d rotation scenekit
I'm trying to animate between two camera positions using the point of view node.
I want the animation to mimic the animation I get when I click and drag the orbit arc ball camera controller, which is a very short route most of the time.
As you can see in the movie below, the animation looks weird. It takes big detours. Sometimes out of the viewport.
Is it a gimbal lock situation? I get the same results whether I'm using rotation
, eulerAngles
or just set the transform. You can see my various attempts commented out in the code below
Here's the entire code :
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()
}
}
3d rotation scenekit
3d rotation scenekit
edited Nov 25 '18 at 14:15
Morten J
asked Nov 25 '18 at 11:40
Morten JMorten J
362617
362617
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467070%2fweird-scenekit-camera-rotation-and-translation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467070%2fweird-scenekit-camera-rotation-and-translation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown