0

I developed an Augmented Reality application using the front-camera and the min3d library. This application works fine on the Samsung Galaxy Tab 10,1 (first generation), running Android 4.0.4

But testing this same application (landscape mode only) on the ASUS Transformer TF700T with Android 4.1.1 give wrong orientation back and the augmented world does not match any more to the camera view.

The following code is used for getting the orientation vectors target_axis and up_axis needed for min3D:

SensorManager.getRotationMatrix(mR, null, mLastAccelerometer, mLastMagnetometer); 
SensorManager.getOrientation(mR, mOrientation);
Number3d target_axis = new Number3d( -mR[2], -mR[5], -mR[8] );
Number3d up_axis = new Number3d( mR[1], mR[4], mR[7] );

The mLastAccelerometer and mLastMagnetometer are received from an onSensorChanged(SensorEvent event)

Can somebody tell me if the above code is still too much device dependent? I would expect that using the SensorManager's gerOrientation call this solution should work throughout different devices?

Roalt
  • 8,330
  • 7
  • 41
  • 53

2 Answers2

1

My guess is that this is related to the orientation of the device, i.e. portrait, landscape, reversePortrait, reverseLandscape etc. The code that you posted is certainly too naive, because it doesn't take account of the rotation of the device relative to its default orientation. Use something like the following to calculate the azimuth adjustment

int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
float screen_adjustment = 0;
switch(rotation) {
    case Surface.ROTATION_0:   screen_adjustment =          0;         break;
    case Surface.ROTATION_90:  screen_adjustment =   (float)Math.PI/2; break;
    case Surface.ROTATION_180: screen_adjustment =   (float)Math.PI;   break;
    case Surface.ROTATION_270: screen_adjustment = 3*(float)Math.PI/2; break;
}

which is what I use in my answer to Android Compass that can Compensate for Tilt and Pitch. Other people suggest using SensorManager.remapCoordinateSystem(float[], int, int, float[]) depending on what that rotation number is.

Community
  • 1
  • 1
Stochastically
  • 7,616
  • 5
  • 30
  • 58
  • Ah, as I hold both device the same way, this would suggest that a Galaxy Tab has a different "default" orientation than a Asus Transformer ? – Roalt May 16 '13 at 11:27
  • I'm not sure about those devices, however I *think* that tablets can have default orientation as landscape, whereas the default orientation on phones tends to be portrait. – Stochastically May 16 '13 at 11:40
0

In the end, there was something wrong with the hardware of the ASUS Transformer Pad TF700. On other devices, the application worked as expected.

Roalt
  • 8,330
  • 7
  • 41
  • 53