| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "device/vr/vr_math.h" | 5 #include "device/vr/vr_math.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 float len = vec->Length(); | 113 float len = vec->Length(); |
| 114 if (len == 0) | 114 if (len == 0) |
| 115 return 0; | 115 return 0; |
| 116 vec->Scale(1.0f / len); | 116 vec->Scale(1.0f / len); |
| 117 return len; | 117 return len; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void NormalizeQuat(Quatf* quat) { | 120 void NormalizeQuat(Quatf* quat) { |
| 121 float len = sqrt(quat->qx * quat->qx + quat->qy * quat->qy + | 121 float len = sqrt(quat->qx * quat->qx + quat->qy * quat->qy + |
| 122 quat->qz * quat->qz + quat->qw * quat->qw); | 122 quat->qz * quat->qz + quat->qw * quat->qw); |
| 123 DCHECK_NE(len, 0); |
| 124 if (len == 0) |
| 125 return; |
| 123 quat->qx /= len; | 126 quat->qx /= len; |
| 124 quat->qy /= len; | 127 quat->qy /= len; |
| 125 quat->qz /= len; | 128 quat->qz /= len; |
| 126 quat->qw /= len; | 129 quat->qw /= len; |
| 127 } | 130 } |
| 128 | 131 |
| 129 Quatf QuatFromAxisAngle(const RotationAxisAngle& axis_angle) { | 132 Quatf QuatFromAxisAngle(const RotationAxisAngle& axis_angle) { |
| 130 // Rotation angle is the product of |angle| and the magnitude of |axis|. | 133 // Rotation angle is the product of |angle| and the magnitude of |axis|. |
| 131 gfx::Vector3dF normal(axis_angle.x, axis_angle.y, axis_angle.z); | 134 gfx::Vector3dF normal(axis_angle.x, axis_angle.y, axis_angle.z); |
| 132 float length = NormalizeVector(&normal); | 135 float length = NormalizeVector(&normal); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 283 |
| 281 float Clampf(float value, float min, float max) { | 284 float Clampf(float value, float min, float max) { |
| 282 if (value < min) | 285 if (value < min) |
| 283 return min; | 286 return min; |
| 284 if (value > max) | 287 if (value > max) |
| 285 return max; | 288 return max; |
| 286 return value; | 289 return value; |
| 287 } | 290 } |
| 288 | 291 |
| 289 } // namespace vr | 292 } // namespace vr |
| OLD | NEW |