AR Camera Rotation without gyroscope

Hello,

First, I’m sorry if my english is not very good, I’m french !

The code below come from Heyworks Unity Studio and thanks to the GyroController.unitypackage which helped me a lot with gyroscope.

Summary :

Unity 4.3.4f - C#
Galaxy Tab 2 (model GT-P5110) without gyroscope
Trying to rotate the camera using the compass (and anything else) on the 3 axis or 2 at the minimum (up/down & right/left).

In details :

I’m developper on Unity (in C# currently) and programming an AR application.
So the application is working on the tablet with gyroscope but i have to adapt it for the tablets without gyroscope. On my Galaxy Tab 2 (GT-P5110) there is no gyroscope.

How can I rotate the camera in the 3 axis just with the compass (and any other tool if necessary) ?

I’m trying only with Compass like this :

m_camAR.transform.rotation = Quaternion.Euler(Input.compass.rawVector.y, -Input.compass.rawVector.x, 0);

This code let me turn on the up/down and right/left axis but only until I reach some values. These values are approximatively 316-317° and 43-44°, after that, the camera rotation is very strange, it goes up when i’m going to the left, etc…

I’m not very good at maths…so please forgive me if it’s very simple !
Here is a screenshot when looking to the north, a little bit lower.

[23143-ar_camera_forward[1].png|23143]

As you can see in the box, there is the rotation of camera and the rawVector of the compass.

So I’m searching a method to update that position which could accept the 360° rotation with that rawVector (or anything else) but without using gyroscope.

I read a lot of articles and answers and codes but didn’t find the solution. It is possible because i found an app on the Play Store “3D Compass” which works (but in java).

I’m on Unity 4.3.4f.

Thanks a lot for all answers.

I would suggest using true heading instead of raw vector so you can get a simple compass heading in degrees relative to north point. Something like this:

transform.rotation = Quaternion.Euler(0, -Input.compass.trueHeading, 0);

Nevertheless switching gyro to compass could be somewhat bad idea, because compass is not as precise or fast as gyro. Instead you could try to take advantage of accelerometer (there is a plugin for that as well: Unity Asset Store - The Best Assets for Game Making).