mirror of
https://github.com/CrispyPin/sinpin-vr.git
synced 2024-11-10 04:20:25 +01:00
cleanup
This commit is contained in:
parent
00566021a0
commit
e73e9b12f8
4 changed files with 21 additions and 21 deletions
|
@ -28,7 +28,6 @@ struct Ray
|
||||||
{
|
{
|
||||||
Overlay *overlay;
|
Overlay *overlay;
|
||||||
float distance;
|
float distance;
|
||||||
// glm::vec3 pos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class App
|
class App
|
||||||
|
|
|
@ -98,7 +98,7 @@ void Controller::Update()
|
||||||
|
|
||||||
if (!_grabbed_overlays.empty())
|
if (!_grabbed_overlays.empty())
|
||||||
{
|
{
|
||||||
float move = _app->GetInputAnalog(_app->_input_handles.distance).y * 0.1; // TODO use frame time
|
float move = _app->GetInputAnalog(_app->_input_handles.distance, _input_handle).y * 0.1; // TODO use frame time
|
||||||
if (move != 0.0f)
|
if (move != 0.0f)
|
||||||
{
|
{
|
||||||
// delta is calculated & clamped for first overlay so that child overlays don't move further than the root
|
// delta is calculated & clamped for first overlay so that child overlays don't move further than the root
|
||||||
|
@ -108,8 +108,9 @@ void Controller::Update()
|
||||||
|
|
||||||
for (auto overlay : _grabbed_overlays)
|
for (auto overlay : _grabbed_overlays)
|
||||||
{
|
{
|
||||||
overlay->GetTarget()->transform.m[2][3] += real_delta;
|
auto transform = overlay->GetTarget()->transform;
|
||||||
_app->vr_overlay->SetOverlayTransformTrackedDeviceRelative(overlay->Id(), _device_index, &overlay->GetTarget()->transform);
|
transform.m[2][3] += real_delta;
|
||||||
|
overlay->SetTransformTracker(_device_index, &transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,25 +16,18 @@ Overlay::Overlay(App *app, std::string name)
|
||||||
_holding_controller = nullptr;
|
_holding_controller = nullptr;
|
||||||
_width_m = 1;
|
_width_m = 1;
|
||||||
_ratio = 1;
|
_ratio = 1;
|
||||||
|
_hidden = false;
|
||||||
|
|
||||||
_target.type = TargetType::World;
|
_target = Target{.type = TargetType::World, .transform = VRMatIdentity};
|
||||||
|
|
||||||
auto overlay_create_err = _app->vr_overlay->CreateOverlay(_name.c_str(), _name.c_str(), &_id);
|
auto overlay_create_err = _app->vr_overlay->CreateOverlay(_name.c_str(), _name.c_str(), &_id);
|
||||||
assert(overlay_create_err == 0);
|
assert(overlay_create_err == 0);
|
||||||
{
|
|
||||||
vr::ETrackingUniverseOrigin origin;
|
|
||||||
_app->vr_overlay->GetOverlayTransformAbsolute(_id, &origin, &_target.transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t col[4] = {20, 50, 50, 255};
|
|
||||||
_app->vr_overlay->SetOverlayRaw(_id, &col, 1, 1, 4);
|
|
||||||
printf("Created overlay instance %s\n", _name.c_str());
|
|
||||||
|
|
||||||
// (flipping uv on y axis because opengl and xorg are opposite)
|
// (flipping uv on y axis because opengl and xorg are opposite)
|
||||||
vr::VRTextureBounds_t bounds{0, 1, 1, 0};
|
vr::VRTextureBounds_t bounds{0, 1, 1, 0};
|
||||||
_app->vr_overlay->SetOverlayTextureBounds(_id, &bounds);
|
_app->vr_overlay->SetOverlayTextureBounds(_id, &bounds);
|
||||||
_hidden = false;
|
|
||||||
_app->vr_overlay->ShowOverlay(_id);
|
_app->vr_overlay->ShowOverlay(_id);
|
||||||
|
printf("Created overlay instance %s\n", _name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
OverlayID Overlay::Id()
|
OverlayID Overlay::Id()
|
||||||
|
@ -132,8 +125,7 @@ void Overlay::SetTransformWorld(const VRMat *transform)
|
||||||
void Overlay::SetTargetWorld()
|
void Overlay::SetTargetWorld()
|
||||||
{
|
{
|
||||||
auto abs_pose = ConvertMat(GetTransformAbsolute());
|
auto abs_pose = ConvertMat(GetTransformAbsolute());
|
||||||
_app->vr_overlay->SetOverlayTransformAbsolute(_id, vr::TrackingUniverseStanding, &abs_pose);
|
SetTransformWorld(&abs_pose);
|
||||||
_target.type = TargetType::World;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ray Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
|
Ray Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
|
||||||
|
@ -161,7 +153,7 @@ Ray Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
|
||||||
closest_dist = dist;
|
closest_dist = dist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ray{.overlay = this, .distance = closest_dist /* , .pos = p */};
|
return Ray{.overlay = this, .distance = closest_dist};
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4x4 Overlay::GetTransformAbsolute()
|
glm::mat4x4 Overlay::GetTransformAbsolute()
|
||||||
|
@ -221,14 +213,18 @@ void Overlay::Update()
|
||||||
|
|
||||||
void Overlay::ControllerGrab(Controller *controller)
|
void Overlay::ControllerGrab(Controller *controller)
|
||||||
{
|
{
|
||||||
|
if (_holding_controller != nullptr)
|
||||||
|
{
|
||||||
|
_holding_controller->ReleaseOverlay(this);
|
||||||
|
}
|
||||||
|
|
||||||
_app->vr_overlay->SetOverlayColor(_id, 0.6f, 0.8f, 0.8f);
|
_app->vr_overlay->SetOverlayColor(_id, 0.6f, 0.8f, 0.8f);
|
||||||
|
|
||||||
auto abs_mat = GetTransformAbsolute();
|
auto abs_mat = GetTransformAbsolute();
|
||||||
auto controller_mat = _app->GetTrackerPose(controller->DeviceIndex());
|
auto controller_mat = _app->GetTrackerPose(controller->DeviceIndex());
|
||||||
VRMat relative_pose = ConvertMat(glm::inverse(controller_mat) * abs_mat);
|
VRMat relative_pose = ConvertMat(glm::inverse(controller_mat) * abs_mat);
|
||||||
|
|
||||||
_app->vr_overlay->SetOverlayTransformTrackedDeviceRelative(_id, controller->DeviceIndex(), &relative_pose);
|
SetTransformTracker(controller->DeviceIndex(), &relative_pose);
|
||||||
_target.transform = relative_pose;
|
|
||||||
|
|
||||||
controller->RegisterGrabbedOverlay(this);
|
controller->RegisterGrabbedOverlay(this);
|
||||||
if (_GrabBeginCallback != nullptr)
|
if (_GrabBeginCallback != nullptr)
|
||||||
|
@ -240,12 +236,15 @@ void Overlay::ControllerGrab(Controller *controller)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Overlay::ControllerRelease()
|
void Overlay::ControllerRelease()
|
||||||
|
{
|
||||||
|
if (_holding_controller != nullptr)
|
||||||
{
|
{
|
||||||
_holding_controller->ReleaseOverlay(this);
|
_holding_controller->ReleaseOverlay(this);
|
||||||
|
}
|
||||||
_app->vr_overlay->SetOverlayColor(_id, 1.0f, 1.0f, 1.0f);
|
_app->vr_overlay->SetOverlayColor(_id, 1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
auto new_pose = ConvertMat(GetTransformAbsolute());
|
auto new_pose = ConvertMat(GetTransformAbsolute());
|
||||||
_app->vr_overlay->SetOverlayTransformAbsolute(_id, _app->_tracking_origin, &new_pose);
|
SetTransformWorld(&new_pose);
|
||||||
|
|
||||||
if (_GrabEndCallback != nullptr)
|
if (_GrabEndCallback != nullptr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,6 +23,7 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height)
|
||||||
_texture.eType = vr::TextureType_OpenGL;
|
_texture.eType = vr::TextureType_OpenGL;
|
||||||
_texture.handle = (void *)(uintptr_t)_gl_texture;
|
_texture.handle = (void *)(uintptr_t)_gl_texture;
|
||||||
_overlay.SetRatio(height / (float)width);
|
_overlay.SetRatio(height / (float)width);
|
||||||
|
_overlay.SetTextureToColor(50, 20, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::Update()
|
void Panel::Update()
|
||||||
|
|
Loading…
Reference in a new issue