augmented-reality-tutorial icon indicating copy to clipboard operation
augmented-reality-tutorial copied to clipboard

How to make it work properly on landscape?

Open dhagz opened this issue 8 years ago • 3 comments

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 avatar Nov 22 '16 06:11 dhagz

@dhagz Did you find a solution for this?

JvPer avatar Jan 30 '17 07:01 JvPer

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.

dhagz avatar Jan 30 '17 17:01 dhagz

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)

JvPer avatar Jan 31 '17 07:01 JvPer