hmd orient, vr ui
This commit is contained in:
31
src/app.cpp
31
src/app.cpp
@@ -365,7 +365,8 @@ void App::init()
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
#endif
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
//glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendEquationSeparate(GL_FUNC_ADD, GL_MAX);
|
||||
|
||||
initShaders();
|
||||
initAssets();
|
||||
@@ -492,18 +493,38 @@ void App::update(float dt)
|
||||
}
|
||||
return false;
|
||||
};
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
uirtt.bindFramebuffer();
|
||||
uirtt.clear();
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
for (int i = 1; i < layout[main_id]->m_children.size(); i++)
|
||||
layout[main_id]->m_children[i]->watch(observer);
|
||||
//msgbox->watch(observer);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
uirtt.unbindFramebuffer();
|
||||
|
||||
#if __IOS__
|
||||
[ios_view->glview bindDrawable];
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#endif
|
||||
//canvas->watch(observer);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
if (auto* main = layout[main_id])
|
||||
main->watch(observer);
|
||||
for (int i = 0; i < layout[main_id]->m_children.size(); i++)
|
||||
layout[main_id]->m_children[i]->watch(observer);
|
||||
//msgbox->watch(observer);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
|
||||
// glEnable(GL_BLEND);
|
||||
// sampler.bind(0);
|
||||
// ui::ShaderManager::use(kShader::Texture);
|
||||
// ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
// ui::ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-1.f, 1.f, -1.f, 1.f));
|
||||
// glActiveTexture(GL_TEXTURE0);
|
||||
// uirtt.bindTexture();
|
||||
// m_face_plane.draw_fill();
|
||||
// uirtt.unbindTexture();
|
||||
// glDisable(GL_BLEND);
|
||||
|
||||
if (rec_running)
|
||||
{
|
||||
rec_timer += dt;
|
||||
|
||||
@@ -80,6 +80,9 @@ public:
|
||||
bool keys[256];
|
||||
bool redraw = true;
|
||||
bool animate = false;
|
||||
glm::mat4 vr_rot{ 0 };
|
||||
glm::mat4 vr_uirot{ 0 };
|
||||
glm::vec2 cursor{ 0, 0 };
|
||||
glm::vec2 gesture_p0;
|
||||
glm::vec2 gesture_p1;
|
||||
#ifdef __ANDROID__
|
||||
|
||||
@@ -19,6 +19,7 @@ void App::tick(float dt)
|
||||
|
||||
void App::resize(float w, float h)
|
||||
{
|
||||
uirtt.create(w, h);
|
||||
redraw = true;
|
||||
width = w;
|
||||
height = h;
|
||||
@@ -181,6 +182,7 @@ bool App::mouse_down(int button, float x, float y, float pressure, kEventSource
|
||||
}
|
||||
bool App::mouse_move(float x, float y, float pressure, kEventSource source, bool eraser)
|
||||
{
|
||||
cursor = { x / zoom, y / zoom };
|
||||
redraw = true;
|
||||
MouseEvent e;
|
||||
e.m_type = kEventType::MouseMove;
|
||||
@@ -264,6 +266,8 @@ bool App::gesture_end()
|
||||
}
|
||||
bool App::key_down(kKey key)
|
||||
{
|
||||
if (key == kKey::KeySpacebar)
|
||||
canvas->m_canvas->m_cam_rot = vr_rot;
|
||||
redraw = true;
|
||||
keys[(int)key] = true;
|
||||
KeyEvent e;
|
||||
|
||||
@@ -13,6 +13,8 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera)
|
||||
// auto plane_mvp = proj * camera * transform *
|
||||
// glm::scale(glm::vec3(sz, 1));
|
||||
|
||||
//glm::extractEulerAngleXYZ(camera, vr_rot.y, vr_rot.x, vr_rot.z);
|
||||
vr_rot = camera;
|
||||
|
||||
sampler.bind(0);
|
||||
sampler.bind(1);
|
||||
@@ -51,11 +53,67 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera)
|
||||
|
||||
int z = (int)(canvas->m_canvas->m_order.size() - i);
|
||||
auto plane_mvp_z = proj * camera *
|
||||
glm::scale(glm::vec3(z + 1)) *
|
||||
glm::scale(glm::vec3(z + 1) * 100.f) *
|
||||
//glm::eulerAngleYXZ(yaw, pitch, roll) *
|
||||
canvas->m_canvas->m_plane_transform[plane_index] *
|
||||
glm::translate(glm::vec3(0, 0, -1));
|
||||
|
||||
if (canvas->m_canvas->m_state == ui::Canvas::kCanvasMode::Erase && canvas->m_canvas->m_show_tmp && canvas->m_canvas->m_current_layer_idx == layer_index)
|
||||
{
|
||||
sampler.bind(0);
|
||||
ui::ShaderManager::use(kShader::CompErase);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ui::ShaderManager::u_int(kShaderUniform::TexStroke, 1);
|
||||
//ui::ShaderManager::u_int(kShaderUniform::TexMask, 2);
|
||||
ui::ShaderManager::u_float(kShaderUniform::Alpha, canvas->m_canvas->m_current_stroke->m_brush.m_tip_opacity);
|
||||
//ui::ShaderManager::u_int(kShaderUniform::Lock, m_canvas->m_layers[layer_index].m_alpha_locked);
|
||||
//ui::ShaderManager::u_int(kShaderUniform::Mask, m_canvas->m_smask_active);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
canvas->m_canvas->m_layers[layer_index].m_rtt[plane_index].bindTexture();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
canvas->m_canvas->m_tmp[plane_index].bindTexture();
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
canvas->m_canvas->m_smask.m_rtt[plane_index].bindTexture();
|
||||
m_face_plane.draw_fill();
|
||||
canvas->m_canvas->m_smask.m_rtt[plane_index].unbindTexture();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
canvas->m_canvas->m_tmp[plane_index].unbindTexture();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
canvas->m_canvas->m_layers[layer_index].m_rtt[plane_index].unbindTexture();
|
||||
}
|
||||
else if (canvas->m_canvas->m_show_tmp && canvas->m_canvas->m_current_layer_idx == layer_index)
|
||||
{
|
||||
sampler.bind(0);
|
||||
auto& paper = TextureManager::get(const_hash("data/paper.jpg"));
|
||||
ui::ShaderManager::use(kShader::CompDraw);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ui::ShaderManager::u_int(kShaderUniform::TexStroke, 1);
|
||||
ui::ShaderManager::u_int(kShaderUniform::TexMask, 2);
|
||||
//ui::ShaderManager::u_int(kShaderUniform::TexStencil, 3);
|
||||
ui::ShaderManager::u_float(kShaderUniform::Alpha, canvas->m_canvas->m_current_stroke->m_brush.m_tip_opacity);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Lock, canvas->m_canvas->m_layers[layer_index].m_alpha_locked);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Mask, canvas->m_canvas->m_smask_active);
|
||||
ui::ShaderManager::u_int(kShaderUniform::BlendMode, canvas->m_canvas->m_current_stroke->m_brush.m_blend_mode);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
canvas->m_canvas->m_layers[layer_index].m_rtt[plane_index].bindTexture();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
canvas->m_canvas->m_tmp[plane_index].bindTexture();
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
canvas->m_canvas->m_smask.m_rtt[plane_index].bindTexture();
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
paper.bind();
|
||||
m_face_plane.draw_fill();
|
||||
paper.unbind();
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
canvas->m_canvas->m_smask.m_rtt[plane_index].unbindTexture();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
canvas->m_canvas->m_tmp[plane_index].unbindTexture();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
canvas->m_canvas->m_layers[layer_index].m_rtt[plane_index].unbindTexture();
|
||||
}
|
||||
else
|
||||
{
|
||||
sampler.bind(0);
|
||||
sampler_linear.bind(1);
|
||||
@@ -81,6 +139,43 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera)
|
||||
}
|
||||
}
|
||||
|
||||
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 };
|
||||
// draw the 2D UI
|
||||
{
|
||||
auto plane_mvp_z = proj * camera *
|
||||
glm::scale(glm::vec3(100)) *
|
||||
//glm::eulerAngleYXZ(yaw, pitch, roll) *
|
||||
//canvas->m_canvas->m_plane_transform[plane_index] *
|
||||
glm::transpose(canvas->m_canvas->m_cam_rot) *
|
||||
glm::translate(glm::vec3(0, 0, -1)) *
|
||||
glm::scale(aspect * tan_fov);
|
||||
sampler.bind(0);
|
||||
ui::ShaderManager::use(kShader::Texture);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
uirtt.bindTexture();
|
||||
m_face_plane.draw_fill();
|
||||
uirtt.unbindTexture();
|
||||
}
|
||||
|
||||
// draw the cursor
|
||||
{
|
||||
auto cur = (glm::vec2(cursor.x / width, 1.f - cursor.y / height) - 0.5f) * 2.f;
|
||||
auto mvp = proj * camera *
|
||||
glm::scale(glm::vec3(100)) *
|
||||
//glm::eulerAngleYXZ(yaw, pitch, roll) *
|
||||
//canvas->m_canvas->m_plane_transform[plane_index] *
|
||||
glm::transpose(canvas->m_canvas->m_cam_rot) *
|
||||
glm::translate(glm::vec3(cur * glm::vec2(aspect * tan_fov), -1)) *
|
||||
glm::scale(glm::vec3(.01));
|
||||
ui::ShaderManager::use(kShader::Color);
|
||||
ui::ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 });
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
|
||||
m_face_plane.draw_fill();
|
||||
}
|
||||
|
||||
/*
|
||||
for (auto& mode : *m_canvas->m_mode)
|
||||
mode->on_Draw(ortho_proj, proj, camera);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "brush.h"
|
||||
#include "canvas.h"
|
||||
|
||||
void ui::BrushMesh::draw(const std::vector<StrokeSample>& samples, const glm::mat4& proj)
|
||||
{
|
||||
@@ -240,7 +239,7 @@ void ui::Stroke::start(const ui::Brush& brush)
|
||||
m_last_kp = 0;
|
||||
m_dist = 0.f;
|
||||
m_brush = brush;
|
||||
m_brush.m_tip_size *= 1.f / glm::tan(glm::radians(Canvas::I->m_cam_fov * 0.5f));
|
||||
m_brush.m_tip_size *= 1.f / glm::tan(glm::radians(m_camera.fov * 0.5f));
|
||||
m_step = glm::max(m_brush.m_tip_spacing * m_brush.m_tip_size * 800.f, 1.f);
|
||||
prng.seed(0);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
};
|
||||
struct Camera
|
||||
{
|
||||
glm::vec2 rot = { 0, 0 };
|
||||
glm::mat4 rot;
|
||||
float fov = 0;
|
||||
};
|
||||
int m_layer = 0;
|
||||
|
||||
@@ -155,7 +155,7 @@ public:
|
||||
Sampler m_sampler_mask;
|
||||
Sampler m_sampler_stencil;
|
||||
Sampler m_sampler_mix;
|
||||
glm::vec2 m_cam_rot{ 0 };
|
||||
glm::mat4 m_cam_rot = glm::mat4(1);
|
||||
glm::vec3 m_cam_pos{ 0 };
|
||||
float m_cam_fov = 85;
|
||||
glm::vec2 m_cur_pos;
|
||||
|
||||
@@ -45,8 +45,11 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
break;
|
||||
case kEventType::MouseMove:
|
||||
if (m_draggingR)
|
||||
{
|
||||
canvas->m_pan = m_pan_start + (me->m_pos - m_dragR_start) * glm::vec2(-1, -1) * (canvas->m_cam_fov / 85.f);
|
||||
canvas->m_cam_rot = canvas->m_pan * 0.003f;
|
||||
auto angle = canvas->m_pan * 0.003f;
|
||||
canvas->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x);
|
||||
}
|
||||
break;
|
||||
case kEventType::MouseScroll:
|
||||
m_zoom_canvas += me->m_scroll_delta * 0.1f;
|
||||
@@ -74,7 +77,8 @@ void CanvasModeBasicCamera::on_GestureEvent(GestureEvent* ge)
|
||||
case kEventType::GestureMove:
|
||||
canvas->m_pan = m_pan_start + ge->m_pos_delta * glm::vec2(-1, -1) * 0.3f * (canvas->m_cam_fov / 85.f);
|
||||
canvas->m_cam_fov = m_camera_fov - ge->m_distance_delta * .05f;
|
||||
canvas->m_cam_rot = canvas->m_pan * 0.003f;
|
||||
auto angle = canvas->m_pan * 0.003f;
|
||||
canvas->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x);
|
||||
App::I.brush_update();
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -103,7 +103,8 @@ void Vive::Draw()
|
||||
h.m[0][0], h.m[1][0], h.m[2][0], 0,
|
||||
h.m[0][1], h.m[1][1], h.m[2][1], 0,
|
||||
h.m[0][2], h.m[1][2], h.m[2][2], 0,
|
||||
h.m[0][3], h.m[1][3], h.m[2][3], 1,
|
||||
0, 0, 0, 1,
|
||||
//h.m[0][3], h.m[1][3], h.m[2][3], 1,
|
||||
};
|
||||
|
||||
auto mat_proj = glm::make_mat4((float*)eyeProj);
|
||||
|
||||
@@ -709,6 +709,9 @@ int main(int argc, char** argv)
|
||||
std::condition_variable hmd_render_cv;
|
||||
|
||||
std::thread hmd_renderer([&] {
|
||||
if (!vive)
|
||||
return;
|
||||
|
||||
BT_SetTerminate();
|
||||
LOG("start hmd render thread");
|
||||
|
||||
|
||||
@@ -77,8 +77,7 @@ void NodeCanvas::draw()
|
||||
|
||||
glm::mat4 ortho_proj = glm::ortho(0.f, box.z, 0.f, box.w, -1000.f, 1000.f);
|
||||
glm::mat4 proj = glm::perspective(glm::radians(m_canvas->m_cam_fov), box.z / box.w, 0.01f, 1000.f);
|
||||
glm::mat4 camera = glm::eulerAngleXY(m_canvas->m_cam_rot.y, m_canvas->m_cam_rot.x) *
|
||||
glm::translate(m_canvas->m_cam_pos);
|
||||
glm::mat4 camera = m_canvas->m_cam_rot * glm::translate(m_canvas->m_cam_pos);
|
||||
|
||||
m_canvas->m_mv = camera;
|
||||
m_canvas->m_proj = proj;
|
||||
@@ -450,7 +449,7 @@ kEventResult NodeCanvas::handle_event(Event* e)
|
||||
|
||||
void NodeCanvas::reset_camera()
|
||||
{
|
||||
m_canvas->m_cam_rot = {0, 0};
|
||||
m_canvas->m_cam_rot = glm::mat4(1);
|
||||
m_canvas->m_cam_pos = {0, 0, 0};
|
||||
m_canvas->m_cam_fov = 85;
|
||||
m_canvas->m_pan = {0, 0};
|
||||
|
||||
Reference in New Issue
Block a user