quat quat_slerp(const quat *q1, const quat *q2, float t) { float cos_theta = quat_dot(q1, q2); float theta = acos(cos_theta); float sin_theta = sin(theta); if (sin_theta > 0.001f) { float w1 = sin( (1.f-t) * theta) / sin_theta; float w2 = sin(t * theta) / sin_theta; quat q3, q4; q3 = quat_scale(q1, w1); q4 = quat_scale(q2, w2); return quat_add(&q3, &q4); } else { return quat_lerp(q1, q2, t); } }
union quat *quat_nlerp(union quat *qo, const union quat *qfrom, const union quat *qto, float t) { quat_lerp(qo, qfrom, qto, t); quat_normalize_self(qo); return qo; }