fix vr controllers interfering with screen drawing

This commit is contained in:
2020-11-07 23:03:03 +01:00
parent 5394cbf8c3
commit ce6805f261
6 changed files with 36 additions and 5 deletions

View File

@@ -272,6 +272,10 @@
<checkbox id="tools-vr-check" width="20" height="20"/> <checkbox id="tools-vr-check" width="20" height="20"/>
<text text="Enable VR" margin="0 0 0 5"/> <text text="Enable VR" margin="0 0 0 5"/>
</button-custom> </button-custom>
<button-custom id="tools-vr-controllers" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<checkbox id="tools-vr-controllers-check" width="20" height="20"/>
<text text="Enable VR Controllers" margin="0 0 0 5"/>
</button-custom>
<button-custom id="tools-timelapse" height="40" align="center" color=".2" pad="0 0 0 10" dir="row"> <button-custom id="tools-timelapse" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<checkbox id="tools-timelapse-check" width="20" height="20"/> <checkbox id="tools-timelapse-check" width="20" height="20"/>
<text text="Auto Timelapse" margin="0 0 0 5"/> <text text="Auto Timelapse" margin="0 0 0 5"/>

View File

@@ -472,6 +472,7 @@ void App::init()
if (Settings::value_or<Serializer::Boolean>("auto-timelapse", true)) if (Settings::value_or<Serializer::Boolean>("auto-timelapse", true))
rec_start(); rec_start();
Settings::value<Serializer::Boolean>("vr-controllers-enabled", vr_controllers_enabled);
if (!check_license()) if (!check_license())
{ {

View File

@@ -132,6 +132,7 @@ public:
std::string doc_filename; std::string doc_filename;
bool has_stylus = false; bool has_stylus = false;
bool has_vr = false; bool has_vr = false;
bool vr_controllers_enabled = true;
float off_x = 0; float off_x = 0;
float off_y = 0; float off_y = 0;
float width; float width;

View File

@@ -1004,6 +1004,25 @@ void App::init_menu_tools()
}; };
} }
if (auto vr_btn = popup_time->find<NodeButtonCustom>("tools-vr-controllers"))
{
NodeCheckBox* cb = vr_btn->find<NodeCheckBox>("tools-vr-controllers-check");
cb->set_value(vr_controllers_enabled);
vr_btn->on_click = [this, vr_btn](Node* b)
{
NodeCheckBox* cb = vr_btn->find<NodeCheckBox>("tools-vr-controllers-check");
cb->set_value(!cb->checked, true);
};
vr_btn->find<NodeCheckBox>("tools-vr-controllers-check")->on_value_changed = [this, main](Node* target, bool checked)
{
vr_controllers_enabled = checked;
Settings::set("vr-controllers-enabled", Serializer::Boolean(checked));
Settings::save();
};
}
if (auto btn = popup_time->find<NodeButtonCustom>("tools-timelapse")) if (auto btn = popup_time->find<NodeButtonCustom>("tools-timelapse"))
{ {
NodeCheckBox* cb = btn->find<NodeCheckBox>("tools-timelapse-check"); NodeCheckBox* cb = btn->find<NodeCheckBox>("tools-timelapse-check");

View File

@@ -49,6 +49,8 @@ void App::vr_draw_ui()
void App::vr_update(float dt) void App::vr_update(float dt)
{ {
if (!vr_controllers_enabled)
return;
canvas->m_canvas->m_cam_fov = 60; canvas->m_canvas->m_cam_fov = 60;
float tan_fov = glm::tan(glm::radians(canvas->m_canvas->m_cam_fov / 2.f)); float tan_fov = glm::tan(glm::radians(canvas->m_canvas->m_cam_fov / 2.f));
glm::vec3 aspect = { (float)uirtt.getWidth() / (float)uirtt.getHeight(), 1.f, 1.f }; glm::vec3 aspect = { (float)uirtt.getWidth() / (float)uirtt.getHeight(), 1.f, 1.f };
@@ -106,6 +108,8 @@ void App::vr_update(float dt)
void App::vr_analog(const VRController& c, VRController::kButton b, VRController::kAction a, glm::vec2 force) void App::vr_analog(const VRController& c, VRController::kButton b, VRController::kAction a, glm::vec2 force)
{ {
if (!vr_controllers_enabled)
return;
if (b == VRController::kButton::Trigger) if (b == VRController::kButton::Trigger)
{ {
if (!down_controller && (ui_inside || ui_capture) && ui_visible) if (!down_controller && (ui_inside || ui_capture) && ui_visible)
@@ -151,6 +155,8 @@ void App::vr_analog(const VRController& c, VRController::kButton b, VRController
void App::vr_digital(const VRController& c, VRController::kButton b, VRController::kAction a, glm::vec2 axis) void App::vr_digital(const VRController& c, VRController::kButton b, VRController::kAction a, glm::vec2 axis)
{ {
if (!vr_controllers_enabled)
return;
if ((b == VRController::kButton::A || b == VRController::kButton::Menu || b == VRController::kButton::Pad) if ((b == VRController::kButton::A || b == VRController::kButton::Menu || b == VRController::kButton::Pad)
&& a == VRController::kAction::Press) && a == VRController::kAction::Press)
{ {
@@ -400,7 +406,7 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
} }
// draw the cursor // draw the cursor
if (ui_visible && ui_inside) if (ui_visible /*&& ui_inside*/)
{ {
auto cur = (glm::vec2(cursor.x / width * zoom, 1.f - cursor.y / height * zoom) - 0.5f) * 2.f; auto cur = (glm::vec2(cursor.x / width * zoom, 1.f - cursor.y / height * zoom) - 0.5f) * 2.f;
auto mvp = proj * camera * auto mvp = proj * camera *
@@ -418,7 +424,7 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
// draw the motion controller sphere // draw the motion controller sphere
if (ui_visible && ui_inside) if (vr_controllers_enabled && ui_visible && ui_inside)
{ {
auto mvp = proj * camera * vr_controllers[0].m_mat; auto mvp = proj * camera * vr_controllers[0].m_mat;
ShaderManager::use(kShader::Color); ShaderManager::use(kShader::Color);
@@ -429,7 +435,7 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
// draw the motion controller brush // draw the motion controller brush
if (!ui_visible || !ui_inside) if (vr_controllers_enabled && (!ui_visible || !ui_inside))
{ {
glm::vec3 cpos = vr_controllers[0].get_pos() - xyz(pose[3]); glm::vec3 cpos = vr_controllers[0].get_pos() - xyz(pose[3]);
auto pos = glm::translate(glm::normalize(cpos) * 100.f); auto pos = glm::translate(glm::normalize(cpos) * 100.f);