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

Implement Quaternions #2311

Merged
merged 2 commits into from
Aug 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,25 @@ public boolean stopRoute(Scene scene) {
private MathQuaternion.Builder rotAsMathQuaternion() {
val result = MathQuaternion.newBuilder();
if (startRot != null) {
result.setX(startRot.getX()).setY(startRot.getY()).setZ(startRot.getZ());
// https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
// "MY BRAIN!" - Nazrin
val roll = Math.toRadians(startRot.getX());
val pitch = Math.toRadians(startRot.getY());
val yaw = Math.toRadians(startRot.getZ());

val cr = (float)Math.cos(roll * 0.5);
val sr = (float)Math.sin(roll * 0.5);
val cp = (float)Math.cos(pitch * 0.5);
val sp = (float)Math.sin(pitch * 0.5);
val cy = (float)Math.cos(yaw * 0.5);
val sy = (float)Math.sin(yaw * 0.5);

result.setW(cr * cp * cy + sr * sp * sy);
result.setX(sr * cp * cy - cr * sp * sy);
result.setY(cr * sp * cy + sr * cp * sy);
result.setZ(cr * cp * sy - sr * sp * cy);
} else {
result.setW(1f);
}
return result;
}
Expand Down
Loading