I need to rotate an object to have an exact rotation relative to real world. Therefore calling Input.gyro.attitude returns a Quaternion representing the position of the device. On the other hand, this forces me to compute every rotation based upon this quaternion as default rotation.
An easy way to set some object facing upwards would be the following:
Vector3 up = Input.gyro.attitude.eulerAngles;
...
transform.rotation = Quaternion.Euler(up.x, up.y, up.z);
This rotates up.z around z, then up.x around x, and up.y around y.
My problem is, that the coordinate system is not quite right, in my app the y and z axis swapped (I'm using Vuforia, so it's always relative to the marker), meaning that an rotation around z results in a rotation around y and the other way around. Here things get difficult: Obviously
transform.rotation = Quaternion.Euler(up.x, up.z, up.y);
fails, since this still rotates first around z, but now with up.y. The correct order would be to create a rotation, that rotates first around y, then x, then z.
Since the Euler Angles are retrieved from a Quaternion,
transform.rotation = Quaternion.identity;
transform.Rotate(0, up.eulerAngles.z, 0);
transform.Rotate(up.eulerAngles.x, 0, 0);
transform.Rotate(0, 0, up.eulerAngles.y);
won't work either, of course.
However, I can't find a way to do this. Am I overlooking something?