vr brush preview and pen gestures (pick and size)
This commit is contained in:
@@ -75,6 +75,7 @@ public:
|
||||
std::string doc_dir;
|
||||
std::string doc_filename;
|
||||
bool has_stylus = false;
|
||||
bool has_vr = false;
|
||||
float width;
|
||||
float height;
|
||||
bool keys[256];
|
||||
|
||||
@@ -155,6 +155,36 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
|
||||
m_face_plane.draw_stroke();
|
||||
}
|
||||
|
||||
// draw the brush
|
||||
if (auto mode = dynamic_cast<CanvasModePen*>(canvas->m_canvas->modes[(int)canvas->m_canvas->m_current_mode][0]))
|
||||
{
|
||||
auto pos = mode->m_resizing ? mode->m_size_pos_start : mode->m_cur_pos;
|
||||
if (App::I.keys[(int)kKey::KeyAlt] && !mode->m_resizing)
|
||||
pos.x = pos.x - canvas->m_canvas->m_current_brush.m_tip_size * 500;
|
||||
auto cur = (glm::vec2(pos.x / width, 1.f - pos.y / height) - 0.5f) * 2.f;
|
||||
|
||||
ui::ShaderManager::use(ui::kShader::StrokePreview);
|
||||
ui::ShaderManager::u_int(ui::kShaderUniform::Tex, 0);
|
||||
ui::ShaderManager::u_float(ui::kShaderUniform::Alpha, canvas->m_canvas->m_current_brush.m_tip_flow);
|
||||
auto tip_color = glm::vec4(glm::vec3(canvas->m_canvas->m_current_brush.m_tip_color), 1);
|
||||
ui::ShaderManager::u_vec4(ui::kShaderUniform::Col, tip_color);
|
||||
ui::ShaderManager::u_mat4(ui::kShaderUniform::MVP,
|
||||
proj * camera *
|
||||
glm::scale(glm::vec3(100)) *
|
||||
glm::transpose(canvas->m_canvas->m_cam_rot) *
|
||||
glm::translate(glm::vec3(cur * glm::vec2(aspect * tan_fov), -1)) *
|
||||
glm::scale(glm::vec3(canvas->m_canvas->m_current_brush.m_tip_size * 800.f / App::I.height)) *
|
||||
glm::eulerAngleZ(canvas->m_canvas->m_current_brush.m_tip_angle * (float)(M_PI * 2.0))
|
||||
);
|
||||
glEnable(GL_BLEND);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
auto& tex = TextureManager::get(canvas->m_canvas->m_current_brush.m_tex_id);
|
||||
tex.bind();
|
||||
sampler_linear.bind(0);
|
||||
m_face_plane.draw_fill();
|
||||
tex.unbind();
|
||||
}
|
||||
|
||||
// draw the 2D UI
|
||||
if (ui_visible)
|
||||
{
|
||||
@@ -163,7 +193,7 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
|
||||
glm::transpose(canvas->m_canvas->m_cam_rot) *
|
||||
glm::translate(glm::vec3(0, 0, -1)) *
|
||||
glm::scale(aspect * tan_fov);
|
||||
sampler.bind(0);
|
||||
sampler_linear.bind(0);
|
||||
ui::ShaderManager::use(kShader::Texture);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
|
||||
@@ -178,14 +208,14 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
|
||||
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));
|
||||
glm::translate(glm::vec3(cur * glm::vec2(aspect * tan_fov), -1));
|
||||
ui::ShaderManager::use(kShader::Color);
|
||||
ui::ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 });
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, mvp * glm::scale(glm::vec3(.01)));
|
||||
m_face_plane.draw_fill();
|
||||
ui::ShaderManager::u_vec4(kShaderUniform::Col, { 1, 1, 1, 1 });
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, mvp * glm::scale(glm::vec3(.005)));
|
||||
m_face_plane.draw_fill();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,8 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
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);
|
||||
auto dir = App::I.has_vr ? glm::vec2(1, 1) : glm::vec2(-1, -1);
|
||||
canvas->m_pan = m_pan_start + (me->m_pos - m_dragR_start) * dir * (canvas->m_cam_fov / 85.f);
|
||||
auto angle = canvas->m_pan * 0.003f;
|
||||
canvas->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
|
||||
class CanvasModePen : public CanvasMode
|
||||
{
|
||||
friend class App;
|
||||
bool m_draw_tip = false;
|
||||
bool m_dragging = false;
|
||||
glm::vec2 m_pan_start;
|
||||
|
||||
46
src/main.cpp
46
src/main.cpp
@@ -714,7 +714,7 @@ int main(int argc, char** argv)
|
||||
|
||||
BT_SetTerminate();
|
||||
LOG("start hmd render thread");
|
||||
|
||||
App::I.has_vr = true;
|
||||
const float target_tick_rate = 90;
|
||||
unsigned long t0 = GetTickCount();
|
||||
while (running && vive->Valid())
|
||||
@@ -731,6 +731,7 @@ int main(int argc, char** argv)
|
||||
const int diff = framerate - (t1 - t0);
|
||||
hmd_render_cv.wait_for(lock, std::chrono::milliseconds(diff));
|
||||
}
|
||||
App::I.has_vr = false;
|
||||
async_lock();
|
||||
vive->Terminate();
|
||||
async_unlock();
|
||||
@@ -772,7 +773,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
static bool leftDown = false;
|
||||
static DWORD lastTime;
|
||||
static POINT lastPoint;
|
||||
static glm::vec2 lastPoint;
|
||||
|
||||
auto extra = GetMessageExtraInfo();
|
||||
// if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
@@ -866,8 +867,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
{
|
||||
/*
|
||||
RECT r;
|
||||
POINT curpos;
|
||||
GetWindowRect(hWnd, &r);
|
||||
glm::vec2 center = { r.left + (r.right - r.left) / 2, r.top + (r.bottom - r.top) / 2 };
|
||||
GetCursorPos(&curpos);
|
||||
SetCursorPos(center.x, center.y);
|
||||
|
||||
//glm::vec2 cur = { GET_X_LPARAM(lp), GET_Y_LPARAM(lp) };
|
||||
glm::vec2 sz = { App::I.width, App::I.height };
|
||||
glm::vec2 diff = { curpos.x - center.x, curpos.y - center.y };
|
||||
lastPoint = glm::clamp(lastPoint + diff, { 0, 0 }, sz);
|
||||
|
||||
*/
|
||||
lastPoint = { GET_X_LPARAM(lp), GET_Y_LPARAM(lp) };
|
||||
|
||||
auto pt = lastPoint;
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([lp, extra, p = WacomTablet::I.get_pressure()]{
|
||||
tasklist.emplace_back([pt, extra, p = WacomTablet::I.get_pressure()]{
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
{
|
||||
@@ -879,14 +897,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
}
|
||||
App::I.mouse_move((float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), p, pointer_source, WacomTablet::I.m_eraser);
|
||||
App::I.mouse_move((float)pt.x, (float)pt.y, p, pointer_source, WacomTablet::I.m_eraser);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([lp, extra, hWnd, p = WacomTablet::I.get_pressure()]{
|
||||
auto pt = lastPoint;
|
||||
tasklist.emplace_back([pt, extra, hWnd, p = WacomTablet::I.get_pressure()]{
|
||||
SetCapture(hWnd);
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
@@ -899,14 +918,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
}
|
||||
App::I.mouse_down(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), p, pointer_source, WacomTablet::I.m_eraser);
|
||||
App::I.mouse_down(0, (float)pt.x, (float)pt.y, p, pointer_source, WacomTablet::I.m_eraser);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([lp, extra]{
|
||||
auto pt = lastPoint;
|
||||
tasklist.emplace_back([pt, extra] {
|
||||
WacomTablet::I.reset_pressure();
|
||||
ReleaseCapture();
|
||||
kEventSource pointer_source;
|
||||
@@ -920,14 +940,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
}
|
||||
App::I.mouse_up(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), pointer_source, WacomTablet::I.m_eraser);
|
||||
App::I.mouse_up(0, (float)pt.x, (float)pt.y, pointer_source, WacomTablet::I.m_eraser);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([lp, extra, hWnd]{
|
||||
auto pt = lastPoint;
|
||||
tasklist.emplace_back([pt, extra, hWnd] {
|
||||
SetCapture(hWnd);
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
@@ -940,14 +961,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
}
|
||||
App::I.mouse_down(1, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), 1.f, pointer_source, 0);
|
||||
App::I.mouse_down(1, (float)pt.x, (float)pt.y, 1.f, pointer_source, 0);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case WM_RBUTTONUP:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([lp, extra]{
|
||||
auto pt = lastPoint;
|
||||
tasklist.emplace_back([pt, extra] {
|
||||
ReleaseCapture();
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
@@ -960,7 +982,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
}
|
||||
App::I.mouse_up(1, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), pointer_source, 0);
|
||||
App::I.mouse_up(1, (float)pt.x, (float)pt.y, pointer_source, 0);
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user