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

Optimized version of gb_quat_euler_angles #48

Open
dc1248 opened this issue Oct 20, 2022 · 0 comments
Open

Optimized version of gb_quat_euler_angles #48

dc1248 opened this issue Oct 20, 2022 · 0 comments

Comments

@dc1248
Copy link

dc1248 commented Oct 20, 2022

Noticed you had a TODO for this and I needed a slight variation of it anyway. Not well tested, but my variant seems to work.

gbQuat gb_quat_euler_angles(float pitch, float yaw, float roll) {
	gbQuat q, p, y, r;

	p.x = gb_sin(0.5f*pitch), p.y = 0, p.z = 0, p.w = gb_cos(0.5f*pitch);
	y.x = 0, y.y = gb_sin(0.5f*yaw), y.z = 0, y.w = gb_cos(0.5f*yaw);
	r.x = 0, r.y = 0, r.z = gb_sin(0.5f*roll), r.w = gb_cos(0.5f*roll);

	q.x =   y.w * p.x;
	q.y =   y.y * p.w;
	q.z = - y.y * p.x;
	q.w =   y.w * p.w;

	q.x =   q.x * r.w + q.y * r.z;
	q.y = - q.x * r.z + q.y * r.w;
	q.z =   q.w * r.z + q.z * r.w;
	q.w =   q.w * r.w - q.z * r.z;

	return q;
}
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