mirror of
https://github.com/DrBeef/JKXR.git
synced 2024-11-24 21:11:03 +00:00
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:
parent
ec021f9b2e
commit
d00d0a6a26
5 changed files with 61 additions and 35 deletions
|
@ -19,6 +19,6 @@ bool between(float min, float val, float max);
|
||||||
void rotateAboutOrigin(float v1, float v2, float rotation, vec2_t out);
|
void rotateAboutOrigin(float v1, float v2, float rotation, vec2_t out);
|
||||||
void QuatToYawPitchRoll(XrQuaternionf q, vec3_t rotation, vec3_t out);
|
void QuatToYawPitchRoll(XrQuaternionf q, vec3_t rotation, vec3_t out);
|
||||||
void handleTrackedControllerButton(ovrInputStateTrackedRemote * trackedRemoteState, ovrInputStateTrackedRemote * prevTrackedRemoteState, uint32_t button, int key);
|
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
|
#endif //vrcommon_h
|
|
@ -129,15 +129,9 @@ float clamp(float _min, float _val, float _max)
|
||||||
return fmax(fmin(_val, _max), _min);
|
return fmax(fmin(_val, _max), _min);
|
||||||
}
|
}
|
||||||
|
|
||||||
void interactWithTouchScreen(bool reset, ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemote *oldState) {
|
void interactWithTouchScreen(float menuYaw, vec3_t controllerAngles) {
|
||||||
|
float cursorX = -sinf(DEG2RAD(controllerAngles[YAW] - menuYaw)) + 0.5f;
|
||||||
static float centerYaw = 0;
|
float cursorY = (float)(controllerAngles[PITCH] / 90.0) + 0.5f;
|
||||||
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;
|
|
||||||
|
|
||||||
PortableMouseAbs(cursorX, cursorY);
|
PortableMouseAbs(cursorX, cursorY);
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,25 +132,42 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
||||||
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, xrButton_Enter, A_ESCAPE);
|
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, xrButton_Enter, A_ESCAPE);
|
||||||
handleTrackedControllerButton(&rightTrackedRemoteState_new, &rightTrackedRemoteState_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*/)
|
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);
|
bool controlsLeftHanded = vr_control_scheme->integer >= 10;
|
||||||
resetCursor = qfalse;
|
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, domButton1, A_MOUSE1);
|
||||||
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
|
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
|
||||||
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, A_ESCAPE);
|
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, A_ESCAPE);
|
||||||
|
if ((pOffTrackedRemoteNew->Buttons & xrButton_Trigger) != (pOffTrackedRemoteOld->Buttons & xrButton_Trigger) && (pOffTrackedRemoteNew->Buttons & xrButton_Trigger)) {
|
||||||
|
switchedMenuControls = !switchedMenuControls;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//To skip flatscreen cinematic
|
//To skip flatscreen cinematic use thumb of any controller
|
||||||
if ((pDominantTrackedRemoteNew->Buttons & primaryThumb) !=
|
if ((pDominantTrackedRemoteNew->Buttons & primaryThumb) !=
|
||||||
(pDominantTrackedRemoteOld->Buttons & primaryThumb)) {
|
(pDominantTrackedRemoteOld->Buttons & primaryThumb)) {
|
||||||
sendButtonAction("+use", (pDominantTrackedRemoteNew->Buttons & primaryThumb));
|
sendButtonAction("+use", (pDominantTrackedRemoteNew->Buttons & primaryThumb));
|
||||||
}
|
}
|
||||||
|
if ((pOffTrackedRemoteNew->Buttons & secondaryThumb) !=
|
||||||
|
(pOffTrackedRemoteOld->Buttons & secondaryThumb)) {
|
||||||
|
sendButtonAction("+use", (pOffTrackedRemoteNew->Buttons & secondaryThumb));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
resetCursor = qtrue;
|
menuYaw = vr.hmdorientation[YAW];
|
||||||
|
|
||||||
float distance = sqrtf(powf(pOff->Pose.position.x - pWeapon->Pose.position.x, 2) +
|
float distance = sqrtf(powf(pOff->Pose.position.x - pWeapon->Pose.position.x, 2) +
|
||||||
powf(pOff->Pose.position.y - pWeapon->Pose.position.y, 2) +
|
powf(pOff->Pose.position.y - pWeapon->Pose.position.y, 2) +
|
||||||
|
|
|
@ -69,19 +69,32 @@ void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemote
|
||||||
//Menu button
|
//Menu button
|
||||||
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, xrButton_Enter, A_ESCAPE);
|
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, xrButton_Enter, A_ESCAPE);
|
||||||
|
|
||||||
static bool resetCursor = qtrue;
|
static float menuYaw = 0;
|
||||||
|
static bool switchedMenuControls = qfalse;
|
||||||
if (VR_UseScreenLayer() )
|
if (VR_UseScreenLayer() )
|
||||||
{
|
{
|
||||||
interactWithTouchScreen(resetCursor, pDominantTrackedRemoteNew, pDominantTrackedRemoteOld);
|
bool controlsLeftHanded = vr_control_scheme->integer >= 10;
|
||||||
resetCursor = qfalse;
|
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, domButton1, A_MOUSE1);
|
||||||
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
|
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
|
||||||
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, A_ESCAPE);
|
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, A_ESCAPE);
|
||||||
|
if ((pOffTrackedRemoteNew->Buttons & xrButton_Trigger) != (pOffTrackedRemoteOld->Buttons & xrButton_Trigger) && (pOffTrackedRemoteNew->Buttons & xrButton_Trigger)) {
|
||||||
|
switchedMenuControls = !switchedMenuControls;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
resetCursor = qtrue;
|
menuYaw = vr.hmdorientation[YAW];
|
||||||
|
|
||||||
//dominant hand stuff first
|
//dominant hand stuff first
|
||||||
{
|
{
|
||||||
|
|
|
@ -4114,27 +4114,29 @@ UI_MouseEventAbs
|
||||||
=================
|
=================
|
||||||
*/
|
*/
|
||||||
//JLFMOUSE CALLED EACH FRAME IN UI
|
//JLFMOUSE CALLED EACH FRAME IN UI
|
||||||
|
const int cursorSize = 48;
|
||||||
void _UI_MouseEventAbs( int x, int y )
|
void _UI_MouseEventAbs( int x, int y )
|
||||||
{
|
{
|
||||||
// update mouse screen position
|
// update mouse screen position
|
||||||
|
// allow to hide cursor beyond the screen edges
|
||||||
uiInfo.uiDC.cursorx = x;
|
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;
|
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)
|
if (Menu_Count() > 0)
|
||||||
|
|
Loading…
Reference in a new issue