Example usage for android.hardware SensorManager AXIS_MINUS_Y

List of usage examples for android.hardware SensorManager AXIS_MINUS_Y

Introduction

In this page you can find the example usage for android.hardware SensorManager AXIS_MINUS_Y.

Prototype

int AXIS_MINUS_Y

To view the source code for android.hardware SensorManager AXIS_MINUS_Y.

Click Source Link

Document

see #remapCoordinateSystem

Usage

From source file:Main.java

public static void sensorRotation2Matrix(float[] gravity, float[] geomagnetic, int rotation, float[] output) {
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180: /* Notice: not supported for ROTATION_180! */
        SensorManager.getRotationMatrix(output, null, gravity, geomagnetic);
        break;/*ww w .  j av a2  s .  c om*/
    case Surface.ROTATION_90:
        SensorManager.getRotationMatrix(mTmp, null, gravity, geomagnetic);
        SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, output);
        break;
    case Surface.ROTATION_270:
        SensorManager.getRotationMatrix(mTmp, null, gravity, geomagnetic);
        SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, output);
        break;
    }
    Matrix.rotateM(output, 0, 90.0F, 1.0F, 0.0F, 0.0F);
}

From source file:Main.java

public static void sensorRotationVector2Matrix(SensorEvent event, int rotation, float[] output) {
    float[] values = event.values;
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180: /* Notice: not supported for ROTATION_180! */
        SensorManager.getRotationMatrixFromVector(output, values);
        break;//from   ww w . j a  va2s  . com
    case Surface.ROTATION_90:
        SensorManager.getRotationMatrixFromVector(mTmp, values);
        SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, output);
        break;
    case Surface.ROTATION_270:
        SensorManager.getRotationMatrixFromVector(mTmp, values);
        SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, output);
        break;
    }
    Matrix.rotateM(output, 0, 90.0F, 1.0F, 0.0F, 0.0F);
}

From source file:Main.java

public static void sensorRotationVector2Matrix(SensorEvent event, int rotation, float[] output) {
    if (!sIsTruncated) {
        try {//from   w  w  w . ja  v  a  2  s.  co  m
            SensorManager.getRotationMatrixFromVector(sUIThreadTmp, event.values);
        } catch (Exception e) {
            // On some Samsung devices, SensorManager#getRotationMatrixFromVector throws an exception
            // if the rotation vector has more than 4 elements. Since only the four first elements are used,
            // we can truncate the vector without losing precision.
            Log.e(TAG, "maybe Samsung bug, will truncate vector");
            sIsTruncated = true;
        }
    }

    if (sIsTruncated) {
        System.arraycopy(event.values, 0, sTruncatedVector, 0, 4);
        SensorManager.getRotationMatrixFromVector(sUIThreadTmp, sTruncatedVector);
    }

    float[] values = event.values;
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180: /* Notice: not supported for ROTATION_180! */
        SensorManager.getRotationMatrixFromVector(output, values);
        break;
    case Surface.ROTATION_90:
        SensorManager.getRotationMatrixFromVector(sUIThreadTmp, values);
        SensorManager.remapCoordinateSystem(sUIThreadTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X,
                output);
        break;
    case Surface.ROTATION_270:
        SensorManager.getRotationMatrixFromVector(sUIThreadTmp, values);
        SensorManager.remapCoordinateSystem(sUIThreadTmp, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X,
                output);
        break;
    }
    Matrix.rotateM(output, 0, 90.0F, 1.0F, 0.0F, 0.0F);
}

From source file:com.metinkale.prayerapp.compass.Main.java

