fix vr head and controller pos
This commit is contained in:
@@ -207,7 +207,7 @@ void oculus_draw(float dt)
|
||||
controllers[0].update_state(predictedDisplayTime, head_pos);
|
||||
App::I.vr_controllers[0] = controllers[0];
|
||||
}
|
||||
|
||||
App::I.vr_head = pose;
|
||||
App::I.vr_update(dt);
|
||||
|
||||
// update hmd
|
||||
|
||||
@@ -118,6 +118,7 @@ public:
|
||||
bool vr_active = false;
|
||||
bool vr_only = false;
|
||||
VRController vr_controllers[2];
|
||||
glm::mat4 vr_head;
|
||||
float vr_pressure = 1.f;
|
||||
glm::mat4 vr_rot{ 0 };
|
||||
glm::mat4 vr_uirot{ 0 };
|
||||
|
||||
@@ -17,7 +17,6 @@ glm::vec2 controller_cursor;
|
||||
bool ui_inside = false;
|
||||
bool ui_capture = false;
|
||||
Sphere controller_ray;
|
||||
glm::mat4 head_pose;
|
||||
|
||||
bool App::vr_start()
|
||||
{
|
||||
@@ -54,7 +53,7 @@ void App::vr_draw_ui()
|
||||
|
||||
void App::vr_update(float dt)
|
||||
{
|
||||
canvas->m_canvas->m_cam_fov = 45;
|
||||
canvas->m_canvas->m_cam_fov = 60;
|
||||
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 };
|
||||
glm::mat4 m = (
|
||||
@@ -69,7 +68,7 @@ void App::vr_update(float dt)
|
||||
auto n = glm::normalize(glm::vec3(glm::vec4(0, 0, 1, 0) * mm));
|
||||
auto u = glm::normalize(glm::vec3(glm::vec4(0, 1, 0, 0) * mm));
|
||||
auto co = vr_controllers[0].get_pos();
|
||||
auto cd = co + glm::mat3(vr_controllers[0].m_mat) * glm::vec3(0, 0, -1);
|
||||
auto cd = glm::mat3(vr_controllers[0].m_mat) * glm::vec3(0, 0, -1);
|
||||
ui_inside = false;
|
||||
glm::vec3 hit;
|
||||
float t;
|
||||
@@ -96,7 +95,7 @@ void App::vr_update(float dt)
|
||||
|
||||
if (down_controller)
|
||||
{
|
||||
glm::vec3 head_position = head_pose[3];
|
||||
glm::vec3 head_position = vr_head[3];
|
||||
glm::vec3 c_pos = glm::normalize(down_controller->get_pos() - head_position) * 800.f;
|
||||
controller_points.add(c_pos);
|
||||
auto p = controller_points.average();
|
||||
@@ -141,7 +140,7 @@ void App::vr_analog(const VRController& c, VRController::kButton b, VRController
|
||||
{
|
||||
if (a == VRController::kAction::Press)
|
||||
{
|
||||
glm::vec3 head_position = head_pose[3];
|
||||
glm::vec3 head_position = vr_head[3];
|
||||
glm::vec3 c_pos = glm::normalize(c.get_pos() - head_position) * 800.f;
|
||||
async_start();
|
||||
Canvas::I->stroke_start(c_pos, force.x);
|
||||
@@ -438,7 +437,8 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
|
||||
// draw the motion controller brush
|
||||
if (!ui_visible || !ui_inside)
|
||||
{
|
||||
auto pos = glm::translate(vr_controllers[0].get_pos_n() * 100.f);
|
||||
glm::vec3 cpos = vr_controllers[0].get_pos() - xyz(pose[3]);
|
||||
auto pos = glm::translate(glm::normalize(cpos) * 100.f);
|
||||
ShaderManager::use(kShader::StrokePreview);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_float(kShaderUniform::Alpha, canvas->m_canvas->m_current_brush->m_tip_flow);
|
||||
@@ -447,7 +447,7 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, tip_color);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP,
|
||||
proj * camera * pos *
|
||||
glm::inverse(glm::lookAt({ 0, 0, 0 }, vr_controllers[0].get_pos(), { 0, 1, 0 })) *
|
||||
glm::inverse(glm::lookAt({ 0, 0, 0 }, cpos, { 0, 1, 0 })) *
|
||||
glm::scale(glm::vec3(canvas->m_canvas->m_current_brush->m_tip_size * 100.f / height)) *
|
||||
glm::eulerAngleZ(canvas->m_canvas->m_current_brush->m_tip_angle * (float)(M_PI * 2.0))
|
||||
);
|
||||
|
||||
@@ -91,7 +91,7 @@ void Vive::Update()
|
||||
h.m[0][3], h.m[1][3], h.m[2][3], 1,
|
||||
};
|
||||
|
||||
if (!m_position_valid)
|
||||
if (current_pose.bPoseIsValid && !m_position_valid)
|
||||
{
|
||||
m_initial_position = { h.m[0][3], h.m[1][3], h.m[2][3] };
|
||||
m_position_valid = true;
|
||||
@@ -102,7 +102,7 @@ void Vive::Update()
|
||||
auto mat_eye = glm::inverse(glm::make_mat4(data_eye_pose));
|
||||
|
||||
m_proj[eye] = mat_proj;
|
||||
m_view[eye] = mat_eye * mat_pose * glm::translate(m_initial_position);
|
||||
m_view[eye] = mat_eye * mat_pose/* * glm::translate(m_initial_position)*/;
|
||||
m_pose = glm::make_mat4(data_hmd_pose);
|
||||
|
||||
// invalidate controller state
|
||||
@@ -125,7 +125,7 @@ void Vive::Update()
|
||||
{
|
||||
m_controllers[controller_index].m_valid = true;
|
||||
m_hmd->GetControllerState(id, &m_controllers[controller_index].m_state, sizeof(vr::VRControllerState_t));
|
||||
m_controllers[controller_index].m_mat = glm::translate(-m_initial_position) * Pose2Mat(poses[id].mDeviceToAbsoluteTracking);
|
||||
m_controllers[controller_index].m_mat = /*glm::translate(-m_initial_position) * */Pose2Mat(poses[id].mDeviceToAbsoluteTracking);
|
||||
|
||||
auto pressed_mask = m_controllers[controller_index].m_state.ulButtonPressed;
|
||||
for (uint8_t bi = 0; bi < (uint8_t)ViveController::kButton::COUNT; bi++)
|
||||
|
||||
@@ -586,6 +586,7 @@ bool win32_vr_start()
|
||||
vive->Update();
|
||||
App::I.vr_active = vive->m_active;
|
||||
App::I.vr_controllers[0] = vive->m_controllers[0];
|
||||
App::I.vr_head = vive->m_pose;
|
||||
App::I.vr_update(dt);
|
||||
|
||||
if (vr_running && vive->m_active)
|
||||
|
||||
Reference in New Issue
Block a user