6 hours ago, congard said:There was a problem with this. In a free camera, if I rotate it around the Y-axis (as it would if I changed the yaw of the FPS camera), the rotation around the Y-axis will not change... The pitch and roll will change. Here is the result of rotating the camera by ~180 degrees around the Y-axis:
3.05986, -0.109744, 3.07922 (in degrees ~175.3, ~-6.3, ~176.4)
I got these values using glm::eulerAngles.
I assume what you're talking about here is trying to compute a reasonable initial set of Euler angles when the vehicle transitions from 'flying' mode to 'ground' mode. (If that's not what you're talking about, my answer probably won't make much sense.)
I don't think converting the 'flying' quaternion to Euler angles is what you want to do. Among other things, Euler angles are subject to aliasing, meaning multiple triples can represent the same orientation. The angles in your example are close to (180, 0, 180). If I'm not mistaken, this is actually the same orientation as (0, 180, 0), assuming e.g. XYZ order, which is what you were expecting. So I think your result is correct and as expected, but just looks wrong to you because of aliasing.
In any case, I don't think an Euler-angle conversion of this sort is what you want, because the two control schemes are fundamentally different, and an Euler-angle set computed from the 'flying' quaternion at the point of landing won't necessarily make sense as an initial Euler-angle set for the ground-based control system. More abstractly, the problem is that the last flying orientation may not make sense as an initial orientation for the ground-based control system (for example, if the vehicle lands upside down, you don't want to start out upside down in 'ground' mode).
Here is what I would try:
- Always start in ground mode with pitch and roll set to zero, and an appropriate yaw. This means you only have one angle to compute.
- Compute the yaw angle as follows. On landing, project the local forward vector of the vehicle onto the ground plane, and use atan2() to compute the yaw from it. If the magnitude of the projected vector is small (which it may be if the vehicle lands nose- or tail-first), use the local up vector instead.
I think that will give you a 'sensible' initial orientation for ground mode. Again, this is a fairly crude approach, and I'm working with limited information (for example, I don't know if the ground is flat or if there's terrain or other irregularities). But, this would be my starting point.