fix depth export, improve VR UI interaction

This commit is contained in:
2019-06-02 14:10:01 +02:00
parent e5c7a35fd2
commit d8a1a99d04
6 changed files with 93 additions and 97 deletions

View File

@@ -1,12 +1,21 @@
#include "pch.h"
#include "app.h"
#include "util.h"
#include "shape.h"
#ifdef _WIN32
bool win32_vr_start();
void win32_vr_stop();
#endif
bool trigger_down = false;
cbuffer<glm::vec3> controller_points(10);
glm::vec3 controller_last_point;
const VRController* down_controller = nullptr;
glm::vec2 controller_cursor;
bool ui_inside = false;
bool ui_capture = false;
Sphere controller_ray;
bool App::vr_start()
{
@@ -41,12 +50,6 @@ void App::vr_draw_ui()
uirtt.unbindFramebuffer();
}
bool trigger_down = false;
cbuffer<glm::vec3> controller_points(10);
glm::vec3 controller_last_point;
const VRController* down_controller = nullptr;
glm::vec2 controller_cursor;
bool ui_inside = false;
void App::vr_update(float dt)
{
glm::vec3 hit;
@@ -56,27 +59,25 @@ void App::vr_update(float dt)
auto r = m * glm::vec3(1, 0, 0);
auto n = m * glm::vec3(0, 0, 1);
auto u = m * glm::vec3(0, 1, 0);
if (ray_intersect({ 0, 0, 0 }, vr_controllers[0].get_pos_n(), o, n, r, hit, t))
auto co = vr_controllers[0].get_pos();
auto cd = co + glm::mat3(vr_controllers[0].m_mat) * glm::vec3(0, 0, -1);
ui_inside = false;
if (ray_intersect(co, cd, o, n, r, hit, t))
{
glm::mat4 plane_camera = glm::lookAt(o, n, u);
glm::vec4 plane_local = plane_camera * glm::vec4(hit, 1);
if (glm::all(glm::lessThanEqual(glm::abs(xy(plane_local)), glm::vec2(1.5f))))
glm::vec4 plane_local = (plane_camera * glm::vec4(hit, 1)) * 2.f;
if (glm::all(glm::lessThanEqual(glm::abs(xy(plane_local)), glm::vec2(1.0f))))
{
controller_cursor.x = -(plane_local.x * 0.5f - 0.5f) * width;
controller_cursor.y = height - (plane_local.y * 0.5f + 0.5f) * height - 1;
async_start();
mouse_move(controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false);
async_end();
ui_inside = true;
if (!down_controller && ui_visible)
{
async_start();
mouse_move(controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false);
async_end();
ui_inside = true;
}
}
else
{
ui_inside = false;
}
}
else
{
ui_inside = false;
}
if (down_controller)
@@ -98,22 +99,40 @@ void App::vr_analog(const VRController& c, VRController::kButton b, VRController
{
if (b == VRController::kButton::Trigger)
{
if (a == VRController::kAction::Press)
if (!down_controller && (ui_inside || ui_capture) && ui_visible)
{
glm::vec3 pos = c.get_pos_n() * 800.f;
async_start();
Canvas::I->stroke_start(pos, force.x);
if (a == VRController::kAction::Press)
{
mouse_down(0, controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false);
ui_capture = true;
}
else
{
mouse_up(0, controller_cursor.x, controller_cursor.y, kEventSource::Mouse, false);
ui_capture = false;
}
async_end();
controller_last_point = pos;
controller_points.clear();
down_controller = &c;
}
if (a == VRController::kAction::Release)
else
{
down_controller = nullptr;
async_start();
Canvas::I->stroke_end();
async_end();
if (a == VRController::kAction::Press)
{
glm::vec3 pos = c.get_pos_n() * 800.f;
async_start();
Canvas::I->stroke_start(pos, force.x);
async_end();
controller_last_point = pos;
controller_points.clear();
down_controller = &c;
}
if (a == VRController::kAction::Release)
{
down_controller = nullptr;
async_start();
Canvas::I->stroke_end();
async_end();
}
}
}
}
@@ -129,15 +148,6 @@ void App::vr_digital(const VRController& c, VRController::kButton b, VRControlle
toggle_ui();
}
}
if (b == VRController::kButton::A)
{
async_start();
if (a == VRController::kAction::Press)
mouse_down(0, controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false);
else
mouse_up(0, controller_cursor.x, controller_cursor.y, kEventSource::Mouse, false);
async_end();
}
}
void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat4& pose)
@@ -299,7 +309,7 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
}
}
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)) * 0.5f;
glm::vec3 aspect = { (float)uirtt.getWidth() / (float)uirtt.getHeight(), 1.f, 1.f };
// draw the frame
@@ -419,22 +429,22 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
tex.unbind();
}
/*
for (auto& mode : *m_canvas->m_mode)
glm::mat4 ortho_proj(1);
for (auto& mode : *canvas->m_canvas->m_mode)
mode->on_Draw(ortho_proj, proj, camera);
glDisable(GL_DEPTH_TEST);
if (m_canvas->m_smask_active)
if (canvas->m_canvas->m_smask_active)
{
m_canvas->modes[(int)kCanvasMode::MaskFree][0]->on_Draw(ortho_proj, proj, camera);
m_canvas->modes[(int)kCanvasMode::MaskLine][0]->on_Draw(ortho_proj, proj, camera);
canvas->m_canvas->modes[(int)kCanvasMode::MaskFree][0]->on_Draw(ortho_proj, proj, camera);
canvas->m_canvas->modes[(int)kCanvasMode::MaskLine][0]->on_Draw(ortho_proj, proj, camera);
}
// keep drawing the grids
if (m_canvas->m_state != kCanvasMode::Grid)
if (canvas->m_canvas->m_current_mode != kCanvasMode::Grid)
for (auto& mode : Canvas::modes[(int)kCanvasMode::Grid])
mode->on_Draw(ortho_proj, proj, camera);
*/
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
depth ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);