diff options
author | Mathias Agopian <mathias@google.com> | 2010-11-22 01:04:09 -0800 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2012-06-27 17:07:54 -0700 |
commit | 5c6d7ff3e643d0fb4b46d81a3a4e6edaba779edd (patch) | |
tree | a56e015dde1660d103d95a8aa457cad1668b5774 /services/sensorservice/RotationVectorSensor.cpp | |
parent | f001c92436b4a66eb7687286325ced7f10c9f917 (diff) | |
download | frameworks_native-5c6d7ff3e643d0fb4b46d81a3a4e6edaba779edd.zip frameworks_native-5c6d7ff3e643d0fb4b46d81a3a4e6edaba779edd.tar.gz frameworks_native-5c6d7ff3e643d0fb4b46d81a3a4e6edaba779edd.tar.bz2 |
don't attempt to normalize the rotation vector
indeed, by construction of the rotation matrix, it is
guaranteed to have a length of 1.
moreover, the normalization code was missing a square-root,
fortunatelly, since the length is 1, this didn't cause any
damage (since sqrt(1) = 1).
Change-Id: I9facd668caaf5bb3bfccb139ab872f2bb2066365
Diffstat (limited to 'services/sensorservice/RotationVectorSensor.cpp')
-rw-r--r-- | services/sensorservice/RotationVectorSensor.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/services/sensorservice/RotationVectorSensor.cpp b/services/sensorservice/RotationVectorSensor.cpp index 6f4b8be..eecf260 100644 --- a/services/sensorservice/RotationVectorSensor.cpp +++ b/services/sensorservice/RotationVectorSensor.cpp @@ -114,10 +114,12 @@ bool RotationVectorSensor::process(sensors_event_t* outEvent, float qx = sqrtf( clamp( Hx - My - Az + 1) * 0.25f ); float qy = sqrtf( clamp(-Hx + My - Az + 1) * 0.25f ); float qz = sqrtf( clamp(-Hx - My + Az + 1) * 0.25f ); - const float n = 1.0f / (qw*qw + qx*qx + qy*qy + qz*qz); - qx = copysignf(qx, Ay - Mz) * n; - qy = copysignf(qy, Hz - Ax) * n; - qz = copysignf(qz, Mx - Hy) * n; + qx = copysignf(qx, Ay - Mz); + qy = copysignf(qy, Hz - Ax); + qz = copysignf(qz, Mx - Hy); + + // this quaternion is guaranteed to be normalized, by construction + // of the rotation matrix. *outEvent = event; outEvent->data[0] = qx; |