Wednesday, October 2, 2013

[android-developers] Re:  getRotationMatrixFromVector() broken on Note 3

As a temporary fix you could just copy-paste the original source code from the Android SDK as a drop-in replacement:

    public static void getRotationMatrixFromVector(float[] R, float[] rotationVector) {

        float q0;
        float q1 = rotationVector[0];
        float q2 = rotationVector[1];
        float q3 = rotationVector[2];

        if (rotationVector.length == 4) {
            q0 = rotationVector[3];
        } else {
            q0 = 1 - q1*q1 - q2*q2 - q3*q3;
            q0 = (q0 > 0) ? (float)Math.sqrt(q0) : 0;
        }

        float sq_q1 = 2 * q1 * q1;
        float sq_q2 = 2 * q2 * q2;
        float sq_q3 = 2 * q3 * q3;
        float q1_q2 = 2 * q1 * q2;
        float q3_q0 = 2 * q3 * q0;
        float q1_q3 = 2 * q1 * q3;
        float q2_q0 = 2 * q2 * q0;
        float q2_q3 = 2 * q2 * q3;
        float q1_q0 = 2 * q1 * q0;

        if(R.length == 9) {
            R[0] = 1 - sq_q2 - sq_q3;
            R[1] = q1_q2 - q3_q0;
            R[2] = q1_q3 + q2_q0;

            R[3] = q1_q2 + q3_q0;
            R[4] = 1 - sq_q1 - sq_q3;
            R[5] = q2_q3 - q1_q0;

            R[6] = q1_q3 - q2_q0;
            R[7] = q2_q3 + q1_q0;
            R[8] = 1 - sq_q1 - sq_q2;
        } else if (R.length == 16) {
            R[0] = 1 - sq_q2 - sq_q3;
            R[1] = q1_q2 - q3_q0;
            R[2] = q1_q3 + q2_q0;
            R[3] = 0.0f;

            R[4] = q1_q2 + q3_q0;
            R[5] = 1 - sq_q1 - sq_q3;
            R[6] = q2_q3 - q1_q0;
            R[7] = 0.0f;

            R[8] = q1_q3 - q2_q0;
            R[9] = q2_q3 + q1_q0;
            R[10] = 1 - sq_q1 - sq_q2;
            R[11] = 0.0f;

            R[12] = R[13] = R[14] = 0.0f;
            R[15] = 1.0f;
        }
    }

Interestingly enough the original code does not explicitly throw the exception you mentioned. So it must be some weird Samsung hack. You could try registering with Samsung as a developer and use their support ticket system in order to tell them about this problem. However, I already complained once about one of their SDKs and never heard back from them.

On Wednesday, October 2, 2013 8:41:01 AM UTC-5, String wrote:

I've been getting error reports from users of the Note 3 that boil down to the following:


java.lang.IllegalArgumentException: R array length must be 3 or 4

at android.hardware.SensorManager.getRotationMatrixFromVector(SensorManager.java:1336)


This function, getRotationMatrixFromVector(), is documented as a "Helper function to convert a rotation vector to a rotation matrix. Given a rotation vector (presumably from a ROTATION_VECTOR sensor)". My typical call to this function looks like this:


SensorManager.getRotationMatrixFromVector(R, rotationVector);


Where the rotationVector comes from the hardware accelerometer and gyroscope, and (despite the error message about R) it's with this parameter where the problem lies. It's directly passed from android.hardware.SensorEventListener.onSensorChanged(SensorEvent event) for a Sensor.TYPE_ROTATION_VECTOR event. The event parameter there has a values property that is passed as the rotationVector in the previous call. And according to the docs at
http://developer.android.com/reference/android/hardware/SensorEvent.html#values, this array can legitimately have up to 5 elements - moreover, in Android 4.3, it 
should have all 5. However, passing an array of length 5 causes the Note 3 to crash on the aforementioned IllegalArgumentException; it seems to expect 4 elements at most.


So, here's the summary: Android 4.3 passes an array with 5 elements to this hardware event, and the Note 3 throws an exception when passed that same array to the system-defined helper function for that event. This behavior does not happen on the other 4.3 devices I have at hand (Galaxy Nexus and Nexus 7); it appears to be a basic flaw in the Samsung implementation of 4.3.


And I know, this all looks like minutiae of a hyper-specific issue - but believe me, it's likely to be encountered by any app using the device's motion sensors. A Google search for getRotationMatrixFromVectoreturns 51,400 results.

Any comment from Samsung on this would be most welcome, if unlikely.


String


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate