我使用以下行旋转SCNNode:
let rotate = SCNAction.rotateByAngle(CGFloat(M_PI), aroundAxis:SCNVector3Make(0, 1, 0), duration: NSTimeInterval(10.0))
let repeat = SCNAction.repeatActionForever(rotate)
node.runAction(repeat)
然后我在render方法中打印节点的eulerAngles.y:
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)")
但是我在旋转期间会得到奇怪的值,如下所示:
...
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
...
我不明白为什么要打印270。你能用其他方式解释我吗? 获得节点的正确角度?
答案 0 :(得分:4)
这就是欧拉角度的工作方式。他们有两个怪癖(我将x
,y
和z
分别称为pitch
,yaw
和roll
:
roll
和yaw
随着逆时针旋转从0增加到π(180度),然后跳转到-π(-180度)并随着旋转完成继续增加到0一个圆圈;但pitch
增加到π/ 2(90度)然后减小到0,然后减少到-π/ 2(-90度)并增加到0.
值在某些方向上变得不准确。特别是,当pitch
为±90度时,roll
和yaw
变得不稳定。请参阅wikipedia article on gimbal lock。