Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid compass rotateanimation
    primarykey
    data
    text
    <p>I'm making a compass that points to a user defined location. I'm using the rotateanimation to rotate the needle. When the needle points in the direction of the phone I know the phone is pointing in the direction I want. However, I wanted the needle to point in the correct direction irregardless of the phone's azimuth.</p> <p>The problem is that it seems that rotateanimation does not rotate the needle according to the real world coordinates, and instead is relative to the phone's screen. So a 58 degree rotation of the needle does not match a 58 degree rotation in the real world. Is this true or am I making a mistake in my code?</p> <p>The compass is meant to be used by placing the phone's back flat on a surface. I've also tried outputting the azimuth and it reads like this:</p> <pre><code>Azimuth Actual Phone angle 0 0 45 90 90 180 </code></pre> <p>when it gets close to a full circle back it bounces between 120 and 340.</p> <p>Here's the code:</p> <pre><code>direction = 360 - azimuth + rotate; RotateAnimation animate = new RotateAnimation(rotateLast, direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animate.setFillAfter(true); animate.setInterpolator(new LinearInterpolator()); animate.setDuration(10); needle.startAnimation(animate); rotateLast = direction; </code></pre> <p>azimuth is the phone's azimuth from the sensor, rotate is the user specified direction (in degrees from north), and direction is the required rotation of the needle.</p> <p>rotateLast is the last position the needle was at, I'm using this because without it the needle reverts to zero degrees and flickers.</p> <p>Thanks, P.S. this has been driving me crazy</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload