Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small bugs related to the quaternion class #1

Open
diegomacario opened this issue Oct 14, 2020 · 0 comments
Open

Small bugs related to the quaternion class #1

diegomacario opened this issue Oct 14, 2020 · 0 comments

Comments

@diegomacario
Copy link

diegomacario commented Oct 14, 2020

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! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant