ScenKit eulerAngles strange values during rotation

↘锁芯ラ 提交于 2020-01-14 10:22:54

问题


I'm rotating a SCNNode using the following lines:

 let rotate = SCNAction.rotateByAngle(CGFloat(M_PI), aroundAxis:SCNVector3Make(0, 1, 0), duration: NSTimeInterval(10.0))
    let repeat = SCNAction.repeatActionForever(rotate)
    node.runAction(repeat)

and i print the eulerAngles.y of the node in the render method:

let rad = Double(node.eulerAngles.y)        
var angleInDegrees = fmodf(360.0 + -Float(rad) * (180.0 / Float(M_PI)), 360.0)
println("eulerAngles.y rad:\(rad) degree:\(angleInDegrees)")

but I get strange values during rotation like the following:

...
eulerAngles.y rad:-1.38788688182831 degree:79.5201
eulerAngles.y rad:-1.40567290782928 degree:80.5391 
eulerAngles.y rad:-1.4227991104126 degree:81.5204
eulerAngles.y rad:-1.44030773639679 degree:82.5236
eulerAngles.y rad:-1.45790004730225 degree:83.5315
eulerAngles.y rad:-1.47438871860504 degree:84.4763
eulerAngles.y rad:-1.49130213260651 degree:85.4453
eulerAngles.y rad:1.57079637050629 degree:270.0
eulerAngles.y rad:1.57079637050629 degree:270.0
eulerAngles.y rad:1.57079637050629 degree:270.0
eulerAngles.y rad:1.57079637050629 degree:270.0
eulerAngles.y rad:1.57079637050629 degree:270.0
eulerAngles.y rad:1.57079637050629 degree:270.0
eulerAngles.y rad:1.57079637050629 degree:270.0
eulerAngles.y rad:1.57079637050629 degree:270.0
eulerAngles.y rad:-1.49359321594238 degree:85.5766
eulerAngles.y rad:-1.47716772556305 degree:84.6355
...

I don't understant why 270 is printed. Can you explain me or there another way to get the correct angle of the node?


回答1:


That's how Euler angles work. They have two quirks (I'll refer to x, y, and z as pitch, yaw, and roll respectively):

  • roll and yaw increase with counterclockwise rotation from 0 to π (180 degrees) and then jump to -π (-180 degrees) and continue to increase to 0 as the rotation completes a circle; but pitch increases to π/2 (90 degrees) and then decreases to 0, then decreases to -π/2 (-90 degrees) and increases to 0.

  • Values become inaccurate in certain orientations. In particular, when pitch is ±90 degrees, roll and yaw become erratic. See the wikipedia article on gimbal lock.



来源:https://stackoverflow.com/questions/32126632/scenkit-eulerangles-strange-values-during-rotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!