Godot Version
4.2.1.stable.mono
Question
Sorry about the click-bait, I know there are many many reasons why Quaternions and Bases are better than using Euler-Angles. Anyone on a 5 second google search could easily know why!
But I am trying my hardest to use Quaternions, and most the time I love them! They are a dream! But in specific instances like I am having now, I keep wondering “Are there times I can use Euler-Angles over Quaternions?”.
I set up the logic for the rotation of a compass in the UI two ways. One way with Euler-Angles that took just a second and is short, and the other way with Quaternions that took me a while longer to set-up because I kept having problems with the discontinuity of interpolation angles. And so the compass would jump from 160
to -160
instead of going from 160 -> 180 -> -160
(the interpolation was taking the long way around).
I would like you to take a look at the code, and tell me if this would be a time that using semi-Euler’s is better than Quaternions, or if the way I set up my Quaternion rotations is in-efficient or needlessly complex! I am really trying my hardest to use Quaternions and Bases for everything because I see their benefits!
P.S.: I still get the jumping between 160
and -160
degrees.
EULER-ANGLES:
float compassAngle = Vector3.Forward.SignedAngleTo(playerCamera.GlobalTransform.Basis.X, Vector3.Up);
compassInst.Rotation = new Vector3(0, compassAngle, 0);
QUATERNIONS/BASES:
Quaternion forwardRot = new Quaternion(Vector3.Forward, 0.0f).Normalized();
Quaternion playerCamRot = playerCamera.GlobalTransform.Basis.GetRotationQuaternion().Normalized();
if(playerCamRot.Dot(forwardRot) < 0){
forwardRot = -forwardRot;
}
Quaternion targertRotComp = playerCamRot.Slerp(forwardRot, 0.1f);
compassInst.GlobalTransform = new Transform3D(new Basis (targertRotComp), compassInst.GlobalTransform.Origin);