-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Hi Gabor! First I wanted to say that I loved your book. Thank you for sharing your knowledge on the topic of animation!
And second I wanted to point out some small bugs related to the quaternion class:
- The first one is in the
operator==function:
bool operator==(const quat& left, const quat& right) {
return (fabsf(left.x - right.x) <= QUAT_EPSILON && fabsf(left.y - right.y) <= QUAT_EPSILON && fabsf(left.z - right.z) <= QUAT_EPSILON && fabsf(left.w - left.w) <= QUAT_EPSILON);
}
Notice how the comparison of the scalar values uses this fabsf(left.w - left.w) instead of this fabsf(left.w - right.w)
- The second one is in the
sameOrientationfunction:
bool sameOrientation(const quat& left, const quat& right) {
return (fabsf(left.x - right.x) <= QUAT_EPSILON && fabsf(left.y - right.y) <= QUAT_EPSILON && fabsf(left.z - right.z) <= QUAT_EPSILON && fabsf(left.w - left.w) <= QUAT_EPSILON)
|| (fabsf(left.x + right.x) <= QUAT_EPSILON && fabsf(left.y + right.y) <= QUAT_EPSILON && fabsf(left.z + right.z) <= QUAT_EPSILON && fabsf(left.w + left.w) <= QUAT_EPSILON);
}
Notice how the comparison of the scalar values uses this fabsf(left.w - left.w) instead of this fabsf(left.w - right.w) and it also uses this fabsf(left.w + left.w) instead of this fabsf(left.w + right.w)
- The last one is in the
slerpfunction:
quat slerp(const quat& start, const quat& end, float t) {
if (fabsf(dot(start, end)) > 1.0f - QUAT_EPSILON) {
return nlerp(start, end, t);
}
return normalized(((inverse(start) * end) ^ t) * start);
}
I believe the return value should be this: return normalized(start * ((inverse(start) * end) ^ t));
Notice how I multiply start from the left instead of from the right. That's necessary because of the way the quaternion product function is implemented.
Again, thank you for this book! π