make grabbable area a box instead of sphere, colour grabbed panels

This commit is contained in:
Crispy 2023-04-07 20:49:09 +02:00
parent 1770dd6e26
commit 2c120f462f
3 changed files with 29 additions and 11 deletions

View file

@ -15,6 +15,7 @@ Panel::Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int x, int y, in
{ {
_name = "screen_view_" + std::to_string(index); _name = "screen_view_" + std::to_string(index);
_alpha = 1.0f; _alpha = 1.0f;
_meters = 1.0f;
_active_hand = -1; _active_hand = -1;
glGenTextures(1, &_gl_texture); glGenTextures(1, &_gl_texture);
glBindTexture(GL_TEXTURE_2D, _gl_texture); glBindTexture(GL_TEXTURE_2D, _gl_texture);
@ -52,22 +53,29 @@ void Panel::Update()
if (!_is_held) if (!_is_held)
{ {
for (auto controller : _app->GetControllers()) for (auto controller : _app->GetControllers())
{
if (_app->IsGrabActive(controller))
{ {
vr::HmdMatrix34_t overlay_pose; vr::HmdMatrix34_t overlay_pose;
vr::ETrackingUniverseOrigin tracking_universe; vr::ETrackingUniverseOrigin tracking_universe;
_app->vr_overlay->GetOverlayTransformAbsolute(_id, &tracking_universe, &overlay_pose); _app->vr_overlay->GetOverlayTransformAbsolute(_id, &tracking_universe, &overlay_pose);
auto controller_pos = GetPos(_app->GetTrackerPose(controller)); auto controller_pos = GetPos(_app->GetTrackerPose(controller));
auto overlay_pos = GetPos(ConvertMat(overlay_pose));
bool close_enough = glm::length(overlay_pos - controller_pos) < 1.0f; auto local_pos = glm::inverse(ConvertMat(overlay_pose)) * glm::vec4(controller_pos - GetPos(overlay_pose), 0);
if (close_enough && _app->IsGrabActive(controller)) float grab_area_thickness = 0.3f;
bool close_enough = glm::abs(local_pos.z) < grab_area_thickness;
close_enough &= glm::abs(local_pos.x) < _meters / 2.0f;
close_enough &= glm::abs(local_pos.y) < _meters / 2.0f;
if (close_enough)
{ {
ControllerGrab(controller); ControllerGrab(controller);
} }
} }
} }
}
else else
{ {
if (!_app->IsGrabActive(_active_hand)) if (!_app->IsGrabActive(_active_hand))
@ -116,6 +124,8 @@ void Panel::ControllerGrab(TrackerID controller)
_is_held = true; _is_held = true;
_active_hand = controller; _active_hand = controller;
_app->vr_overlay->SetOverlayColor(_id, 0.6f, 1.0f, 1.0f);
vr::HmdMatrix34_t abs_pose; vr::HmdMatrix34_t abs_pose;
vr::ETrackingUniverseOrigin tracking_universe; vr::ETrackingUniverseOrigin tracking_universe;
@ -134,6 +144,8 @@ void Panel::ControllerRelease()
printf("Released panel %d\n", _index); printf("Released panel %d\n", _index);
_is_held = false; _is_held = false;
_app->vr_overlay->SetOverlayColor(_id, 1.0f, 1.0f, 1.0f);
vr::HmdMatrix34_t relative_pose; vr::HmdMatrix34_t relative_pose;
_app->vr_overlay->GetOverlayTransformTrackedDeviceRelative(_id, &_active_hand, &relative_pose); _app->vr_overlay->GetOverlayTransformTrackedDeviceRelative(_id, &_active_hand, &relative_pose);
auto relative_mat = ConvertMat(relative_pose); auto relative_mat = ConvertMat(relative_pose);

View file

@ -30,6 +30,7 @@ class Panel
int _x, _y; int _x, _y;
int _width, _height; int _width, _height;
float _meters;
float _alpha; float _alpha;
vr::Texture_t _texture; vr::Texture_t _texture;

View file

@ -46,3 +46,8 @@ inline glm::vec3 GetPos(glm::mat4x4 mat)
{ {
return glm::vec3(mat[3][0], mat[3][1], mat[3][2]); return glm::vec3(mat[3][0], mat[3][1], mat[3][2]);
} }
inline glm::vec3 GetPos(vr::HmdMatrix34_t mat)
{
return glm::vec3(mat.m[0][3], mat.m[1][3], mat.m[2][3]);
}