Why clone Android sensor values before using ROTATION_VECTOR sensor?
-
09-02-2021 - |
Question
I've noticed that in several tutorials for using the rotation vector sensor, the mag and accel values are cloned prior to using them in getRotationMatrix.
For example, the code in the question here: Using getRotationMatrix and getOrientation in Android 2.1
However, getRotationMatrix doesn't change the mag and accel vectors. Therefore what is the point of cloning them? Thanks
Solution
I think they make that because onSensorChange can change their values (it uses the same variables), so they copy the values first.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow