Skip to content

Optimized version of gb_quat_euler_angles #48

@dc1248

Description

@dc1248

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

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