| 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/android/gvr/gvr_gamepad_data_fetcher.h" | 5 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 | |
| 10 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" | 9 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" |
| 10 #include "device/vr/vr_types.h" |
| 11 #include "third_party/WebKit/public/platform/WebGamepads.h" | 11 #include "third_party/WebKit/public/platform/WebGamepads.h" |
| 12 | 12 |
| 13 namespace device { | 13 namespace device { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 void CopyToWebUString(blink::WebUChar* dest, | 17 void CopyToWebUString(blink::WebUChar* dest, |
| 18 size_t dest_length, | 18 size_t dest_length, |
| 19 base::string16 src) { | 19 base::string16 src) { |
| 20 static_assert(sizeof(base::string16::value_type) == sizeof(blink::WebUChar), | 20 static_assert(sizeof(base::string16::value_type) == sizeof(blink::WebUChar), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 pad.axesLength = 2; | 98 pad.axesLength = 2; |
| 99 | 99 |
| 100 pad.displayId = display_id_; | 100 pad.displayId = display_id_; |
| 101 | 101 |
| 102 pad.hand = provided_data.right_handed ? GamepadHandRight : GamepadHandLeft; | 102 pad.hand = provided_data.right_handed ? GamepadHandRight : GamepadHandLeft; |
| 103 } | 103 } |
| 104 | 104 |
| 105 pad.timestamp = provided_data.timestamp; | 105 pad.timestamp = provided_data.timestamp; |
| 106 | 106 |
| 107 if (provided_data.is_touching) { | 107 if (provided_data.is_touching) { |
| 108 gvr_vec2f touch_position = provided_data.touch_pos; | 108 gfx::Vector2dF touch_position = provided_data.touch_pos; |
| 109 pad.axes[0] = (touch_position.x * 2.0f) - 1.0f; | 109 pad.axes[0] = (touch_position.x() * 2.0f) - 1.0f; |
| 110 pad.axes[1] = (touch_position.y * 2.0f) - 1.0f; | 110 pad.axes[1] = (touch_position.y() * 2.0f) - 1.0f; |
| 111 } else { | 111 } else { |
| 112 pad.axes[0] = 0.0f; | 112 pad.axes[0] = 0.0f; |
| 113 pad.axes[1] = 0.0f; | 113 pad.axes[1] = 0.0f; |
| 114 } | 114 } |
| 115 | 115 |
| 116 pad.buttons[0].touched = provided_data.is_touching; | 116 pad.buttons[0].touched = provided_data.is_touching; |
| 117 pad.buttons[0].pressed = provided_data.controller_button_pressed; | 117 pad.buttons[0].pressed = provided_data.controller_button_pressed; |
| 118 pad.buttons[0].value = pad.buttons[0].pressed ? 1.0f : 0.0f; | 118 pad.buttons[0].value = pad.buttons[0].pressed ? 1.0f : 0.0f; |
| 119 | 119 |
| 120 pad.pose.notNull = true; | 120 pad.pose.notNull = true; |
| 121 pad.pose.hasOrientation = true; | 121 pad.pose.hasOrientation = true; |
| 122 pad.pose.hasPosition = false; | 122 pad.pose.hasPosition = false; |
| 123 | 123 |
| 124 gvr_quatf orientation = provided_data.orientation; | 124 vr::Quatf orientation = provided_data.orientation; |
| 125 pad.pose.orientation.notNull = true; | 125 pad.pose.orientation.notNull = true; |
| 126 pad.pose.orientation.x = orientation.qx; | 126 pad.pose.orientation.x = orientation.qx; |
| 127 pad.pose.orientation.y = orientation.qy; | 127 pad.pose.orientation.y = orientation.qy; |
| 128 pad.pose.orientation.z = orientation.qz; | 128 pad.pose.orientation.z = orientation.qz; |
| 129 pad.pose.orientation.w = orientation.qw; | 129 pad.pose.orientation.w = orientation.qw; |
| 130 | 130 |
| 131 gvr_vec3f accel = provided_data.accel; | 131 gfx::Vector3dF accel = provided_data.accel; |
| 132 pad.pose.linearAcceleration.notNull = true; | 132 pad.pose.linearAcceleration.notNull = true; |
| 133 pad.pose.linearAcceleration.x = accel.x; | 133 pad.pose.linearAcceleration.x = accel.x(); |
| 134 pad.pose.linearAcceleration.y = accel.y; | 134 pad.pose.linearAcceleration.y = accel.y(); |
| 135 pad.pose.linearAcceleration.z = accel.z; | 135 pad.pose.linearAcceleration.z = accel.z(); |
| 136 | 136 |
| 137 gvr_vec3f gyro = provided_data.gyro; | 137 gfx::Vector3dF gyro = provided_data.gyro; |
| 138 pad.pose.angularVelocity.notNull = true; | 138 pad.pose.angularVelocity.notNull = true; |
| 139 pad.pose.angularVelocity.x = gyro.x; | 139 pad.pose.angularVelocity.x = gyro.x(); |
| 140 pad.pose.angularVelocity.y = gyro.y; | 140 pad.pose.angularVelocity.y = gyro.y(); |
| 141 pad.pose.angularVelocity.z = gyro.z; | 141 pad.pose.angularVelocity.z = gyro.z(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void GvrGamepadDataFetcher::PauseHint(bool paused) {} | 144 void GvrGamepadDataFetcher::PauseHint(bool paused) {} |
| 145 | 145 |
| 146 } // namespace device | 146 } // namespace device |
| OLD | NEW |