From d33eb40c694a0f68a10cd8970b8b836faae3f764 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 29 Apr 2023 18:14:15 +0200 Subject: [PATCH] color code lasers --- src/app.cpp | 5 +++++ src/controller.cpp | 12 ++++++++---- src/controller.h | 3 ++- src/overlay.cpp | 11 +++++++++++ src/overlay.h | 2 ++ src/util.h | 7 +++++++ 6 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 9d6acb2..f2f56af 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -199,6 +199,11 @@ void App::UpdateInput() { _edit_mode = !_edit_mode; UpdateUIVisibility(); + if (_edit_mode && _active_cursor.has_value()) + { + _active_cursor.value()->_cursor_active = false; + _active_cursor = {}; + } } } _controllers[0]->Update(); diff --git a/src/controller.cpp b/src/controller.cpp index d4cac9e..e4e8722 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -4,7 +4,9 @@ #include "util.h" #include -const float width = 0.004f; +const float laser_width = 0.004f; +const Color edit_col{1, 0.6f, 1}; +const Color cursor_col{0.3f, 1, 1}; Controller::Controller(App *app, ControllerSide side) { @@ -23,7 +25,7 @@ Controller::Controller(App *app, ControllerSide side) _laser = Overlay(app, laser_name); UpdateStatus(); - _laser.SetTextureToColor(255, 200, 255); + _laser.SetTextureToColor(255, 255, 255); _laser.SetAlpha(0.2f); _laser.SetHidden(true); } @@ -78,6 +80,7 @@ void Controller::Update() if (_app->_edit_mode) { + _laser.SetColor(edit_col); if (_last_ray.overlay != nullptr) { auto ray = _last_ray; @@ -106,7 +109,7 @@ void Controller::Update() } } } - else //view mode + else // cursor mode { if (_app->IsInputJustPressed(_app->_input_handles.cursor.activate, _input_handle)) { @@ -117,6 +120,7 @@ void Controller::Update() } _cursor_active = !_cursor_active; _app->_active_cursor = this; + _laser.SetColor(cursor_col); } if (_cursor_active) { @@ -166,7 +170,7 @@ void Controller::UpdateLaser() hmd_local_pos.z = 0; auto hmd_dir = glm::normalize(hmd_local_pos); - VRMat transform = {{{width * hmd_dir.y, 0, width * hmd_dir.x, 0}, {width * -hmd_dir.x, 0, width * hmd_dir.y, 0}, {0, len, 0, len * -0.5f}}}; + VRMat transform = {{{laser_width * hmd_dir.y, 0, laser_width * hmd_dir.x, 0}, {laser_width * -hmd_dir.x, 0, laser_width * hmd_dir.y, 0}, {0, len, 0, len * -0.5f}}}; _laser.SetTransformTracker(_device_index, &transform); _laser.SetHidden(!_is_connected || _app->_hidden || (!_app->_edit_mode && !_cursor_active)); } diff --git a/src/controller.h b/src/controller.h index 982a1b8..cf810d2 100644 --- a/src/controller.h +++ b/src/controller.h @@ -28,6 +28,8 @@ class Controller void Update(); + bool _cursor_active; + private: void UpdateStatus(); void UpdateLaser(); @@ -40,7 +42,6 @@ class Controller bool _is_connected; - bool _cursor_active; Overlay *_grabbed_overlay; Ray _last_ray; diff --git a/src/overlay.cpp b/src/overlay.cpp index 7f236e0..a35f61a 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -108,6 +108,17 @@ void Overlay::SetTextureToColor(uint8_t r, uint8_t g, uint8_t b) assert(set_texture_err == 0); } +void Overlay::SetColor(float r, float g, float b) +{ + auto set_color_err = _app->vr_overlay->SetOverlayColor(_id, r, g, b); + assert(set_color_err == 0); +} + +void Overlay::SetColor(Color c) +{ + SetColor(c.r, c.g, c.b); +} + void Overlay::SetTransformTracker(TrackerID tracker, const VRMat *transform) { auto original_pose = _target.transform; diff --git a/src/overlay.h b/src/overlay.h index c2ff311..67d110e 100644 --- a/src/overlay.h +++ b/src/overlay.h @@ -43,6 +43,8 @@ class Overlay void SetRatio(float ratio); void SetTexture(vr::Texture_t *texture); void SetTextureToColor(uint8_t r, uint8_t g, uint8_t b); + void SetColor(float r, float g, float b); + void SetColor(Color c); glm::mat4x4 GetTransformAbsolute(); Target *GetTarget(); diff --git a/src/util.h b/src/util.h index 2e510b8..ecb7484 100644 --- a/src/util.h +++ b/src/util.h @@ -20,6 +20,13 @@ struct Ray Panel *hit_panel; }; +struct Color +{ + float r; + float g; + float b; +}; + inline void PrintVec(glm::vec3 v) { printf("(%.2f, %.2f, %.2f)\n", v.x, v.y, v.z);