Index: chrome/browser/android/vr_shell/vr_shell_gl.cc |
diff --git a/chrome/browser/android/vr_shell/vr_shell_gl.cc b/chrome/browser/android/vr_shell/vr_shell_gl.cc |
index 04576097918cdeb873940654a892d8a31229dee4..b5cae58d5f22566b787c3ad694ca37381b33b421 100644 |
--- a/chrome/browser/android/vr_shell/vr_shell_gl.cc |
+++ b/chrome/browser/android/vr_shell/vr_shell_gl.cc |
@@ -48,15 +48,8 @@ static constexpr float kReticleHeight = 0.025f; |
static constexpr float kLaserWidth = 0.01f; |
-// Angle (radians) the beam down from the controller axis, for wrist comfort. |
-static constexpr float kErgoAngleOffset = 0.26f; |
- |
static constexpr gvr::Vec3f kOrigin = {0.0f, 0.0f, 0.0f}; |
-// In lieu of an elbow model, we assume a position for the user's hand. |
-// TODO(mthiesse): Handedness options. |
-static constexpr gvr::Vec3f kHandPosition = {0.2f, -0.5f, -0.2f}; |
- |
// Fraction of the distance to the object the cursor is drawn at to avoid |
// rounding errors drawing the cursor behind the object. |
static constexpr float kReticleOffset = 0.99f; |
@@ -469,15 +462,16 @@ void VrShellGl::InitializeRenderer() { |
FROM_HERE, base::Bind(&VrShell::GvrDelegateReady, weak_vr_shell_)); |
} |
-void VrShellGl::UpdateController() { |
- controller_->UpdateState(); |
+void VrShellGl::UpdateController(const gvr::Vec3f& head_direction) { |
+ controller_->UpdateState(head_direction); |
+ pointer_start_ = controller_->GetPointerStart(); |
device::GvrGamepadData pad = controller_->GetGamepadData(); |
main_thread_task_runner_->PostTask( |
FROM_HERE, base::Bind(&VrShell::UpdateGamepadData, weak_vr_shell_, pad)); |
} |
-void VrShellGl::HandleControllerInput(const gvr::Vec3f& forward_vector) { |
+void VrShellGl::HandleControllerInput(const gvr::Vec3f& head_direction) { |
if (ShouldDrawWebVr()) { |
// Process screen touch events for Cardboard button compatibility. |
// Also send tap events for controller "touchpad click" events. |
@@ -501,7 +495,7 @@ void VrShellGl::HandleControllerInput(const gvr::Vec3f& forward_vector) { |
// No controller detected, set up a gaze cursor that tracks the |
// forward direction. |
ergo_neutral_pose = {0.0f, 0.0f, -1.0f}; |
- controller_quat_ = GetRotationFromZAxis(forward_vector); |
+ controller_quat_ = GetRotationFromZAxis(head_direction); |
} else { |
ergo_neutral_pose = {0.0f, -sin(kErgoAngleOffset), -cos(kErgoAngleOffset)}; |
controller_quat_ = controller_->Orientation(); |
@@ -531,7 +525,7 @@ void VrShellGl::HandleControllerInput(const gvr::Vec3f& forward_vector) { |
// that the sphere is centered at the controller, rather than the eye, for |
// simplicity. |
float distance = scene_->GetBackgroundDistance(); |
- target_point_ = GetRayPoint(kHandPosition, controller_direction, distance); |
+ target_point_ = GetRayPoint(pointer_start_, controller_direction, distance); |
gvr::Vec3f eye_to_target = target_point_; |
NormalizeVector(eye_to_target); |
@@ -819,7 +813,7 @@ void VrShellGl::DrawFrame(int16_t frame_index) { |
// object_from_reference_matrix, we're not updating position_external. |
// TODO: Not sure what object_from_reference_matrix is. The new api removed |
// it. For now, removing it seems working fine. |
- gvr_api_->ApplyNeckModel(head_pose, 1.0f); |
+ head_pose = gvr_api_->ApplyNeckModel(head_pose, 1.0f); |
} |
// Update the render position of all UI elements (including desktop). |
@@ -829,8 +823,9 @@ void VrShellGl::DrawFrame(int16_t frame_index) { |
// TODO(crbug.com/704690): Acquire controller state in a way that's timely |
// for both the gamepad API and UI input handling. |
TRACE_EVENT0("gpu", "VrShellGl::UpdateController"); |
- UpdateController(); |
- HandleControllerInput(GetForwardVector(head_pose)); |
+ auto head_direction = GetForwardVector(head_pose); |
+ UpdateController(head_direction); |
+ HandleControllerInput(head_direction); |
} |
DrawWorldElements(head_pose); |
@@ -934,8 +929,8 @@ void VrShellGl::DrawUiView(const gvr::Mat4f& head_pose, |
DrawElements(render_matrix, elementsInDrawOrder); |
if (draw_cursor) { |
- DrawCursor(render_matrix); |
DrawController(render_matrix); |
+ DrawCursor(render_matrix); |
} |
} |
} |
@@ -1057,7 +1052,7 @@ void VrShellGl::DrawCursor(const gvr::Mat4f& render_matrix) { |
// Draw the laser. |
// Find the length of the beam (from hand to target). |
- const float laser_length = Distance(kHandPosition, target_point_); |
+ const float laser_length = Distance(pointer_start_, target_point_); |
// Build a beam, originating from the origin. |
SetIdentityM(mat); |
@@ -1070,12 +1065,13 @@ void VrShellGl::DrawCursor(const gvr::Mat4f& render_matrix) { |
const gvr::Quatf q = QuatFromAxisAngle({1.0f, 0.0f, 0.0f}, -M_PI / 2); |
mat = MatrixMul(QuatToMatrix(q), mat); |
- const gvr::Vec3f beam_direction = {target_point_.x - kHandPosition.x, |
- target_point_.y - kHandPosition.y, |
- target_point_.z - kHandPosition.z}; |
+ const gvr::Vec3f beam_direction = {target_point_.x - pointer_start_.x, |
+ target_point_.y - pointer_start_.y, |
+ target_point_.z - pointer_start_.z}; |
const gvr::Mat4f beam_direction_mat = |
QuatToMatrix(GetRotationFromZAxis(beam_direction)); |
+ float opacity = controller_->GetOpacity(); |
// Render multiple faces to make the laser appear cylindrical. |
const int faces = 4; |
for (int i = 0; i < faces; i++) { |
@@ -1088,20 +1084,21 @@ void VrShellGl::DrawCursor(const gvr::Mat4f& render_matrix) { |
face_transform = MatrixMul(beam_direction_mat, face_transform); |
// Move the beam origin to the hand. |
- TranslateM(face_transform, face_transform, kHandPosition.x, kHandPosition.y, |
- kHandPosition.z); |
+ TranslateM(face_transform, face_transform, pointer_start_.x, |
+ pointer_start_.y, pointer_start_.z); |
transform = MatrixMul(render_matrix, face_transform); |
- vr_shell_renderer_->GetLaserRenderer()->Draw(transform); |
+ vr_shell_renderer_->GetLaserRenderer()->Draw(opacity, transform); |
} |
} |
void VrShellGl::DrawController(const gvr::Mat4f& view_proj_matrix) { |
if (!vr_shell_renderer_->GetControllerRenderer()->IsSetUp()) |
return; |
- auto transform = MatrixMul(view_proj_matrix, controller_->GetTransform()); |
auto state = controller_->GetModelState(); |
- vr_shell_renderer_->GetControllerRenderer()->Draw(state, transform); |
+ auto opacity = controller_->GetOpacity(); |
+ auto transform = MatrixMul(view_proj_matrix, controller_->GetTransform()); |
+ vr_shell_renderer_->GetControllerRenderer()->Draw(state, opacity, transform); |
} |
bool VrShellGl::ShouldDrawWebVr() { |