Index: chrome/browser/android/vr_shell/vr_controller.cc |
diff --git a/chrome/browser/android/vr_shell/vr_controller.cc b/chrome/browser/android/vr_shell/vr_controller.cc |
index b64671687be12e2dc4d8823ac6d5ef4400fd27f2..efbece142e203b729eb728fb7554ce9df5df4845 100644 |
--- a/chrome/browser/android/vr_shell/vr_controller.cc |
+++ b/chrome/browser/android/vr_shell/vr_controller.cc |
@@ -9,6 +9,7 @@ |
#include <utility> |
#include "base/logging.h" |
+#include "base/memory/ptr_util.h" |
#include "base/time/time.h" |
#include "chrome/browser/android/vr_shell/vr_math.h" |
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr.h" |
@@ -41,8 +42,6 @@ constexpr float kNanoSecondsPerSecond = 1.0e9f; |
constexpr int kMaxNumOfExtrapolations = 2; |
-static constexpr gvr::Vec3f kControllerPosition = {0.2f, -0.5f, -0.15f}; |
- |
class Vector { |
public: |
static inline void ClampTouchpadPosition(gvr::Vec2f* position) { |
@@ -87,7 +86,10 @@ class Vector { |
VrController::VrController(gvr_context* vr_context) { |
DVLOG(1) << __FUNCTION__ << "=" << this; |
Initialize(vr_context); |
+ elbow_model_ = base::MakeUnique<ElbowModel>(handedness_); |
Reset(); |
+ last_timestamp_nanos_ = |
+ gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; |
} |
VrController::~VrController() { |
@@ -137,19 +139,20 @@ gvr::Quatf VrController::Orientation() const { |
} |
gvr::Mat4f VrController::GetTransform() const { |
- // TODO(acondor): Position and orientation needs to be obtained |
- // from an elbow model. |
- // Placing the controller in a fixed position for now. |
- gvr::Mat4f mat; |
- SetIdentityM(mat); |
- // Changing rotation point. |
- TranslateM(mat, mat, 0, 0, 0.05); |
- mat = MatrixMul(QuatToMatrix(Orientation()), mat); |
- TranslateM(mat, mat, kControllerPosition.x, kControllerPosition.y, |
- kControllerPosition.z - 0.05); |
+ auto mat = QuatToMatrix(elbow_model_->GetControllerRotation()); |
+ auto position = elbow_model_->GetControllerPosition(); |
+ TranslateM(mat, mat, position.x, position.y, position.z); |
return mat; |
} |
+float VrController::GetOpacity() const { |
+ return elbow_model_->GetAlphaValue(); |
+} |
+ |
+gvr::Vec3f VrController::GetPointerStart() const { |
+ return elbow_model_->GetControllerPosition(); |
+} |
+ |
VrControllerModel::State VrController::GetModelState() const { |
if (ButtonState(gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) |
return VrControllerModel::TOUCHPAD; |
@@ -184,7 +187,7 @@ bool VrController::IsConnected() { |
return controller_state_->GetConnectionState() == gvr::kControllerConnected; |
} |
-void VrController::UpdateState() { |
+void VrController::UpdateState(const gvr::Vec3f& head_direction) { |
const int32_t old_status = controller_state_->GetApiStatus(); |
const int32_t old_connection_state = controller_state_->GetConnectionState(); |
// Read current controller state. |
@@ -196,6 +199,14 @@ void VrController::UpdateState() { |
<< gvr_controller_connection_state_to_string( |
controller_state_->GetConnectionState()); |
} |
+ |
+ float delta_time_seconds = |
asimjour1
2017/04/19 18:58:12
this conversion is repeated a few times, could you
acondor_
2017/04/21 21:04:32
Done.
|
+ (gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos - |
+ last_timestamp_nanos_) / |
+ kNanoSecondsPerSecond; |
+ elbow_model_->Update({IsConnected(), Orientation(), |
+ controller_state_->GetGyro(), head_direction, |
+ delta_time_seconds}); |
} |
void VrController::UpdateTouchInfo() { |