Skip to content

Commit

Permalink
Merged @baggyg's changes for Cybershoes support
Browse files Browse the repository at this point in the history
  • Loading branch information
DrBeef committed May 16, 2021
1 parent 035881d commit f8ab514
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 29 deletions.
8 changes: 6 additions & 2 deletions Projects/Android/jni/QzDoom/QzDoom_SurfaceView.c
Original file line number Diff line number Diff line change
Expand Up @@ -1629,13 +1629,17 @@ void QzDoom_getTrackedRemotesOrientation(int vr_control_scheme) {//Get info for
switch ((int)vr_control_scheme)
{
case RIGHT_HANDED_DEFAULT:
HandleInput_Default(vr_control_scheme, &rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new,
HandleInput_Default(vr_control_scheme,
&footTrackedRemoteState_new, &footTrackedRemoteState_old,
&rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new,
&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, &leftRemoteTracking_new,
ovrButton_A, ovrButton_B, ovrButton_X, ovrButton_Y);
break;
case LEFT_HANDED_DEFAULT:
case LEFT_HANDED_ALT:
HandleInput_Default(vr_control_scheme, &leftTrackedRemoteState_new, &leftTrackedRemoteState_old, &leftRemoteTracking_new,
HandleInput_Default(vr_control_scheme,
&footTrackedRemoteState_new, &footTrackedRemoteState_old,
&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, &leftRemoteTracking_new,
&rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new,
ovrButton_X, ovrButton_Y, ovrButton_A, ovrButton_B);
break;
Expand Down
7 changes: 6 additions & 1 deletion Projects/Android/jni/QzDoom/VrInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ ovrInputStateTrackedRemote rightTrackedRemoteState_old;
ovrInputStateTrackedRemote rightTrackedRemoteState_new;
ovrTracking rightRemoteTracking_new;

ovrInputStateGamepad footTrackedRemoteState_old;
ovrInputStateGamepad footTrackedRemoteState_new;


ovrDeviceID controllerIDs[2];

float remote_movementSideways;
Expand All @@ -26,7 +30,8 @@ float cinemamodePitch;

void acquireTrackedRemotesData(const ovrMobile *Ovr, double displayTime);

void HandleInput_Default( int control_scheme, ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
void HandleInput_Default( int control_scheme, ovrInputStateGamepad *pFootTrackingNew, ovrInputStateGamepad *pFootTrackingOld, ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking,
int domButton1, int domButton2, int offButton1, int offButton2 );

Expand Down
63 changes: 40 additions & 23 deletions Projects/Android/jni/QzDoom/VrInputCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,51 @@ bool between(float min, float val, float max)

void acquireTrackedRemotesData(const ovrMobile *Ovr, double displayTime) {//The amount of yaw changed by controller
for ( int i = 0; ; i++ ) {
ovrInputCapabilityHeader cap;
ovrResult result = vrapi_EnumerateInputDevices(Ovr, i, &cap);
ovrInputCapabilityHeader capsHeader;
ovrResult result = vrapi_EnumerateInputDevices(Ovr, i, &capsHeader);
if (result < 0) {
break;
}

if (cap.Type == ovrControllerType_TrackedRemote) {
if (capsHeader.Type == ovrControllerType_Gamepad) {

ovrInputGamepadCapabilities remoteCaps;
remoteCaps.Header = capsHeader;
if (vrapi_GetInputDeviceCapabilities(Ovr, &remoteCaps.Header) >= 0) {
// remote is connected
ovrInputStateGamepad remoteState;
remoteState.Header.ControllerType = ovrControllerType_Gamepad;
if ( vrapi_GetCurrentInputState( Ovr, capsHeader.DeviceID, &remoteState.Header ) >= 0 )
{
// act on device state returned in remoteState
footTrackedRemoteState_new = remoteState;
}
}
}
else if (capsHeader.Type == ovrControllerType_TrackedRemote) {
ovrTracking remoteTracking;
ovrInputStateTrackedRemote trackedRemoteState;
trackedRemoteState.Header.ControllerType = ovrControllerType_TrackedRemote;
result = vrapi_GetCurrentInputState(Ovr, cap.DeviceID, &trackedRemoteState.Header);

if (result == ovrSuccess) {
ovrInputTrackedRemoteCapabilities remoteCapabilities;
remoteCapabilities.Header = cap;
result = vrapi_GetInputDeviceCapabilities(Ovr, &remoteCapabilities.Header);

result = vrapi_GetInputTrackingState(Ovr, cap.DeviceID, displayTime,
&remoteTracking);

if (remoteCapabilities.ControllerCapabilities & ovrControllerCaps_RightHand) {
rightTrackedRemoteState_new = trackedRemoteState;
rightRemoteTracking_new = remoteTracking;
controllerIDs[1] = cap.DeviceID;
} else{
leftTrackedRemoteState_new = trackedRemoteState;
leftRemoteTracking_new = remoteTracking;
controllerIDs[0] = cap.DeviceID;
ovrInputTrackedRemoteCapabilities remoteCaps;
remoteCaps.Header = capsHeader;
if ( vrapi_GetInputDeviceCapabilities( Ovr, &remoteCaps.Header ) >= 0 )
{
// remote is connected
ovrInputStateTrackedRemote remoteState;
remoteState.Header.ControllerType = ovrControllerType_TrackedRemote;

if(vrapi_GetCurrentInputState(Ovr, capsHeader.DeviceID, &remoteState.Header) >= 0) {
if (vrapi_GetInputTrackingState(Ovr, capsHeader.DeviceID, displayTime,
&remoteTracking) >= 0) {
// act on device state returned in remoteState
if (remoteCaps.ControllerCapabilities & ovrControllerCaps_RightHand) {
rightTrackedRemoteState_new = remoteState;
rightRemoteTracking_new = remoteTracking;
controllerIDs[1] = capsHeader.DeviceID;
} else {
leftTrackedRemoteState_new = remoteState;
leftRemoteTracking_new = remoteTracking;
controllerIDs[0] = capsHeader.DeviceID;
}
}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions Projects/Android/jni/QzDoom/VrInputDefault.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ int getMenuState();
void Joy_GenerateButtonEvents(int oldbuttons, int newbuttons, int numbuttons, int base);
float getViewpointYaw();

void HandleInput_Default( int control_scheme, ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
void HandleInput_Default( int control_scheme, ovrInputStateGamepad *pFootTrackingNew, ovrInputStateGamepad *pFootTrackingOld,
ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking,
int domButton1, int domButton2, int offButton1, int offButton2 )

Expand Down Expand Up @@ -243,8 +244,8 @@ void HandleInput_Default( int control_scheme, ovrInputStateTrackedRemote *pDomin
//and we don't get movement jitter when the joystick doesn't quite center properly
float dist = length(pSecondaryTrackedRemoteNew->Joystick.x, pSecondaryTrackedRemoteNew->Joystick.y);
float nlf = nonLinearFilter(dist);
float x = nlf * pSecondaryTrackedRemoteNew->Joystick.x;
float y = nlf * pSecondaryTrackedRemoteNew->Joystick.y;
float x = nlf * pSecondaryTrackedRemoteNew->Joystick.x + pFootTrackingNew->LeftJoystick.x;
float y = nlf * pSecondaryTrackedRemoteNew->Joystick.y - pFootTrackingNew->LeftJoystick.y;

//Apply a simple deadzone
player_moving = (fabs(x) + fabs(y)) > 0.05f;
Expand Down

0 comments on commit f8ab514

Please sign in to comment.