Skip to content

Small bugs related to the quaternion classΒ #1

@diegomacario

Description

@diegomacario

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 sameOrientation function:
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 slerp function:
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! πŸ˜ƒ

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions