0

I was wondering which sensors are used in race games in android.

As a matter of fact I needed to measure the exact angle of rotation in my android phone but I found out my cellphone doesn't have required sensors like GRAVITY or MAGNETIC and its android API is 17. Based on my searches through the web, I find out it's impossible to measure the exact angle of rotation without these sensors.

So I was wondering how race games work in my cellphone??? In such games you control the car by rotating the screen. But how these games find out about its rotation when it doesn't have required sensors!!!

This question may seem a little Stupid but I will appreciate if someone answer it.

Taher
  • 1,185
  • 3
  • 18
  • 36
  • possible duplicate of [Get Android rotation angle in x-axis](http://stackoverflow.com/questions/12080170/get-android-rotation-angle-in-x-axis) Also check this out: http://www.reddit.com/r/androiddev/comments/1av1la/ – Paul Sasik Dec 07 '14 at 07:59
  • Additional thoughts: don't think about absolute measures of rotation. You don't need the absolute, all you need is changes from some initial state and maybe adjustments as you go. For a simple example, say you're laying on your side holding the phone in landscape perspective to you. That's your starting point and all steering calculations are made from this initial state. Things get more interesting if you take into account standing up etc. but that's just a matter of some fuzzy math and resetting your "base" rotation. – Paul Sasik Dec 07 '14 at 08:10
  • I checked it and some other posts too. That doesn't work. I don't know why but it gives wrong values for rotation angle in each axis. I checked a lot of pages and also I read couple books like "Book-Android Sensor Programming, published by Wrox". They say TYPE_ORIENTATION is deprecated.For API 20 and later TYPE_LINEAR_ACCELERATION gives rotation and for other APIs GRAVITY or MAGNETIC is needed. – Taher Dec 07 '14 at 08:18
  • Hmm. I'm not big on games on my Android. Are the grav and mag sensors a newer generation thing? e.g. Do you happen to have an older phone and most newer phones have the sensors? Btw, it's tough to develop when you have only one device to test/work with, especially an older one. – Paul Sasik Dec 07 '14 at 08:21
  • So they don't use rotation angle to define the amount of steering? It doesn't make sense!!! because as much as you rotate the phone, the car turns left or right more. So it should be a relation between the amount of rotating and steering. Also how the app find out I rotate the cellphone? It should use some sensors. – Taher Dec 07 '14 at 08:23
  • Yea, I don't have any access to a powerful cellphone. I don't think they are new but as I know my cellphone doesn't have them. – Taher Dec 07 '14 at 08:27

1 Answers1

0

You can use Accelerometer for checking orientation of device in all X, Y and Z axis. You don't need to depend on GRAVITY and MAGNETIC as you said. Refer the code below, may be this might help you -

float[] rotationMatrix = new float[9];  
if(SensorManager.getRotationMatrix(rotationMatrix, null, lastAcceleration, lastMagneticField)){
float[] orientMatrix = new float[3];
float remapMatrix = new float[9];
SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, remapMatrix);
SensorManager.getOrientation(remapMatrix, orientMatrix);

orientation = orientMat[0]*180/(float)Math.PI;

Cheers :)

Ashish Tamrakar
  • 810
  • 10
  • 24
  • You use lastMagneticField which is derived from MAGNETIC!!! So how you suggest that I don't need MAGNETIC!!! – Taher Dec 12 '14 at 14:55