Android : Rotating a 3D object based on sensors : TYPE_ROTATION_VECTOR vs TYPE_ACCELEROMETER

Burf2000

Coming from a iOS background, I am starting to see some of the more interesting parts of Android like device support for sensors and even OpenGL calls.

I have been using the Sensor.TYPE_ROTATION_VECTOR in Android to rotate a object in 3D space based on the device. Works great on a Nexus 7 (2012) with no issues. However, any other device (Nexus 5, HTC sensation, Terga Note) it jumps around like its on speed.

This was the same result I got when I just used the Sensor.TYPE_ACCELEROMETER

Does anyone have any advice, code or anything about getting a smooth (on majority of devices) sensor value.

Override
    public void onSensorChanged(SensorEvent event) {

        int type = event.sensor.getType();

        //Log.i("TAG", "Sensor " + type);

        // It is good practice to check that we received the proper sensor event
        if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
            //lowPass( event.values.clone(), MagneticFieldValues_last );

            // Convert the rotation-vector to a 4x4 matrix.
            SensorManager.getRotationMatrixFromVector(mRotationMatrix,
                    event.values);

            SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mRotationMatrix);
            SensorManager.getOrientation(mRotationMatrix, orientationVals);

            Matrix.multiplyMV(orientationVector, 0, mRotationMatrix, 0, sZVector, 0);
            orientation = (float) (-Math.atan2(orientationVector[0], orientationVector[1]) * RADIANS_TO_DEGREES);

            Matrix.invertM(mRotationMatrix_inv, 0, mRotationMatrix, 0);
            Matrix.multiplyMV(azimuthVector, 0, mRotationMatrix_inv, 0, sZVector, 0);
            azimuth = (float) (180 + Math.atan2(azimuthVector[0], azimuthVector[1]) * RADIANS_TO_DEGREES);

            // Optionally convert the result from radians to degrees
            orientationVals[0] = (float) Math.toDegrees(orientationVals[0]);
            orientationVals[1] = (float) Math.toDegrees(orientationVals[1]);
            orientationVals[2] = (float) Math.toDegrees(orientationVals[2]);

        }


        if (type == Sensor.TYPE_MAGNETIC_FIELD) {

            pitch = event.values[2] * axisSwapper;
        }
    }

I was using a low pass filter however it was not required on the Nexus 7 and did not seem to work well.

//    protected float[] lowPass( float[] input, float[] output ) {
//        if ( output == null ) return input;
//
//        for ( int i=0; i<input.length; i++ ) {
//            output[i] = output[i] + ALPHA * (input[i] - output[i]);
//        }
//        return output;
//    }
Burf2000

I found moving to Google Cardboard for head tracking made things just work! really easy to implement. Copied

https://github.com/MasDennis/RajawaliVR

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android : Rotating a 3D object based on sensors : TYPE_ROTATION_VECTOR vs TYPE_ACCELEROMETER

From Dev

Android TYPE_ROTATION_VECTOR null

From Dev

Android Sensor Manager Rotation Vector (TYPE_ROTATION_VECTOR) unreliable / slow

From Dev

Android Sensor Manager Rotation Vector (TYPE_ROTATION_VECTOR) unreliable / slow

From Dev

How type TYPE_ACCELEROMETER and TYPE_MAGNETIC_FIELD used to make compass on android devices

From Dev

TYPE_ACCELEROMETER Remove the gravity, the meaning of t/(t+dT)

From Dev

Rotating object via Vector 3 var

From Dev

Rotating Camera according to 3D Object's position

From Dev

Rotating Camera according to 3D Object's position

From Dev

Rajawali rotating camera with Sensor.TYPE_ROTATION_VECTOR strange behavior

From Dev

Rotating a 3D Vector without a Matrix (OpenGL)

From Dev

Rotating Vector3D

From Dev

Rotating Vector3D

From Dev

Implementing current cardinal direction method with TYPE_ROTATION_VECTOR while standing still?

From Dev

Dynamically creating a 3D object in Android

From Dev

Three js Object 3D rotation

From Dev

Object not rotating

From Dev

calculate vector after rotating it towards another by angle θ in 3D space

From Dev

Generic type vs dynamic vs object

From Dev

Find Object By Type vs String

From Dev

Rotating object along all 3 axes to map to the player's camera LookAt vector

From Dev

Android sensors and thread

From Dev

Android sensors not working in a service

From Dev

Android sensors and thread

From Dev

Get list of sensors in Android

From Dev

Redundant motion sensors on android?

From Dev

Multiple sensors on an android application

From Dev

Three.js - rotating an Object3D around an axis

From Dev

Rotating and working on MATLAB 3D objects

Related Related

  1. 1

    Android : Rotating a 3D object based on sensors : TYPE_ROTATION_VECTOR vs TYPE_ACCELEROMETER

  2. 2

    Android TYPE_ROTATION_VECTOR null

  3. 3

    Android Sensor Manager Rotation Vector (TYPE_ROTATION_VECTOR) unreliable / slow

  4. 4

    Android Sensor Manager Rotation Vector (TYPE_ROTATION_VECTOR) unreliable / slow

  5. 5

    How type TYPE_ACCELEROMETER and TYPE_MAGNETIC_FIELD used to make compass on android devices

  6. 6

    TYPE_ACCELEROMETER Remove the gravity, the meaning of t/(t+dT)

  7. 7

    Rotating object via Vector 3 var

  8. 8

    Rotating Camera according to 3D Object's position

  9. 9

    Rotating Camera according to 3D Object's position

  10. 10

    Rajawali rotating camera with Sensor.TYPE_ROTATION_VECTOR strange behavior

  11. 11

    Rotating a 3D Vector without a Matrix (OpenGL)

  12. 12

    Rotating Vector3D

  13. 13

    Rotating Vector3D

  14. 14

    Implementing current cardinal direction method with TYPE_ROTATION_VECTOR while standing still?

  15. 15

    Dynamically creating a 3D object in Android

  16. 16

    Three js Object 3D rotation

  17. 17

    Object not rotating

  18. 18

    calculate vector after rotating it towards another by angle θ in 3D space

  19. 19

    Generic type vs dynamic vs object

  20. 20

    Find Object By Type vs String

  21. 21

    Rotating object along all 3 axes to map to the player's camera LookAt vector

  22. 22

    Android sensors and thread

  23. 23

    Android sensors not working in a service

  24. 24

    Android sensors and thread

  25. 25

    Get list of sensors in Android

  26. 26

    Redundant motion sensors on android?

  27. 27

    Multiple sensors on an android application

  28. 28

    Three.js - rotating an Object3D around an axis

  29. 29

    Rotating and working on MATLAB 3D objects

HotTag

Archive