move UI plane when toggled in VR, fix vr start/stop on Quest
This commit is contained in:
@@ -51,16 +51,28 @@ void App::vr_update(float dt)
|
||||
{
|
||||
glm::vec3 hit;
|
||||
float t;
|
||||
if (ray_intersect({ 0, 0, 0 }, vr_controllers[0].get_pos_n(), { 0, 0, -1 }, { 0, 0, 1 }, { 1, 0, 0 }, hit, t))
|
||||
glm::mat3 m = glm::transpose(Canvas::I->m_cam_rot);
|
||||
auto o = m * glm::vec3(0, 0, -1);
|
||||
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))
|
||||
{
|
||||
glm::mat4 plane_camera = glm::lookAt(glm::vec3(0, 0, -1), { 0, 0, 1 }, { 0, 1, 0 });
|
||||
glm::mat4 plane_camera = glm::lookAt(o, n, u);
|
||||
glm::vec4 plane_local = plane_camera * glm::vec4(hit, 1);
|
||||
controller_cursor.x = -(plane_local.x * 0.5f - 0.5f) * width;
|
||||
controller_cursor.y = height - (plane_local.y * 0.5f + 0.5f) * height - 1;
|
||||
async_start();
|
||||
mouse_move(controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false);
|
||||
async_end();
|
||||
ui_inside = true;
|
||||
if (glm::all(glm::lessThanEqual(glm::abs(xy(plane_local)), glm::vec2(1.5f))))
|
||||
{
|
||||
controller_cursor.x = -(plane_local.x * 0.5f - 0.5f) * width;
|
||||
controller_cursor.y = height - (plane_local.y * 0.5f + 0.5f) * height - 1;
|
||||
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
|
||||
{
|
||||
@@ -111,7 +123,11 @@ void App::vr_digital(const VRController& c, VRController::kButton b, VRControlle
|
||||
if (b == VRController::kButton::Pad && a == VRController::kAction::Press)
|
||||
{
|
||||
if (glm::length(axis) < 0.5f)
|
||||
I.toggle_ui();
|
||||
{
|
||||
if (!ui_visible)
|
||||
Canvas::I->m_cam_rot = vr_rot;
|
||||
toggle_ui();
|
||||
}
|
||||
}
|
||||
if (b == VRController::kButton::A)
|
||||
{
|
||||
@@ -135,7 +151,8 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
|
||||
// glm::scale(glm::vec3(sz, 1));
|
||||
|
||||
//glm::extractEulerAngleXYZ(camera, vr_rot.y, vr_rot.x, vr_rot.z);
|
||||
vr_rot = pose;
|
||||
glm::vec3 origin = glm::vec3(0, 0, -1) * glm::transpose(glm::mat3(pose));
|
||||
vr_rot = glm::lookAt({ 0, 0, 0 }, origin, { 0, 1, 0 });
|
||||
|
||||
sampler.bind(0);
|
||||
sampler.bind(1);
|
||||
|
||||
@@ -98,13 +98,12 @@ void Vive::Update()
|
||||
|
||||
m_proj[eye] = mat_proj;
|
||||
m_view[eye] = mat_eye * mat_pose;
|
||||
m_pose = mat_pose;
|
||||
m_pose = glm::make_mat4(data_hmd_pose);
|
||||
|
||||
// invalidate controller state
|
||||
for (auto& c : m_controllers)
|
||||
c.m_valid = false;
|
||||
int controller_index = 0;
|
||||
auto pose_inv = glm::inverse(m_pose);
|
||||
|
||||
for (int id = 0; id < vr::k_unMaxTrackedDeviceCount; id++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user