Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: third_party/WebKit/Source/modules/gamepad/GamepadPose.cpp

Issue 2300543003: Added Pose attribute to Gamepad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gamepad_touched
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/gamepad/GamepadPose.cpp
diff --git a/third_party/WebKit/Source/modules/gamepad/GamepadPose.cpp b/third_party/WebKit/Source/modules/gamepad/GamepadPose.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5b75a8e3e0b1f12aa2591610b5cfc53227238eb0
--- /dev/null
+++ b/third_party/WebKit/Source/modules/gamepad/GamepadPose.cpp
@@ -0,0 +1,67 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/gamepad/GamepadPose.h"
+
+namespace blink {
+
+namespace {
+
+DOMFloat32Array* vecToFloat32Array(const WebGamepadVector& vec)
+{
+ if (vec.notNull) {
+ DOMFloat32Array* out = DOMFloat32Array::create(3);
+ out->data()[0] = vec.x;
+ out->data()[1] = vec.y;
+ out->data()[2] = vec.z;
+ return out;
+ }
+ return nullptr;
+}
+
+DOMFloat32Array* quatToFloat32Array(const WebGamepadQuaternion& quat)
+{
+ if (quat.notNull) {
+ DOMFloat32Array* out = DOMFloat32Array::create(4);
+ out->data()[0] = quat.x;
+ out->data()[1] = quat.y;
+ out->data()[2] = quat.z;
+ out->data()[3] = quat.w;
+ return out;
+ }
+ return nullptr;
+}
+
+} // namespace
+
+GamepadPose::GamepadPose()
+{
+}
+
+void GamepadPose::setPose(const WebGamepadPose &state)
+{
+ if (state.notNull) {
+ m_hasOrientation = state.hasOrientation;
+ m_hasPosition = state.hasPosition;
+
+ m_orientation = quatToFloat32Array(state.orientation);
+ m_position = vecToFloat32Array(state.position);
+ m_angularVelocity = vecToFloat32Array(state.angularVelocity);
+ m_linearVelocity = vecToFloat32Array(state.linearVelocity);
+ m_angularAcceleration = vecToFloat32Array(state.angularAcceleration);
+ m_linearAcceleration = vecToFloat32Array(state.linearAcceleration);
+ }
+}
+
+DEFINE_TRACE(GamepadPose)
+{
+ visitor->trace(m_orientation);
+ visitor->trace(m_position);
+ visitor->trace(m_angularVelocity);
+ visitor->trace(m_linearVelocity);
+ visitor->trace(m_angularAcceleration);
+ visitor->trace(m_linearAcceleration);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/gamepad/GamepadPose.h ('k') | third_party/WebKit/Source/modules/gamepad/GamepadPose.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698