McNopper / GLUS

GLUS for OpenGL, OpenGL ES and OpenVG
http://nopper.tv
170 stars 54 forks source link

quaternion missing a few features #7

Open ratchetfreak opened 7 years ago

ratchetfreak commented 7 years ago

nlerp, it is less accurate but is much faster, only needing a single sqrt instead of 4 transcendal trig functions. (FYI you can get the slerp using a half dozen nlerps by binary searching into the range using slerp(q1, q2, 0.5) == nlerp(q1, q2, 0.5))

slerp should fall back to nlerp when cosAlpha > 0.95 to avoid instability. The error between nlerp and slerp will decrease as cosAlpha goes to 1.

Getting a quaternion representing the rotation between 2 vectors can be calculated using the cross and dot product directly instead of having to go through glusQuaternionRotatef.

   //assumes v0 and v1 were normalized
    GLUSfloat cross[3];
    glusVector3Crossf(cross, v0, v1);
    result[0] = cross[0];
    result[1] = cross[1];
    result[2] = cross[2];
    result[3] = dotf(v0, v1)+1; 

    glusQuaternionNormalizef(result);
McNopper commented 7 years ago

Will have a look at it, Will take some time, as quite busy right now. Thx for the feedback.

McNopper commented 7 years ago

Okay, makes sense. Will add lerp, nlerp and the fallback for slerp.