You can definitely use a combination of an accelerometer and a gyroscope to detect device rotation ("Gravity" is an alloy of the two where the gyroscope is used to provide smoother and faster response times).
From my own tests, the Vector Rotation Vector affects the magnetic field data (perhaps indirectly by eliminating the bias of the gyroscopes), so you probably should find a different solution (my test tracked the rotation in the car compared to a simple walk around, it turns out the magnetic field the car interfered with the rotation - I made a video comparing the data of the vector rotation of the game, simply integrating the gyroscopic output here ).
If you go without magnetic field data, you will always have a drift (slow increase in rotation error in the horizontal plane). The main part of what you need to do is integrate the gyro data over time (see Googleโs own code for using gyro data to track rotation here ).
To prevent vertical drift, you need to use an accelerometer to track where gravity is relative to your device and combine this with gyro data. Usually the suggested way to do this is to use Kalman Filter , but depending on your application it can be unnecessarily complicated, so I would suggest using what is called an additional filter, which can be described as merging data with a low-pass filter, noisy but stable a signal (accelerometer) and a high-frequency filler on a sensitive but drifting signal (gyroscope). A great resource on kalman and additional filters can be found here .
source share