summaryrefslogtreecommitdiffstats
path: root/core/java/android/hardware/SensorManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/hardware/SensorManager.java')
-rw-r--r--core/java/android/hardware/SensorManager.java21
1 files changed, 14 insertions, 7 deletions
diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java
index c178aee..1b799ae 100644
--- a/core/java/android/hardware/SensorManager.java
+++ b/core/java/android/hardware/SensorManager.java
@@ -1938,13 +1938,18 @@ public class SensorManager
* @param R an array of floats in which to store the rotation matrix
*/
public static void getRotationMatrixFromVector(float[] R, float[] rotationVector) {
- float q0 = (float)Math.sqrt(1 - rotationVector[0]*rotationVector[0] -
- rotationVector[1]*rotationVector[1] -
- rotationVector[2]*rotationVector[2]);
+
+ float q0;
float q1 = rotationVector[0];
float q2 = rotationVector[1];
float q3 = rotationVector[2];
+ if (rotationVector.length == 4) {
+ q0 = rotationVector[3];
+ } else {
+ q0 = (float)Math.sqrt(1 - q1*q1 - q2*q2 - q3*q3);
+ }
+
float sq_q1 = 2 * q1 * q1;
float sq_q2 = 2 * q2 * q2;
float sq_q3 = 2 * q3 * q3;
@@ -1995,10 +2000,12 @@ public class SensorManager
* @param Q an array of floats in which to store the computed quaternion
*/
public static void getQuaternionFromVector(float[] Q, float[] rv) {
- float w = (float)Math.sqrt(1 - rv[0]*rv[0] - rv[1]*rv[1] - rv[2]*rv[2]);
- //In this case, the w component of the quaternion is known to be a positive number
-
- Q[0] = w;
+ if (rv.length == 4) {
+ Q[0] = rv[3];
+ } else {
+ //In this case, the w component of the quaternion is known to be a positive number
+ Q[0] = (float)Math.sqrt(1 - rv[0]*rv[0] - rv[1]*rv[1] - rv[2]*rv[2]);
+ }
Q[1] = rv[0];
Q[2] = rv[1];
Q[3] = rv[2];