mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 07:37:43 +00:00
Implement Quaternions (#2311)
* Implement Quaternions * Update BaseRoute.java --------- Co-authored-by: Magix <27646710+KingRainbow44@users.noreply.github.com>
This commit is contained in:
parent
fc7de04f73
commit
92e4f9057a
@ -63,7 +63,25 @@ public abstract class BaseRoute {
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user