简体   繁体   中英

Scenekit - multiple rotation of SCNNode and direction of axes

I have a SCNNode which i keep on rotating with pan gesture by 90deg increments. The first few rotations are working as intended, by with a scenario where the nodes axes rotate in the oposite direction, the rotation is executed in wrong direction. How can i determine the orientation of the axes after each rotation?

Scenario (using a cube for simplicity):

  • i rotate the cube 90deg along Y axis. Y points still up, X now points to the camera, Z points right
  • i rotate the cube again 90deg along Y. X now points left, Z to the camera
  • PROBLEM - i now try to rotate 90deg along X axis. Because X got rotated 180 degrees, the rotation is now reversed.

How can i understand when to rotate (-1,0,0) and when (1,0,0) ?

I'm quite new to the world of 3D math, i hope i explained my issue correctly.

After further research i realised i chose completely wrong approach. The way to achieve what i want was to rotate the node using the axes of the rootNode - this way i don't need to worry about local axes of my node.

EDIT: updated code based on Xartec's suggestions

let rotation = SCNMatrix4MakeRotation(angle,  x, y, Float(0))
let newTransform = SCNMatrix4Mult(bricksNode.transform, rotation)
let animation = CABasicAnimation(keyPath: "transform")
animation.fromValue = bricksNode.transform
animation.toValue = scnScene.rootNode.convertTransform(newTransform,from: nil)
animation.duration = 0.5
bricksNode.addAnimation(animation, forKey: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM