augmented-reality-tutorial
augmented-reality-tutorial copied to clipboard
How to make it work properly on landscape?
There seems to be a problem when the orientation is landscape. The dots goes left and right even when the device is slightly moved up or down.
@dhagz Did you find a solution for this?
Yes, I get the rotation of the phone whether 0, 90, 180, or 270. So, if it's on landscape I switched the values of the accelerometer's x and y.
Thank you for answering! I've tried that too, but it didn't help for me. I've put the following code in OnResume(), so that each time my phone's orientation changes, I can change the x and y. Have you got any idea what I'm doing wrong here?
` SurfaceOrientation mScreenRotation = this.WindowManager.DefaultDisplay.Rotation;
Android.Hardware.Axis axisX = Android.Hardware.Axis.X;
Android.Hardware.Axis axisY = Android.Hardware.Axis.Y;
switch (mScreenRotation)
{
case SurfaceOrientation.Rotation0:
axisX = Android.Hardware.Axis.X; //Sensor SensorManager.AXIS_X;
axisY = Android.Hardware.Axis.Y; // SensorManager.AXIS_Y;
break;
case SurfaceOrientation.Rotation90:
axisX = Android.Hardware.Axis.Y;
axisY = Android.Hardware.Axis.MinusX; // SensorManager.AXIS_MINUS_X;
break;
case SurfaceOrientation.Rotation180:
axisX = Android.Hardware.Axis.MinusX;
axisY = Android.Hardware.Axis.MinusY;
break;
case SurfaceOrientation.Rotation270:
axisX = Android.Hardware.Axis.MinusY;
axisY = Android.Hardware.Axis.X;
break;
default:
break;
}
float[] oR = new float[9];
float[] iR = new float[9];
bool remapped = SensorManager.RemapCoordinateSystem(iR, axisX, axisY, oR); `
(I'm working in Xamarin, so my code is a little different from Java)