Do-not-wrap-cursor-Do-not-switch-menu-controls

Thanks @MuadDib!

Co-Authored-By: petr666 <5103207+petr666@users.noreply.github.com>
This commit is contained in:
Simon 2023-03-21 20:10:40 +00:00
parent ec021f9b2e
commit d00d0a6a26
5 changed files with 61 additions and 35 deletions

View file

@ -19,6 +19,6 @@ bool between(float min, float val, float max);
void rotateAboutOrigin(float v1, float v2, float rotation, vec2_t out);
void QuatToYawPitchRoll(XrQuaternionf q, vec3_t rotation, vec3_t out);
void handleTrackedControllerButton(ovrInputStateTrackedRemote * trackedRemoteState, ovrInputStateTrackedRemote * prevTrackedRemoteState, uint32_t button, int key);
void interactWithTouchScreen(bool reset, ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemote *oldState);
void interactWithTouchScreen(float menuYaw, vec3_t controllerAngles);
#endif //vrcommon_h

View file

@ -129,15 +129,9 @@ float clamp(float _min, float _val, float _max)
return fmax(fmin(_val, _max), _min);
}
void interactWithTouchScreen(bool reset, ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemote *oldState) {
static float centerYaw = 0;
if (reset || Q_isnan(centerYaw) || fabs(sinf(DEG2RAD(vr.weaponangles[ANGLES_ADJUSTED][YAW]-centerYaw))) > 0.9f)
{
centerYaw = vr.weaponangles[ANGLES_ADJUSTED][YAW];
}
float cursorX = -sinf(DEG2RAD(vr.weaponangles[ANGLES_ADJUSTED][YAW]-centerYaw)) + 0.5f;
float cursorY = (float)(vr.weaponangles[ANGLES_ADJUSTED][PITCH] / 90.0) + 0.5f;
void interactWithTouchScreen(float menuYaw, vec3_t controllerAngles) {
float cursorX = -sinf(DEG2RAD(controllerAngles[YAW] - menuYaw)) + 0.5f;
float cursorY = (float)(controllerAngles[PITCH] / 90.0) + 0.5f;
PortableMouseAbs(cursorX, cursorY);
}

View file

@ -132,25 +132,42 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, xrButton_Enter, A_ESCAPE);
handleTrackedControllerButton(&rightTrackedRemoteState_new, &rightTrackedRemoteState_old, xrButton_Enter, A_ESCAPE);
static bool resetCursor = qtrue;
static float menuYaw = 0;
static bool switchedMenuControls = qfalse;
if (VR_UseScreenLayer() && !vr.misc_camera /*bit of a fiddle, but if we are in a misc camera, we are in the game and shouldn't be in here*/)
{
interactWithTouchScreen(resetCursor, pDominantTrackedRemoteNew, pDominantTrackedRemoteOld);
resetCursor = qfalse;
bool controlsLeftHanded = vr_control_scheme->integer >= 10;
if ((controlsLeftHanded && !switchedMenuControls) || (!controlsLeftHanded && switchedMenuControls)) {
interactWithTouchScreen(menuYaw, vr.offhandangles[ANGLES_DEFAULT]);
handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, offButton1, A_MOUSE1);
handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, offButton2, A_ESCAPE);
if ((pDominantTrackedRemoteNew->Buttons & xrButton_Trigger) != (pDominantTrackedRemoteOld->Buttons & xrButton_Trigger) && (pDominantTrackedRemoteNew->Buttons & xrButton_Trigger)) {
switchedMenuControls = !switchedMenuControls;
}
} else {
interactWithTouchScreen(menuYaw, vr.weaponangles[ANGLES_DEFAULT]);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, A_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, A_ESCAPE);
if ((pOffTrackedRemoteNew->Buttons & xrButton_Trigger) != (pOffTrackedRemoteOld->Buttons & xrButton_Trigger) && (pOffTrackedRemoteNew->Buttons & xrButton_Trigger)) {
switchedMenuControls = !switchedMenuControls;
}
}
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, A_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, A_ESCAPE);
//To skip flatscreen cinematic
//To skip flatscreen cinematic use thumb of any controller
if ((pDominantTrackedRemoteNew->Buttons & primaryThumb) !=
(pDominantTrackedRemoteOld->Buttons & primaryThumb)) {
sendButtonAction("+use", (pDominantTrackedRemoteNew->Buttons & primaryThumb));
}
if ((pOffTrackedRemoteNew->Buttons & secondaryThumb) !=
(pOffTrackedRemoteOld->Buttons & secondaryThumb)) {
sendButtonAction("+use", (pOffTrackedRemoteNew->Buttons & secondaryThumb));
}
}
else
{
resetCursor = qtrue;
menuYaw = vr.hmdorientation[YAW];
float distance = sqrtf(powf(pOff->Pose.position.x - pWeapon->Pose.position.x, 2) +
powf(pOff->Pose.position.y - pWeapon->Pose.position.y, 2) +

View file

@ -69,19 +69,32 @@ void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemote
//Menu button
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, xrButton_Enter, A_ESCAPE);
static bool resetCursor = qtrue;
static float menuYaw = 0;
static bool switchedMenuControls = qfalse;
if (VR_UseScreenLayer() )
{
interactWithTouchScreen(resetCursor, pDominantTrackedRemoteNew, pDominantTrackedRemoteOld);
resetCursor = qfalse;
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, A_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, A_ESCAPE);
bool controlsLeftHanded = vr_control_scheme->integer >= 10;
if ((controlsLeftHanded && !switchedMenuControls) || (!controlsLeftHanded && switchedMenuControls)) {
interactWithTouchScreen(menuYaw, vr.offhandangles[ANGLES_DEFAULT]);
handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, offButton1, A_MOUSE1);
handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, offButton2, A_ESCAPE);
if ((pDominantTrackedRemoteNew->Buttons & xrButton_Trigger) != (pDominantTrackedRemoteOld->Buttons & xrButton_Trigger) && (pDominantTrackedRemoteNew->Buttons & xrButton_Trigger)) {
switchedMenuControls = !switchedMenuControls;
}
} else {
interactWithTouchScreen(menuYaw, vr.weaponangles[ANGLES_DEFAULT]);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, A_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, A_ESCAPE);
if ((pOffTrackedRemoteNew->Buttons & xrButton_Trigger) != (pOffTrackedRemoteOld->Buttons & xrButton_Trigger) && (pOffTrackedRemoteNew->Buttons & xrButton_Trigger)) {
switchedMenuControls = !switchedMenuControls;
}
}
}
else
{
resetCursor = qtrue;
menuYaw = vr.hmdorientation[YAW];
//dominant hand stuff first
{

View file

@ -4114,27 +4114,29 @@ UI_MouseEventAbs
=================
*/
//JLFMOUSE CALLED EACH FRAME IN UI
const int cursorSize = 48;
void _UI_MouseEventAbs( int x, int y )
{
// update mouse screen position
// allow to hide cursor beyond the screen edges
uiInfo.uiDC.cursorx = x;
if (uiInfo.uiDC.cursorx < 0)
if (uiInfo.uiDC.cursorx < -cursorSize)
{
uiInfo.uiDC.cursorx = 0;
uiInfo.uiDC.cursorx = -cursorSize;
}
else if (uiInfo.uiDC.cursorx > SCREEN_WIDTH)
else if (uiInfo.uiDC.cursorx > SCREEN_WIDTH + cursorSize)
{
uiInfo.uiDC.cursorx = SCREEN_WIDTH;
uiInfo.uiDC.cursorx = SCREEN_WIDTH + cursorSize;
}
uiInfo.uiDC.cursory = y;
if (uiInfo.uiDC.cursory < 0)
if (uiInfo.uiDC.cursory < -cursorSize)
{
uiInfo.uiDC.cursory = 0;
uiInfo.uiDC.cursory = -cursorSize;
}
else if (uiInfo.uiDC.cursory > SCREEN_HEIGHT)
else if (uiInfo.uiDC.cursory > SCREEN_HEIGHT + cursorSize)
{
uiInfo.uiDC.cursory = SCREEN_HEIGHT;
uiInfo.uiDC.cursory = SCREEN_HEIGHT + cursorSize;
}
if (Menu_Count() > 0)