I am trying to convert the orientation of an OpenVR controller that I have stored as `glm::vec3`

Euler angles in a `glm::fquat`

and back, but I get extremely different results and the behavior in the game is just wrong *(difficult to explain, but the orientation of the object behaves normally for a small range of angles, then switches in strange axes)*.

Here is my conversion code:

```
// get `orientation` from OpenVR controller sensor data
const glm::vec3 eulerAnglesInDegrees{orientation(PITCH), orientation(YAW), orientation(ROLL)};
debugPrint(eulerAnglesInDegrees);
const glm::fquat quaternion{glm::radians(eulerAnglesInDegrees)};
const glm::vec3 result{glm::degrees(glm::eulerAngles(quaternion))};
debugPrint(result);
// `result` should represent the same orientation as `eulerAnglesInDegrees`
```

I would expect `eulerAnglesInDegrees`

and `result`

be either the same representations, or equivalent representations of the same orientation, but this is apparently not the case. Here are some examples of values I get printed:

```
39.3851 5.17816 3.29104
39.3851 5.17816 3.29104
32.7636 144.849 44.3845
-147.236 35.1512 -135.616
39.3851 5.17816 3.29104
39.3851 5.17816 3.29104
32.0103 137.415 45.1592
-147.99 42.5846 -134.841
```

As you can see above, for some orientation ranges, the conversion is correct, but for others it is completely different.

**What am i doing wrong?**

I looked at the existing questions and tried a few things, including trying all of the possible rotation orders listed here, conjugating the quaternion and other random things like reversing the pitch / yaw / roll. Nothing has given me the expected result.

**How can I convert euler angles to quaternions and back, representing the original orientation, using **`glm`

?

Some other examples of discrepancies:

```
original: 4; 175; 26;
computed: -175; 4; -153;
difference: 179; 171; 179;
original: -6; 173; 32;
computed: 173; 6; -147;
difference: -179; 167; 179;
original: 9; 268; -46;
computed: -170; -88; 133;
difference: 179; 356; -179;
original: -27; -73; 266;
computed: -27; -73; -93;
difference: 0; 0; 359;
original: -33; 111; 205;
computed: 146; 68; 25;
difference: -179; 43; 180;
```

I tried to find a pattern to fix the finale `computed`

results, but there does not seem to be an easy one to identify.

GIF + behavior video:

Visual representation of my current intuition / understanding:

- The image above shows a sphere, and I'm in the center. When I point the gun towards the green half of the sphere, the orientation is correct. When I aim the gun at the red half of the sphere, it's incorrect – it seems like every axis is reversed, but I'm not 100% sure that it is.