vr paint
This commit is contained in:
43
src/main.cpp
43
src/main.cpp
@@ -478,6 +478,33 @@ bool win32_vr_start()
|
||||
App::I.has_vr = true;
|
||||
vr_running = true;
|
||||
|
||||
bool trigger_down = false;
|
||||
cbuffer<glm::vec3> controller_points(10);
|
||||
glm::vec3 controller_last_point;
|
||||
vive->on_analog_button = [&](const ViveController& c, ViveController::kButton b, ViveController::kAction a) {
|
||||
if (b == ViveController::kButton::Trigger)
|
||||
{
|
||||
if (a == ViveController::kAction::Press)
|
||||
{
|
||||
glm::vec3 pos = glm::normalize(xyz(vive->m_controllers[0].m_mat[3])) * 800.f;
|
||||
float force = vive->m_controllers[0].axis(b).x;
|
||||
async_lock();
|
||||
Canvas::I->stroke_start(pos, force);
|
||||
async_unlock();
|
||||
controller_last_point = pos;
|
||||
controller_points.clear();
|
||||
trigger_down = true;
|
||||
}
|
||||
if (a == ViveController::kAction::Release)
|
||||
{
|
||||
trigger_down = false;
|
||||
async_lock();
|
||||
Canvas::I->stroke_end();
|
||||
async_unlock();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const float target_tick_rate = 90;
|
||||
unsigned long t0 = GetTickCount();
|
||||
while (vr_running && running == 1 && vive->Valid())
|
||||
@@ -488,7 +515,23 @@ bool win32_vr_start()
|
||||
|
||||
vive->Update();
|
||||
App::I.vr_active = vive->m_active;
|
||||
App::I.vr_controller = vive->m_controllers[0].m_mat;
|
||||
App::I.vr_controller_pos = glm::normalize(xyz(vive->m_controllers[0].m_mat[3]));
|
||||
|
||||
if (trigger_down)
|
||||
{
|
||||
controller_points.add(App::I.vr_controller_pos * 800.f);
|
||||
auto p = controller_points.average();
|
||||
if (glm::distance(p, controller_last_point) > 1)
|
||||
{
|
||||
async_lock();
|
||||
Canvas::I->stroke_update(p, vive->m_controllers[0].axis(ViveController::kButton::Trigger).x);
|
||||
async_unlock();
|
||||
controller_last_point = p;
|
||||
App::I.redraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (vr_running && vive->m_active)
|
||||
{
|
||||
async_lock();
|
||||
|
||||
Reference in New Issue
Block a user