mirror of
https://github.com/CrispyPin/sinpin-vr.git
synced 2024-11-10 04:20:25 +01:00
rotate lasers to face HMD so they don't look flat
This commit is contained in:
parent
500c198587
commit
14b5c8f745
3 changed files with 13 additions and 4 deletions
|
@ -137,7 +137,6 @@ void App::InitRootOverlay()
|
||||||
panel.GetOverlay()->ControllerRelease();
|
panel.GetOverlay()->ControllerRelease();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
printf("Created root overlay instance\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::Update()
|
void App::Update()
|
||||||
|
|
|
@ -52,12 +52,17 @@ void Controller::Update()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto controller_pose = _app->GetTrackerPose(_device_index);
|
auto controller_pose = _app->GetTrackerPose(_device_index);
|
||||||
auto origin = GetPos(controller_pose);
|
auto controller_pos = GetPos(controller_pose);
|
||||||
auto forward = -glm::vec3(controller_pose[2]);
|
auto forward = -glm::vec3(controller_pose[2]);
|
||||||
auto ray = _app->IntersectRay(origin, forward, 5.0f);
|
auto ray = _app->IntersectRay(controller_pos, forward, 5.0f);
|
||||||
float len = ray.distance;
|
float len = ray.distance;
|
||||||
|
|
||||||
VRMat transform = {{{width, 0, 0, 0}, {0, 0, width, 0}, {0, len, 0, len * -0.5f}}};
|
auto hmd_global_pos = GetPos(_app->GetTrackerPose(0));
|
||||||
|
auto hmd_local_pos = glm::inverse(controller_pose) * glm::vec4(hmd_global_pos - controller_pos, 0);
|
||||||
|
hmd_local_pos.z = 0;
|
||||||
|
auto hmd_dir = glm::normalize(hmd_local_pos);
|
||||||
|
|
||||||
|
VRMat transform = {{{width * hmd_dir.y, 0, width * hmd_dir.x, 0}, {width * -hmd_dir.x, 0, width * hmd_dir.y, 0}, {0, len, 0, len * -0.5f}}};
|
||||||
_laser.SetTransformTracker(_device_index, &transform);
|
_laser.SetTransformTracker(_device_index, &transform);
|
||||||
|
|
||||||
if (ray.overlay != nullptr)
|
if (ray.overlay != nullptr)
|
||||||
|
|
|
@ -10,6 +10,11 @@ typedef vr::HmdMatrix34_t VRMat;
|
||||||
const VRMat VRMatIdentity{{{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}}};
|
const VRMat VRMatIdentity{{{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}}};
|
||||||
const int MAX_TRACKERS = vr::k_unMaxTrackedDeviceCount;
|
const int MAX_TRACKERS = vr::k_unMaxTrackedDeviceCount;
|
||||||
|
|
||||||
|
inline void PrintVec(glm::vec3 v)
|
||||||
|
{
|
||||||
|
printf("(%.2f, %.2f, %.2f)\n", v.x, v.y, v.z);
|
||||||
|
}
|
||||||
|
|
||||||
inline void PrintMat(VRMat m)
|
inline void PrintMat(VRMat m)
|
||||||
{
|
{
|
||||||
printf("[%.2f, %.2f, %.2f, %.2f]\n", m.m[0][0], m.m[0][1], m.m[0][2], m.m[0][3]);
|
printf("[%.2f, %.2f, %.2f, %.2f]\n", m.m[0][0], m.m[0][1], m.m[0][2], m.m[0][3]);
|
||||||
|
|
Loading…
Reference in a new issue