@Override
public void onRotationUpdate(float[] newMatrix) {
    if (mMode == Mode.Map) {
        return;/*www  .  j a v  a  2 s.  c  o  m*/
    }
    // remap matrix values according to display rotation, as in
    // SensorManager documentation.
    switch (mDisplayRotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180:
        break;
    case Surface.ROTATION_90:
        SensorManager.remapCoordinateSystem(newMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X,
                newMatrix);
        break;
    case Surface.ROTATION_270:
        SensorManager.remapCoordinateSystem(newMatrix, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X,
                newMatrix);
        break;
    default:
        break;
    }
    mRotationMatrix.set(newMatrix);
    mOrientationCalculator.getOrientation(mRotationMatrix, mDisplayRotation, mDerivedDeviceOrientation);

    updateFrag((mDerivedDeviceOrientation[1] > -55f) ? Mode.ThreeDim : Mode.TwoDim);

    mList.onUpdateSensors(mDerivedDeviceOrientation);
}

From source file:com.tritop.androsense2.fragments.GpsFragment.java

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        mAccel = event.values;//from  w w  w.  j  a  v  a 2 s .c om
    }
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        mMag = event.values;
    }
    if ((mAccel != null) && (mMag != null)) {
        float R[] = new float[9];
        float I[] = new float[9];
        float Rot[] = new float[9];
        if (SensorManager.getRotationMatrix(R, I, mAccel, mMag)) {
            float orientation[] = new float[3];
            int axisX = 0, axisY = 0;
            switch (display.getRotation()) {
            case Surface.ROTATION_0:
                axisX = SensorManager.AXIS_X;
                axisY = SensorManager.AXIS_Y;
                break;
            case Surface.ROTATION_90:
                axisX = SensorManager.AXIS_Y;
                axisY = SensorManager.AXIS_MINUS_X;
                break;
            case Surface.ROTATION_180:
                axisX = SensorManager.AXIS_MINUS_X;
                axisY = SensorManager.AXIS_MINUS_Y;
                break;
            case Surface.ROTATION_270:
                axisX = SensorManager.AXIS_MINUS_Y;
                axisY = SensorManager.AXIS_X;
                break;
            default:
                break;
            }

            SensorManager.remapCoordinateSystem(R, axisX, axisY, Rot);
            SensorManager.getOrientation(Rot, orientation);
            aRotation = orientation[0];
            aRotation = (int) Math.toDegrees(aRotation);
            satView.setAzimutRotation(-aRotation);
            satView.invalidate();
        }
    }
}

From source file:com.shadowmaps.example.GpsTestActivity.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override//from   w  w w.ja v  a 2 s .  c  o m
public void onSensorChanged(SensorEvent event) {

    double orientation = Double.NaN;
    double tilt = Double.NaN;

    switch (event.sensor.getType()) {
    case Sensor.TYPE_ROTATION_VECTOR:
        // Modern rotation vector sensors
        if (!mTruncateVector) {
            try {
                SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values);
            } catch (IllegalArgumentException e) {
                // On some Samsung devices, an exception is thrown if this vector > 4 (see #39)
                // Truncate the array, since we can deal with only the first four values
                Log.e(TAG, "Samsung device error? Will truncate vectors - " + e);
                mTruncateVector = true;
                // Do the truncation here the first time the exception occurs
                getRotationMatrixFromTruncatedVector(event.values);
            }
        } else {
            // Truncate the array to avoid the exception on some devices (see #39)
            getRotationMatrixFromTruncatedVector(event.values);
        }

        int rot = getWindowManager().getDefaultDisplay().getRotation();
        switch (rot) {
        case Surface.ROTATION_0:
            // No orientation change, use default coordinate system
            SensorManager.getOrientation(mRotationMatrix, mValues);
            // Log.d(TAG, "Rotation-0");
            break;
        case Surface.ROTATION_90:
            // Log.d(TAG, "Rotation-90");
            SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y,
                    SensorManager.AXIS_MINUS_X, mRemappedMatrix);
            SensorManager.getOrientation(mRemappedMatrix, mValues);
            break;
        case Surface.ROTATION_180:
            // Log.d(TAG, "Rotation-180");
            SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_X,
                    SensorManager.AXIS_MINUS_Y, mRemappedMatrix);
            SensorManager.getOrientation(mRemappedMatrix, mValues);
            break;
        case Surface.ROTATION_270:
            // Log.d(TAG, "Rotation-270");
            SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_Y,
                    SensorManager.AXIS_X, mRemappedMatrix);
            SensorManager.getOrientation(mRemappedMatrix, mValues);
            break;
        default:
            // This shouldn't happen - assume default orientation
            SensorManager.getOrientation(mRotationMatrix, mValues);
            // Log.d(TAG, "Rotation-Unknown");
            break;
        }
        orientation = Math.toDegrees(mValues[0]); // azimuth
        tilt = Math.toDegrees(mValues[1]);
        break;
    case Sensor.TYPE_ORIENTATION:
        // Legacy orientation sensors
        orientation = event.values[0];
        break;
    default:
        // A sensor we're not using, so return
        return;
    }

    // Correct for true north, if preference is set
    if (mFaceTrueNorth && mGeomagneticField != null) {
        orientation += mGeomagneticField.getDeclination();
    }

    for (GpsTestListener listener : mGpsTestListeners) {
        listener.onOrientationChanged(orientation, tilt);
    }
}

