JoeyDeVries / Cell

OpenGL C++ Graphics Engine
Other
887 stars 125 forks source link

Logical Error in Calculating Quaternion to axis angle. #11

Open surajsubudhi10 opened 6 years ago

surajsubudhi10 commented 6 years ago

In quaternion.h

inline vec4 quaternion::ToAxisAngle()
    {
        vec4 result;

        const float angle  = 2.0f * acos(w);
        const float length = sqrt(1.0f - angle*angle);

        result.xyz = vec3(x, y, z) / length;
        result.w   = angle;

        return result;
}

At the time calculating length it should be length = sqrt(1.0f - w*w); . And we should also check for length != 0. As per your previous code we can get angle greater than 1 so at that time the length will be undefined.