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

@@ -24,7 +24,8 @@ struct QuestController : public VRController
vrapi_GetInputTrackingState(ovr_context, id, predictedDisplayTime, &tracking);
glm::vec3 c_pos = glm::make_vec3((float*)&tracking.HeadPose.Pose.Position) - head_pos;
auto c_rot_ovr = ovrMatrix4f_CreateFromQuaternion(&tracking.HeadPose.Pose.Orientation);
glm::mat4 c_rot = glm::make_mat4((float*)&c_rot_ovr);
auto c_rot_ovr_tp = ovrMatrix4f_Transpose(&c_rot_ovr);
glm::mat4 c_rot = glm::make_mat4((float*)&c_rot_ovr_tp);
m_mat = glm::translate(c_pos) * c_rot;
// update controllers

View File

@@ -1747,20 +1747,10 @@ Here's a list of what's available in this release.
<scroll id="drop-left" color="0 0 0 .6" min-width="10" mouse-capture="true" rtl="ltr"/>
<!--quick bar-->
<node justify="center" align="center" dir="col" rtl="ltr">
<panel-quick id="panel-quick"/>
<node height="0" grow="1" max-height="50"/>
</node>
<node id="floatings" color="0 0 0 1" width="1" grow="1" height="100%" rtl="ltr"/>
<scroll id="drop-right" color="0 0 0 .6" min-width="10" mouse-capture="true" rtl="ltr"/>
<node dir="col" width="1" grow="1">
<!-- timeline -->
<!--
<node height="100%" width="1" grow="1" dir="col" justify="flex-start" rtl="ltr">
<border color=".3 .3 .3 .4" height="50" width="100%" pad="10" dir="row">
<node width="100%" shrink="1" dir="col" rtl="ltr">
<border color=".3 .3 .3 .4" height="50" width="100%" pad="10" dir="row" mouse-capture="true">
<text text="Timeline: " margin="8 10 0 0"/>
<slider-h id="frames-slider" width="1" grow="1" margin="0 10 0 0"></slider-h>
<node width="30" margin="5 10 0 10">
@@ -1768,7 +1758,18 @@ Here's a list of what's available in this release.
</node>
</border>
</node>
-->
<node dir="row" height="200" grow="1">
<!--quick bar-->
<node justify="center" align="center" dir="col" rtl="ltr">
<panel-quick id="panel-quick"/>
<node height="0" grow="1" max-height="50"/>
</node>
<!--floating area-->
<node id="floatings" color="0 0 0 1" width="1" grow="1" height="100%" rtl="ltr"/>
</node>
</node>
<scroll id="drop-right" color="0 0 0 .6" min-width="10" mouse-capture="true" rtl="ltr"/>
<!--<node height="100%" width="1" grow="1" dir="col" align="center" justify="flex-start" rtl="ltr">
<border border-color="0 0 0 0" thickness="2" color=".2 .2 .2 .6" pad="10" dir="row" margin="2 0 0 0">

View File