From source file:com.android.gpstest.GpsTestActivity.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override/*  ww w  .  ja va 2 s.co  m*/
public void onSensorChanged(SensorEvent event) {

    double orientation = Double.NaN;
    double tilt = Double.NaN;

    switch (event.sensor.getType()) {
    case Sensor.TYPE_ROTATION_VECTOR:
        // Modern rotation vector sensors
        if (!mTruncateVector) {
            try {
                SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values);
            } catch (IllegalArgumentException e) {
                // On some Samsung devices, an exception is thrown if this vector > 4 (see #39)
                // Truncate the array, since we can deal with only the first four values
                Log.e(TAG, "Samsung device error? Will truncate vectors - " + e);
                mTruncateVector = true;
                // Do the truncation here the first time the exception occurs
                getRotationMatrixFromTruncatedVector(event.values);
            }
        } else {
            // Truncate the array to avoid the exception on some devices (see #39)
            getRotationMatrixFromTruncatedVector(event.values);
        }

        int rot = getWindowManager().getDefaultDisplay().getRotation();
        switch (rot) {
        case Surface.ROTATION_0:
            // No orientation change, use default coordinate system
            SensorManager.getOrientation(mRotationMatrix, mValues);
            // Log.d(TAG, "Rotation-0");
            break;
        case Surface.ROTATION_90:
            // Log.d(TAG, "Rotation-90");
            SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y,
                    SensorManager.AXIS_MINUS_X, mRemappedMatrix);
            SensorManager.getOrientation(mRemappedMatrix, mValues);
            break;
        case Surface.ROTATION_180:
            // Log.d(TAG, "Rotation-180");
            SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_X,
                    SensorManager.AXIS_MINUS_Y, mRemappedMatrix);
            SensorManager.getOrientation(mRemappedMatrix, mValues);
            break;
        case Surface.ROTATION_270:
            // Log.d(TAG, "Rotation-270");
            SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_Y,
                    SensorManager.AXIS_X, mRemappedMatrix);
            SensorManager.getOrientation(mRemappedMatrix, mValues);
            break;
        default:
            // This shouldn't happen - assume default orientation
            SensorManager.getOrientation(mRotationMatrix, mValues);
            // Log.d(TAG, "Rotation-Unknown");
            break;
        }
        orientation = Math.toDegrees(mValues[0]); // azimuth
        tilt = Math.toDegrees(mValues[1]);
        break;
    case Sensor.TYPE_ORIENTATION:
        // Legacy orientation sensors
        orientation = event.values[0];
        break;
    default:
        // A sensor we're not using, so return
        return;
    }

    // Correct for true north, if preference is set
    if (mFaceTrueNorth && mGeomagneticField != null) {
        orientation += mGeomagneticField.getDeclination();
        // Make sure value is between 0-360
        orientation = MathUtils.mod((float) orientation, 360.0f);
    }

    for (GpsTestListener listener : mGpsTestListeners) {
        listener.onOrientationChanged(orientation, tilt);
    }
}