- Home /
Fixing rotation using Compass
I think I've been stuck on this for months now.
What I'm trying to do is fix the camera rotation in Augmented Reality using the Compass.
The camera has full freedom of rotation on all axis. This rotation is controlled by ARCore. What I want is for the device to read the value stored in the Compass and fix this rotation based on what the compass is indicating. I cannot directly control the ARCamera and therefore I am instead rotating its parent (strictly on the Y axis) to achieve this.
So if, for example, my camera Eular angle is (25,-25,0) It is pointing a little bit counter-clockwise. If the compass is indicating 0 (North), that means I need to fix the parent of my camera clockwise for the correct rotation. My latest "attempt" at solving this problem goes like this:
Vector3 right = cam.right;
compassT.rotation = Quaternion.Euler(new Vector3(0, compass, 0));
Vector3 east = compassT.right;
float angle =Vector3.SignedAngle(east, right, Vector3.up);
camParent.rotation *= Quaternion.Euler(new Vector3(0, -angle, 0));
This ALMOST works, until the camera rotates on the z axis which creates some strange shaking behaviour, which I am assuming is Gimble Lock.
Was anyone ever able to solve this issue? Please assist
Your answer
Follow this Question
Related Questions
Get real compass direction 1 Answer
Rotate object in specific direction 1 Answer
How can I rotate at a constant speed to look at a point? 2 Answers
how to combine 2 quaternion components? 2 Answers
Change the roll of the rotation 0 Answers