Solved Rotation(yaw,pitch) to Quaternion for TextDisplay

Erfinderlabyrinth

New member
Mar 9, 2024
2
1
0
1
Hi,

I want to create a Textdisplay where the Text shown in a specific direction(yaw,pitch)(z.B. 45,45).
How can I easily transform this to a Quaternion? Had Paper a Library or a method, which can it translated?

I had seen, that I can use a AxisAngle4f, but i dont understand what this do.
 
Version Output
This server is running Paper version git-Paper-389 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: 848a396)
You are 59 version(s) behind
Download the new version at: https://papermc.io/downloads/paper
Solution
Asking the AI, I got following code:


Java:
public static Quaternionf yawPitchToQuaternion(float yaw, float pitch) {
        // Convert yaw and pitch to radians
        double yawRad = Math.toRadians(yaw);
        double pitchRad = Math.toRadians(pitch);

        // Create a new Quaternionf object
        Quaternionf quaternion = new Quaternionf();

        // Set the quaternion using yaw and pitch
        quaternion.rotationYXZ(yawRad, pitchRad, 0.0f);

        // Return the quaternion
        return quaternion;
    }

and this work

Erfinderlabyrinth

New member
Mar 9, 2024
2
1
0
1
Asking the AI, I got following code:


Java:
public static Quaternionf yawPitchToQuaternion(float yaw, float pitch) {
        // Convert yaw and pitch to radians
        double yawRad = Math.toRadians(yaw);
        double pitchRad = Math.toRadians(pitch);

        // Create a new Quaternionf object
        Quaternionf quaternion = new Quaternionf();

        // Set the quaternion using yaw and pitch
        quaternion.rotationYXZ(yawRad, pitchRad, 0.0f);

        // Return the quaternion
        return quaternion;
    }

and this work
 
Solution