| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/device_sensors/sensor_manager_chromeos.h" | 5 #include "content/browser/device_sensors/sensor_manager_chromeos.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "chromeos/accelerometer/accelerometer_reader.h" | 9 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 10 #include "chromeos/accelerometer/accelerometer_types.h" | 10 #include "chromeos/accelerometer/accelerometer_types.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 motion_buffer_->seqlock.WriteEnd(); | 133 motion_buffer_->seqlock.WriteEnd(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void SensorManagerChromeOS::GenerateOrientationEvent(double x, | 136 void SensorManagerChromeOS::GenerateOrientationEvent(double x, |
| 137 double y, | 137 double y, |
| 138 double z) { | 138 double z) { |
| 139 if (!orientation_buffer_) | 139 if (!orientation_buffer_) |
| 140 return; | 140 return; |
| 141 | 141 |
| 142 // Create a unit vector for trigonometry | 142 // Create a unit vector for trigonometry |
| 143 // TODO(jonross): Stop reversing signs for vector components once | 143 gfx::Vector3dF data(x, y, z); |
| 144 // accelerometer values have been fixed. crbug.com/431391 | |
| 145 // Ternaries are to remove -0.0f which gives incorrect trigonometrical | |
| 146 // results. | |
| 147 gfx::Vector3dF data(x, y ? -y : 0.0f, z ? -z : 0.0f); | |
| 148 data.Scale(1.0f / data.Length()); | 144 data.Scale(1.0f / data.Length()); |
| 149 | 145 |
| 150 // Transform accelerometer to W3C angles, using the Z-X-Y Eulerangles matrix. | 146 // Transform accelerometer to W3C angles, using the Z-X-Y Eulerangles matrix. |
| 151 // x = sin(gamma) | 147 // x = sin(gamma) |
| 152 // y = -cos(gamma) * sin(beta) | 148 // y = -cos(gamma) * sin(beta) |
| 153 // z = cos(beta) * cos(gamma) | 149 // z = cos(beta) * cos(gamma) |
| 154 // With only accelerometer alpha cannot be provided. | 150 // With only accelerometer alpha cannot be provided. |
| 155 double beta = kRad2deg * atan2(data.y(), data.z()); | 151 double beta = kRad2deg * atan2(data.y(), data.z()); |
| 156 double gamma = kRad2deg * asin(data.x()); | 152 double gamma = kRad2deg * asin(-data.x()); |
| 157 | 153 |
| 158 // Convert beta and gamma to fit the intervals in the specification. Beta is | 154 // Convert beta and gamma to fit the intervals in the specification. Beta is |
| 159 // [-180, 180) and gamma is [-90, 90). | 155 // [-180, 180) and gamma is [-90, 90). |
| 160 if (beta >= 180.0f) | 156 if (beta >= 180.0f) |
| 161 beta = -180.0f; | 157 beta = -180.0f; |
| 162 if (gamma >= 90.0f) | 158 if (gamma >= 90.0f) |
| 163 gamma = -90.0f; | 159 gamma = -90.0f; |
| 164 orientation_buffer_->seqlock.WriteBegin(); | 160 orientation_buffer_->seqlock.WriteBegin(); |
| 165 orientation_buffer_->data.beta = beta; | 161 orientation_buffer_->data.beta = beta; |
| 166 orientation_buffer_->data.hasBeta = true; | 162 orientation_buffer_->data.hasBeta = true; |
| 167 orientation_buffer_->data.gamma = gamma; | 163 orientation_buffer_->data.gamma = gamma; |
| 168 orientation_buffer_->data.hasGamma = true; | 164 orientation_buffer_->data.hasGamma = true; |
| 169 orientation_buffer_->data.allAvailableSensorsAreActive = true; | 165 orientation_buffer_->data.allAvailableSensorsAreActive = true; |
| 170 orientation_buffer_->seqlock.WriteEnd(); | 166 orientation_buffer_->seqlock.WriteEnd(); |
| 171 } | 167 } |
| 172 | 168 |
| 173 } // namespace content | 169 } // namespace content |
| OLD | NEW |