ScenKit Euler在旋转过程中角度奇怪的值 [英] ScenKit eulerAngles strange values during rotation

查看:115
本文介绍了ScenKit Euler在旋转过程中角度奇怪的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下几行来旋转SCNNode:

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)

然后我在render方法中打印节点的eulerAngles.y:

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
...

我不明白为什么要打印270.你能解释一下我还是另一种方式 以获得正确的节点角度?

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

推荐答案

欧拉角就是这样工作的.他们有两个怪癖(我分别将xyz分别称为pitchyawroll):

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

  • rollyaw随着从0到π(180度)的逆时针旋转而增加,然后跳至-π(-180度),并随着旋转完成一个圆而继续增加至0;但是pitch增大到π/2(90度),然后减小到0,然后减小到-π/2(-90度),然后增大到0.

  • 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.

在某些方向上值变得不准确.特别地,当pitch为±90度时,rollyaw变得不稳定.请参阅关于万向节锁的维基百科文章.

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.

这篇关于ScenKit Euler在旋转过程中角度奇怪的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