clamp sin value to -1, 1

This commit is contained in:
yangxiao 2015-07-29 10:35:01 +08:00
parent 484d763a8d
commit 5d677d49bb
1 changed files with 3 additions and 1 deletions

View File

@ -402,7 +402,9 @@ void Node::updateRotation3D()
//convert quaternion to Euler angle
float x = _rotationQuat.x, y = _rotationQuat.y, z = _rotationQuat.z, w = _rotationQuat.w;
_rotationX = atan2f(2.f * (w * x + y * z), 1.f - 2.f * (x * x + y * y));
_rotationY = asinf(2.f * (w * y - z * x));
float sy = 2.f * (w * y - z * x);
sy = clampf(sy, -1, 1);
_rotationY = asinf(sy);
_rotationZ_X = atan2f(2.f * (w * z + x * y), 1.f - 2.f * (y * y + z * z));
_rotationX = CC_RADIANS_TO_DEGREES(_rotationX);