Tablet AR. Wrong reading ?
Closed this issue · 6 comments
Hi, :) I would like to use this framework on tablets (which is landscape by default) and I'm getting faulty orientation sensors reading. Please help.
Here's what I have so far.
In the SensorsActivity I tried getting the default orientation of the device but I got no luck
int deviceRotation = ((WindowManager) getApplicationContext().getSystemService(
Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
if (deviceRotation == 0) // Default display rotation is landscape
SensorManager.remapCoordinateSystem(temp,
SensorManager.AXIS_MINUS_X, SensorManager.AXIS_Y, rotation);
else {// Default display rotation is landscape
SensorManager.remapCoordinateSystem(temp, SensorManager.AXIS_Y,
SensorManager.AXIS_MINUS_Z, rotation);
}
This is a problem with a few specific tablets and I have yet to find a solution to it. Unfortunately, I don't have a tablet which has the problem, so I cannot really help find a solution. You can follow along here:
https://groups.google.com/forum/#!topic/android-augment-reality-framework/g-id-lovgf4
I see, Thanks for the link Its clear now. and It works well when I use
SensorManager.remapCoordinateSystem(temp, SensorManager.AXIS_Z,SensorManager.AXIS_Y, rotation);
for landscape devices.
Wow, great. What tablet do you have? Which version of Android?
Hi, I've tested it on a SG Tab 2 10.1 which runs stock 4.1 android. Anyways, here's the full code that might help someone.
if (isLandscape()) {
SensorManager.remapCoordinateSystem(temp, SensorManager.AXIS_Z,
SensorManager.AXIS_Y, rotation);
} else {
SensorManager.remapCoordinateSystem(temp, SensorManager.AXIS_Y,
SensorManager.AXIS_MINUS_Z, rotation);
}
the method:
public Boolean isLandscape() {
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Configuration config = getResources().getConfiguration();
int rotation = windowManager.getDefaultDisplay().getRotation();
if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && config.orientation == Configuration.ORIENTATION_LANDSCAPE)
|| ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
return true;
} else {
return false;
}
}
Great. You may want to cache the result since that method is called often and the result of it shouldn't change; although Java will likely cache it at some point also.
Something like:
private boolean isSet = false;
private boolean defaultIsLandscape = false;
public Boolean isLandscape() {
if (isSet) return defaultIsLandscape;
isSet = true;
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Configuration config = getResources().getConfiguration();
int rotation = windowManager.getDefaultDisplay().getRotation();
if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && config.orientation == Configuration.ORIENTATION_LANDSCAPE)
|| ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
defaultIsLandscape = true;
} else {
defaultIsLandscape = false;
}
return defaultIsLandscape;
}
Thanks for pointing that out. :)