refactoring vr code

This commit is contained in:
2019-05-31 23:02:53 +02:00
parent d2a62df5c7
commit 20582dafa8
6 changed files with 138 additions and 117 deletions

View File

@@ -513,38 +513,10 @@ 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, glm::vec2 force) {
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;
async_lock();
Canvas::I->stroke_start(pos, force.x);
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();
}
}
};
vive->on_button = [&](const ViveController& c, ViveController::kButton b, ViveController::kAction a, glm::vec2 axis) {
if (b == ViveController::kButton::Pad && a == ViveController::kAction::Press)
{
if (glm::length(axis) < 0.5f)
App::I.toggle_ui();
}
};
vive->on_analog_button = std::bind(&App::vr_analog, &App::I, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
vive->on_button = std::bind(&App::vr_digital, &App::I, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
const float target_tick_rate = 90;
auto t0 = GetTickCount64();
@@ -569,21 +541,8 @@ bool win32_vr_start()
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]));
App::I.vr_update(dt);
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) > 10)
{
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();