| 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 // Adapted from: | 5 // Adapted from: |
| 6 // https://github.com/googlevr/gvr-unity-sdk/blob/master/Samples/DaydreamLabsCon
trollerPlayground/Assets/GoogleVR/Scripts/Controller/GvrArmModel.cs | 6 // https://github.com/googlevr/gvr-unity-sdk/blob/master/Samples/DaydreamLabsCon
trollerPlayground/Assets/GoogleVR/Scripts/Controller/GvrArmModel.cs |
| 7 | 7 |
| 8 #include "chrome/browser/android/vr_shell/elbow_model.h" | 8 #include "chrome/browser/android/vr_shell/elbow_model.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 constexpr gfx::Vector3dF kDefaultArmExtensionOffset = {-0.13f, 0.14f, -0.08f}; | 25 constexpr gfx::Vector3dF kDefaultArmExtensionOffset = {-0.13f, 0.14f, -0.08f}; |
| 26 constexpr float kMinExtensionAngle = 7.0f; | 26 constexpr float kMinExtensionAngle = 7.0f; |
| 27 constexpr float kMaxExtenstionAngle = 60.0f; | 27 constexpr float kMaxExtenstionAngle = 60.0f; |
| 28 constexpr float kExtensionWeight = 0.4f; | 28 constexpr float kExtensionWeight = 0.4f; |
| 29 constexpr float kDeltaAlpha = 3.0f; | 29 constexpr float kDeltaAlpha = 3.0f; |
| 30 constexpr float kDefaultElbowRotationRatio = 0.4f; | 30 constexpr float kDefaultElbowRotationRatio = 0.4f; |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 ElbowModel::ElbowModel(gvr::ControllerHandedness handedness) | 34 ElbowModel::ElbowModel(gvr::ControllerHandedness handedness) |
| 35 : handedness_(handedness), alpha_value_(1.0f), torso_direction_(kForward) {} | 35 : handedness_(handedness), alpha_value_(1.0f), torso_direction_(kForward) { |
| 36 UpdateHandedness(); |
| 37 } |
| 36 | 38 |
| 37 ElbowModel::~ElbowModel() = default; | 39 ElbowModel::~ElbowModel() = default; |
| 38 | 40 |
| 41 void ElbowModel::SetHandedness(gvr::ControllerHandedness handedness) { |
| 42 if (handedness == handedness_) |
| 43 return; |
| 44 handedness_ = handedness; |
| 45 UpdateHandedness(); |
| 46 } |
| 47 |
| 39 void ElbowModel::UpdateHandedness() { | 48 void ElbowModel::UpdateHandedness() { |
| 40 handed_multiplier_ = { | 49 handed_multiplier_ = { |
| 41 handedness_ == GVR_CONTROLLER_RIGHT_HANDED ? 1.0f : -1.0f, 1.0f, 1.0f}; | 50 handedness_ == GVR_CONTROLLER_RIGHT_HANDED ? 1.0f : -1.0f, 1.0f, 1.0f}; |
| 42 shoulder_rotation_ = kNoRotation; | 51 shoulder_rotation_ = kNoRotation; |
| 43 shoulder_position_ = | 52 shoulder_position_ = |
| 44 vr::ScalePoint(kDefaultShoulderRight, handed_multiplier_); | 53 vr::ScalePoint(kDefaultShoulderRight, handed_multiplier_); |
| 45 } | 54 } |
| 46 | 55 |
| 47 void ElbowModel::Update(const UpdateData& update) { | 56 void ElbowModel::Update(const UpdateData& update) { |
| 48 UpdateHandedness(); | |
| 49 UpdateTorsoDirection(update); | 57 UpdateTorsoDirection(update); |
| 50 ApplyArmModel(update); | 58 ApplyArmModel(update); |
| 51 UpdateTransparency(update); | 59 UpdateTransparency(update); |
| 52 } | 60 } |
| 53 | 61 |
| 54 void ElbowModel::UpdateTorsoDirection(const UpdateData& update) { | 62 void ElbowModel::UpdateTorsoDirection(const UpdateData& update) { |
| 55 auto head_direction = update.head_direction; | 63 auto head_direction = update.head_direction; |
| 56 head_direction.set_y(0); | 64 head_direction.set_y(0); |
| 57 vr::NormalizeVector(&head_direction); | 65 vr::NormalizeVector(&head_direction); |
| 58 | 66 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 void ElbowModel::UpdateTransparency(const UpdateData& update) { | 139 void ElbowModel::UpdateTransparency(const UpdateData& update) { |
| 132 float distance_to_face = vr::ToVector(wrist_position_).Length(); | 140 float distance_to_face = vr::ToVector(wrist_position_).Length(); |
| 133 float alpha_change = kDeltaAlpha * update.delta_time_seconds; | 141 float alpha_change = kDeltaAlpha * update.delta_time_seconds; |
| 134 alpha_value_ = vr::Clampf(distance_to_face < kFadeDistanceFromFace | 142 alpha_value_ = vr::Clampf(distance_to_face < kFadeDistanceFromFace |
| 135 ? alpha_value_ - alpha_change | 143 ? alpha_value_ - alpha_change |
| 136 : alpha_value_ + alpha_change, | 144 : alpha_value_ + alpha_change, |
| 137 0.0f, 1.0f); | 145 0.0f, 1.0f); |
| 138 } | 146 } |
| 139 | 147 |
| 140 } // namespace vr_shell | 148 } // namespace vr_shell |
| OLD | NEW |