@@ -210,34 +210,29 @@ void App::init_sidebar()
layers->on_layer_opacity_changed = [this](Node*, int idx, float value) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_opacity = value;
canvas->m_canvas->m_unsaved = true;
canvas->m_canvas->draw_merge();
title_update();
};
layers->on_layer_visibility_changed = [this](Node*, int idx, bool visible) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_visible = visible;
canvas->m_canvas->m_unsaved = true;
canvas->m_canvas->draw_merge();
title_update();
};
layers->on_layer_alpha_lock_changed = [this](Node*, int idx, bool locked) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_alpha_locked = locked;
canvas->m_canvas->m_unsaved = true;
canvas->m_canvas->draw_merge();
title_update();
};
layers->on_layer_blend_mode_changed = [this](Node*, int idx, int mode) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_blend_mode = mode;
canvas->m_canvas->m_unsaved = true;
canvas->m_canvas->draw_merge();
title_update();
};
layers->on_layer_highlight_changed = [this](Node*, int idx, bool highlight) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_hightlight = highlight;
canvas->m_canvas->draw_merge();
};
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-stroke"))
{

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,28 +59,26 @@ 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;
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)
{
@@ -97,6 +98,23 @@ void App::vr_update(float dt)
void App::vr_analog(const VRController& c, VRController::kButton b, VRController::kAction a, glm::vec2 force)
{
if (b == VRController::kButton::Trigger)
{
if (!down_controller && (ui_inside || ui_capture) && ui_visible)
{
async_start();
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();
}
else
{
if (a == VRController::kAction::Press)
{
@@ -117,6 +135,7 @@ 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)
{
@@ -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);

View File

@@ -143,13 +143,11 @@ void Canvas::clear(const glm::vec4& c/*={0,0,0,1}*/)
snap_history({ 0, 1, 2, 3, 4, 5 });
m_layers[m_current_layer_idx]->clear(c);
m_unsaved = true;
draw_merge();
}
void Canvas::clear_all()
{
for (auto& l : m_layers)
l->clear({0, 0, 0, 0});
draw_merge();
}
void Canvas::snap_history(const std::vector<int>& planes)
{
@@ -630,8 +628,6 @@ void Canvas::stroke_draw()
stroke_commit();
m_current_stroke = nullptr;
}
draw_merge(merge_faces);
}
bool Canvas::point_trace(glm::vec2 loc, glm::vec3& ray_origin, glm::vec3& ray_dir,
glm::vec3& hit_pos, glm::vec2& fb_pos, glm::vec3& hit_normal, int& out_plane_id)
@@ -897,13 +893,10 @@ void Canvas::stroke_commit()
action->m_canvas = this;
//action->m_stroke = std::move(m_current_stroke);
ActionManager::add(action);
draw_merge();
}
void Canvas::draw_merge(std::array<bool, 6> faces /*= SIXPLETTE(false)*/)
{
return;
gl_state gl;
gl.save();
glViewport(0, 0, m_width, m_height);
@@ -1237,7 +1230,6 @@ void Canvas::layer_add(std::string name)
m_layers.back()->create(m_width, m_height, name);
m_order.push_back(idx);
m_current_layer_idx = idx;
draw_merge();
}
void Canvas::layer_remove(int idx) // m_order index
{
@@ -1249,12 +1241,10 @@ void Canvas::layer_remove(int idx) // m_order index
m_layers.erase(m_layers.begin() + n);
m_order.erase(m_order.begin() + idx);
m_current_layer_idx = m_order[std::min<int>((int)m_layers.size() - 1, idx)];
draw_merge();
}
void Canvas::layer_order(int idx, int pos) // m_order index
{
std::swap(m_order[idx], m_order[pos]);
draw_merge();
}
void Canvas::layer_merge(int source_idx, int dest_idx) // m_layer index
{
@@ -1347,7 +1337,6 @@ void Canvas::layer_merge(int source_idx, int dest_idx) // m_layer index
action->m_stroke = std::move(m_current_stroke);
ActionManager::add(action);
*/
draw_merge();
}
void Canvas::resize(int width, int height)
{
@@ -1367,12 +1356,12 @@ void Canvas::resize(int width, int height)
//#endif
m_tex2[i].create(width, height, GL_RGBA8);
}
m_layers_merge.resize(width, height);
for (auto& l : m_layers)
l->resize(width, height);
m_smask.create(width, height, "mask");
//m_merge_rtt.create(width, height);
//m_merge_tex.create(width, height);
m_layers_merge.resize(width, height);
m_merge_rtt.create(width, height);
m_merge_tex.create(width, height);
m_unsaved = true;
}
@@ -1385,13 +1374,13 @@ void Canvas::destroy()
m_tex[i].destroy();
m_tex2[i].destroy();
}
m_layers_merge.destroy();
for (auto& l : m_layers)
l->destroy();
m_smask.destroy();
m_mixer.destroy();
//m_merge_rtt.destroy();
//m_merge_tex.destroy();
m_layers_merge.destroy();
m_merge_rtt.destroy();
m_merge_tex.destroy();
}
bool Canvas::create(int width, int height)
@@ -1432,15 +1421,14 @@ bool Canvas::create(int width, int height)
m_brush_shape.create();
m_mesh.create();
m_brush_mix.create(8, 8);
m_layers_merge.create(width, height, "merge");
for (auto& l : m_layers)
l->create(width, height, "");
m_smask.create(width, height, "mask");
//m_smask.clear({1, 1, 1, 1});
//m_merge_rtt.create(width, height);
//m_merge_tex.create(width, height);
m_layers_merge.create(width, height, "merge");
m_merge_rtt.create(width, height);
m_merge_tex.create(width, height);
m_unsaved = true;
draw_merge();
return true;
}
@@ -1871,6 +1859,8 @@ void Canvas::export_depth_thread(std::string file_name)
gl_state gl;
gl.save();
draw_merge();
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);

View File

@@ -1339,7 +1339,6 @@ void CanvasModeTransform::leave(kCanvasMode next)
layer->optimize();
//auto m = static_cast<CanvasModeMaskFree*>(Canvas::I->modes[(int)kCanvasMode::MaskFree][0]);
//m->clear();
Canvas::I->draw_merge();
}
void CanvasModeTransform::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const glm::mat4& camera)