Skip to content

Commit

Permalink
Fix menu pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Jun 8, 2020
1 parent 4b16100 commit 204206b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Quake/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace quake
namespace
{

[[nodiscard]] constexpr bool is_valid_shader_type(
[[nodiscard, maybe_unused]] constexpr bool is_valid_shader_type(
const GLenum shader_type) noexcept
{
return shader_type == GL_COMPUTE_SHADER ||
Expand Down
22 changes: 9 additions & 13 deletions Quake/vr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ qvec3 lastHudPosition{};
qvec3 lastMenuPosition{};
qvec3 vr_menu_target{};
qvec3 vr_menu_angles{};
qvec3 vr_menu_normal{};
qvec3 vr_menu_intersection_point{};

vr::IVRSystem* ovrHMD;
Expand Down Expand Up @@ -3442,7 +3441,6 @@ void VR_Draw2D()
const auto fwd = getFwdVecFromPitchYawRoll(vr_menu_angles);
vr_menu_target =
r_refdef.vieworg + qfloat(vr_menu_distance.value) * fwd;
vr_menu_normal = fwd;
}
else
{
Expand All @@ -3454,7 +3452,6 @@ void VR_Draw2D()
const auto fwd = getFwdVecFromPitchYawRoll(vr_menu_angles);
vr_menu_target =
cl.handpos[hand] + qfloat(vr_menu_distance.value) * fwd;
vr_menu_normal = fwd;
}

// TODO VR: (P2) control smoothing with cvar
Expand Down Expand Up @@ -3736,16 +3733,15 @@ static void VR_DoInput_UpdateVRMouse()
const auto dir = getFwdVecFromPitchYawRoll(cl.handrot[handIdx]);

const auto& planeOrig = vr_menu_target;
const auto planeDir = getFwdVecFromPitchYawRoll(vr_menu_angles);

const auto [fwd, right, up] = getAngledVectors(vr_menu_normal);
auto adjMenuAngles = vr_menu_angles;
adjMenuAngles[PITCH] -= 90.f;
adjMenuAngles[YAW] += 90.f;

const auto yr = [](const auto& v) {
return redirectVectorByYaw(v, VR_GetTurnYawAngle());
};
const auto [fwd, right, up] = getAngledVectors(adjMenuAngles);

qfloat intersectionDist{};
glm::intersectRayPlane(orig, dir, planeOrig, yr(fwd), intersectionDist);
glm::intersectRayPlane(orig, dir, planeOrig, fwd, intersectionDist);

const auto intersectionPoint = orig + intersectionDist * dir;
const auto res = intersectionPoint - planeOrig;
Expand All @@ -3759,12 +3755,12 @@ static void VR_DoInput_UpdateVRMouse()
return -1.f;
};

const auto xProj = glm::proj(res, yr(right));
const float xSign = -sign(glm::dot(xProj, yr(right)));
const auto xProj = glm::proj(res, right);
const float xSign = sign(glm::dot(xProj, right));
vr_menu_mouse_x = glm::length(xProj) * xSign / scale_hud + 320 / 2;

const auto yProj = glm::proj(res, yr(up));
const float ySign = -sign(glm::dot(yProj, yr(up)));
const auto yProj = glm::proj(res, up);
const float ySign = -sign(glm::dot(yProj, up));
vr_menu_mouse_y = glm::length(yProj) * ySign / scale_hud + 240 / 2;
};

Expand Down
1 change: 0 additions & 1 deletion Quake/vr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ extern float vr_menu_mouse_y;
extern bool vr_menu_mouse_click;
extern qvec3 vr_menu_target;
extern qvec3 vr_menu_angles;
extern qvec3 vr_menu_normal;
extern qvec3 vr_menu_intersection_point;

// TODO VR: (P1) used by show fns
Expand Down
6 changes: 3 additions & 3 deletions Quake/vr_showfn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ void show_menu_intersection_point()
// gl_vertex(cl.handpos[hand_idx]);
// gl_vertex(vr_menu_target);

glColor4f(1, 0, 0, 0.5);
gl_vertex(vr_menu_target);
gl_vertex(vr_menu_target + vr_menu_normal * 205.f);
// glColor4f(1, 0, 0, 0.5);
// gl_vertex(vr_menu_target);
// gl_vertex(vr_menu_target + vr_menu_normal * 205.f);
};

do_hand(cVR_MainHand);
Expand Down

0 comments on commit 204206b

Please sign in to comment.