2022-09-18 15:37:21 +00:00
|
|
|
/************************************************************************************
|
|
|
|
|
|
|
|
Filename : VrInputRight.c
|
|
|
|
Content : Handles common controller input functionality
|
|
|
|
Created : September 2019
|
|
|
|
Authors : Simon Brown
|
|
|
|
|
|
|
|
*************************************************************************************/
|
|
|
|
|
|
|
|
#include <VrApi.h>
|
|
|
|
#include <VrApi_Helpers.h>
|
|
|
|
#include <VrApi_SystemUtils.h>
|
|
|
|
#include <VrApi_Input.h>
|
|
|
|
#include <VrApi_Types.h>
|
|
|
|
|
|
|
|
#include "VrInput.h"
|
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
#include <qcommon/qcommon.h>
|
|
|
|
#include <qcommon/q_platform.h>
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-09-20 22:15:52 +00:00
|
|
|
cvar_t *vr_turn_mode;
|
|
|
|
cvar_t *vr_turn_angle;
|
|
|
|
cvar_t *vr_positional_factor;
|
|
|
|
cvar_t *vr_walkdirection;
|
|
|
|
cvar_t *vr_weapon_pitchadjust;
|
|
|
|
cvar_t *vr_control_scheme;
|
|
|
|
cvar_t *vr_virtual_stock;
|
|
|
|
cvar_t *vr_switch_sticks;
|
2022-09-27 22:19:12 +00:00
|
|
|
cvar_t *vr_immersive_cinematics;
|
2022-09-20 22:15:52 +00:00
|
|
|
cvar_t *vr_screen_dist;
|
2022-10-12 17:00:26 +00:00
|
|
|
cvar_t *vr_weapon_velocity_trigger;
|
2022-11-07 23:57:10 +00:00
|
|
|
cvar_t *vr_force_velocity_trigger;
|
2022-10-20 16:47:12 +00:00
|
|
|
cvar_t *vr_two_handed_weapons;
|
2022-11-07 23:57:10 +00:00
|
|
|
cvar_t *vr_force_motion_controlled;
|
2022-11-11 23:43:50 +00:00
|
|
|
cvar_t *vr_crouch_toggle;
|
2022-11-16 21:27:36 +00:00
|
|
|
cvar_t *vr_irl_crouch_enabled;
|
|
|
|
cvar_t *vr_irl_crouch_to_stand_ratio;
|
2022-11-12 17:05:39 +00:00
|
|
|
cvar_t *vr_saber_block_debounce_time;
|
2022-11-17 00:05:01 +00:00
|
|
|
cvar_t *vr_haptic_intensity;
|
2022-11-25 18:01:08 +00:00
|
|
|
cvar_t *vr_comfort_vignette;
|
2022-11-25 23:35:49 +00:00
|
|
|
cvar_t *vr_saber_3rdperson_mode;
|
2022-11-26 15:38:17 +00:00
|
|
|
cvar_t *vr_gesture_triggered_use;
|
|
|
|
cvar_t *vr_gesture_triggered_use_threshold;
|
2022-09-20 22:15:52 +00:00
|
|
|
|
|
|
|
ovrInputStateTrackedRemote leftTrackedRemoteState_old;
|
|
|
|
ovrInputStateTrackedRemote leftTrackedRemoteState_new;
|
|
|
|
ovrTracking leftRemoteTracking_new;
|
|
|
|
ovrInputStateTrackedRemote rightTrackedRemoteState_old;
|
|
|
|
ovrInputStateTrackedRemote rightTrackedRemoteState_new;
|
|
|
|
ovrTracking rightRemoteTracking_new;
|
|
|
|
ovrInputStateGamepad footTrackedRemoteState_old;
|
|
|
|
ovrInputStateGamepad footTrackedRemoteState_new;
|
|
|
|
ovrDeviceID controllerIDs[2];
|
|
|
|
|
|
|
|
float remote_movementSideways;
|
|
|
|
float remote_movementForward;
|
|
|
|
float remote_movementUp;
|
|
|
|
float positional_movementSideways;
|
|
|
|
float positional_movementForward;
|
2022-09-29 22:38:22 +00:00
|
|
|
bool openjk_initialised;
|
2022-09-20 22:15:52 +00:00
|
|
|
long long global_time;
|
|
|
|
ovrTracking2 tracking;
|
|
|
|
int ducked;
|
|
|
|
vr_client_info_t vr;
|
|
|
|
|
2022-09-18 15:37:21 +00:00
|
|
|
//keys.h
|
|
|
|
void Sys_QueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr );
|
|
|
|
void handleTrackedControllerButton(ovrInputStateTrackedRemote * trackedRemoteState, ovrInputStateTrackedRemote * prevTrackedRemoteState, uint32_t button, int key)
|
|
|
|
{
|
|
|
|
if ((trackedRemoteState->Buttons & button) != (prevTrackedRemoteState->Buttons & button))
|
|
|
|
{
|
|
|
|
Sys_QueEvent( 0, SE_KEY, key, (trackedRemoteState->Buttons & button) != 0, 0, NULL );
|
|
|
|
// Key_Event(key, (trackedRemoteState->Buttons & button) != 0, global_time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rotateAboutOrigin(float x, float y, float rotation, vec2_t out)
|
|
|
|
{
|
|
|
|
out[0] = cosf(DEG2RAD(-rotation)) * x + sinf(DEG2RAD(-rotation)) * y;
|
|
|
|
out[1] = cosf(DEG2RAD(-rotation)) * y - sinf(DEG2RAD(-rotation)) * x;
|
|
|
|
}
|
|
|
|
|
|
|
|
float length(float x, float y)
|
|
|
|
{
|
|
|
|
return sqrtf(powf(x, 2.0f) + powf(y, 2.0f));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NLF_DEADZONE 0.1
|
|
|
|
#define NLF_POWER 2.2
|
|
|
|
|
|
|
|
float nonLinearFilter(float in)
|
|
|
|
{
|
|
|
|
float val = 0.0f;
|
|
|
|
if (in > NLF_DEADZONE)
|
|
|
|
{
|
|
|
|
val = in;
|
|
|
|
val -= NLF_DEADZONE;
|
|
|
|
val /= (1.0f - NLF_DEADZONE);
|
|
|
|
val = powf(val, NLF_POWER);
|
|
|
|
}
|
|
|
|
else if (in < -NLF_DEADZONE)
|
|
|
|
{
|
|
|
|
val = in;
|
|
|
|
val += NLF_DEADZONE;
|
|
|
|
val /= (1.0f - NLF_DEADZONE);
|
|
|
|
val = -powf(fabsf(val), NLF_POWER);
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendButtonActionSimple(const char* action)
|
|
|
|
{
|
|
|
|
char command[256];
|
|
|
|
snprintf( command, sizeof( command ), "%s\n", action );
|
|
|
|
Cbuf_AddText( command );
|
|
|
|
}
|
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
bool between(float min, float val, float max)
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
|
|
|
return (min < val) && (val < max);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendButtonAction(const char* action, long buttonDown)
|
|
|
|
{
|
|
|
|
char command[256];
|
|
|
|
snprintf( command, sizeof( command ), "%s\n", action );
|
|
|
|
if (!buttonDown)
|
|
|
|
{
|
|
|
|
command[0] = '-';
|
|
|
|
}
|
|
|
|
Cbuf_AddText( command );
|
|
|
|
}
|
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
void acquireTrackedRemotesData(ovrMobile *Ovr, double displayTime) {//The amount of yaw changed by controller
|
|
|
|
|
|
|
|
for ( uint32_t i = 0; ; i++ ) {
|
2022-09-18 15:37:21 +00:00
|
|
|
ovrInputCapabilityHeader cap;
|
|
|
|
ovrResult result = vrapi_EnumerateInputDevices(Ovr, i, &cap);
|
|
|
|
if (result < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cap.Type == ovrControllerType_Gamepad) {
|
|
|
|
|
|
|
|
ovrInputGamepadCapabilities remoteCaps;
|
|
|
|
remoteCaps.Header = cap;
|
|
|
|
if (vrapi_GetInputDeviceCapabilities(Ovr, &remoteCaps.Header) >= 0) {
|
|
|
|
// remote is connected
|
|
|
|
ovrInputStateGamepad remoteState;
|
|
|
|
remoteState.Header.ControllerType = ovrControllerType_Gamepad;
|
|
|
|
if ( vrapi_GetCurrentInputState( Ovr, cap.DeviceID, &remoteState.Header ) >= 0 )
|
|
|
|
{
|
|
|
|
// act on device state returned in remoteState
|
|
|
|
footTrackedRemoteState_new = remoteState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cap.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortableMouseAbs(float x,float y);
|
|
|
|
float clamp(float _min, float _val, float _max)
|
|
|
|
{
|
2022-09-19 21:46:47 +00:00
|
|
|
return fmax(fmin(_val, _max), _min);
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
void interactWithTouchScreen(bool reset, ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemote *oldState) {
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-04 21:48:30 +00:00
|
|
|
static float centerYaw = 0;
|
2022-10-05 20:54:36 +00:00
|
|
|
if (reset || Q_isnan(centerYaw) || fabs(sinf(DEG2RAD(vr.weaponangles[YAW]-centerYaw))) > 0.9f)
|
2022-10-04 21:48:30 +00:00
|
|
|
{
|
|
|
|
centerYaw = vr.weaponangles[YAW];
|
|
|
|
}
|
|
|
|
float cursorX = -sinf(DEG2RAD(vr.weaponangles[YAW]-centerYaw)) + 0.5f;
|
2022-09-23 22:10:32 +00:00
|
|
|
float cursorY = (float)(vr.weaponangles[PITCH] / 90.0) + 0.5f;
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
PortableMouseAbs(cursorX, cursorY);
|
|
|
|
}
|