color code lasers

This commit is contained in:
Crispy 2023-04-29 18:14:15 +02:00
parent d94e3040bb
commit d33eb40c69
6 changed files with 35 additions and 5 deletions

View file

@ -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();

View file

@ -4,7 +4,9 @@
#include "util.h"
#include <string>
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));
}

View file

@ -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;

View file

@ -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;

View file

@ -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();

View file

@ -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);