0

I am new to android and I am currently implementing a class which extends from surface view class and implements surface holder.

I just want to get the points like x-axis, y-axis from accelerometer and pass it on to a draw method which will then display the image on the received postions.

So, how can i get these points? I implemented the accelerometer based on this answer.

Moving an image using Accelerometer of android

Now I want to get the points from the accelerometer class. How can I do this?

Thanks in advance

Community
  • 1
  • 1
Mudasar
  • 249
  • 1
  • 5
  • 15

1 Answers1

1

Accelerometer does not return coordinates, it returns gravity readings relative to the phone's X-Y axes. In the answer in your question, the programmer is translating the gravity readings to coordinates by squaring the value (which may work, but not entirely correct).

What you should do is use some physics rules:

accelaration=(velocity2-velocity1)/time
velocity=(distance2-distance1)/time

Using this, you should have a variable representing the delta time & delta velocity between each frame and the previous one and use them to calculate the change in position. If this is too difficult for you, try the one in the answer you posted (it seems to work as the user accepted the answer, although I am not convinced).

Mohamed_AbdAllah
  • 5,311
  • 3
  • 28
  • 47