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

Unified Diff: chrome/browser/android/vr_shell/vr_shell.cc

Issue 2392333003: Incorporate 15 degree laser beam angle on pointer. (Closed)
Patch Set: Address comments; improve CL description; improve naming; avoid a duplicate calculation. Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/vr_shell/vr_shell.cc
diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc
index b8e905c54b031b67f5dfcf52816416821b05361c..f9413821f5252d93b4e339cb8d3f33392a03f746 100644
--- a/chrome/browser/android/vr_shell/vr_shell.cc
+++ b/chrome/browser/android/vr_shell/vr_shell.cc
@@ -49,11 +49,8 @@ static constexpr float kReticleHeight = 0.025f;
static constexpr float kLaserWidth = 0.01f;
-// The neutral direction is fixed in world space, this is the
-// reference angle pointing forward towards the horizon when the
-// controller orientation is reset. This should match the yaw angle
-// where the main screen is placed.
-static constexpr gvr::Vec3f kNeutralPose = {0.0f, 0.0f, -1.0f};
+// 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};
@@ -239,16 +236,19 @@ void VrShell::UpdateController(const gvr::Vec3f& forward_vector) {
}
WebInputEvent::Type original_type = gesture->type;
+ gvr::Vec3f ergo_neutral_pose;
if (!controller_->IsConnected()) {
// 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);
} else {
+ ergo_neutral_pose = {0.0f, -sin(kErgoAngleOffset), -cos(kErgoAngleOffset)};
controller_quat_ = controller_->Orientation();
}
gvr::Mat4f mat = QuatToMatrix(controller_quat_);
- gvr::Vec3f forward = MatrixVectorMul(mat, kNeutralPose);
+ gvr::Vec3f forward = MatrixVectorMul(mat, ergo_neutral_pose);
gvr::Vec3f origin = kHandPosition;
target_element_ = nullptr;
@@ -509,7 +509,7 @@ void VrShell::DrawCursor(const gvr::Mat4f& render_matrix) {
// Draw the laser.
// Find the length of the beam (from hand to target).
- float laser_length = Distance(kHandPosition, target_point_);
+ const float laser_length = Distance(kHandPosition, target_point_);
// Build a beam, originating from the origin.
SetIdentityM(mat);
@@ -519,18 +519,36 @@ void VrShell::DrawCursor(const gvr::Mat4f& render_matrix) {
ScaleM(mat, mat, kLaserWidth, laser_length, 1);
// Tip back 90 degrees to flat, pointing at the scene.
- auto q = QuatFromAxisAngle({1.0f, 0.0f, 0.0f}, -M_PI / 2);
- auto m = QuatToMatrix(q);
- mat = MatrixMul(m, mat);
-
- // Orient according to controller position.
- mat = MatrixMul(QuatToMatrix(controller_quat_), mat);
-
- // Move the beam origin to the hand.
- TranslateM(mat, mat, kHandPosition.x, kHandPosition.y, kHandPosition.z);
-
- transform = MatrixMul(render_matrix, mat);
- vr_shell_renderer_->GetLaserRenderer()->Draw(transform);
+ 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::Mat4f beam_direction_mat =
cjgrant 2016/10/06 15:07:51 I was recomputing the matrix in the loop (needless
+ QuatToMatrix(GetRotationFromZAxis(beam_direction));
+
+
+ // Render multiple faces to make the laser appear cylindrical.
+ const int faces = 4;
+ for (int i = 0; i < faces; i++) {
+ // Rotate around Z.
+ const float angle = M_PI * 2 * i / faces;
+ const gvr::Quatf rot = QuatFromAxisAngle({0.0f, 0.0f, 1.0f}, angle);
+ gvr::Mat4f face_transform = MatrixMul(QuatToMatrix(rot), mat);
+
+ // Orient according to target direction.
+ 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);
+
+ transform = MatrixMul(render_matrix, face_transform);
+ vr_shell_renderer_->GetLaserRenderer()->Draw(transform);
+ }
}
void VrShell::DrawWebVr() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698