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_reloadtimeoutms;
|
|
|
|
cvar_t *vr_positional_factor;
|
|
|
|
cvar_t *vr_walkdirection;
|
|
|
|
cvar_t *vr_movement_multiplier;
|
|
|
|
cvar_t *vr_weapon_pitchadjust;
|
|
|
|
cvar_t *vr_lasersight;
|
|
|
|
cvar_t *vr_control_scheme;
|
|
|
|
cvar_t *vr_teleport;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
float playerHeight;
|
|
|
|
float playerYaw;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//YAW: Left increase, Right decrease
|
|
|
|
void updateScopeAngles()
|
|
|
|
{
|
|
|
|
//Bit of a hack, but use weapon orientation / position for view when scope is engaged
|
|
|
|
static vec3_t currentScopeAngles;
|
|
|
|
static vec3_t lastScopeAngles;
|
|
|
|
if (vr.scopeengaged)
|
|
|
|
{
|
|
|
|
VectorSet(currentScopeAngles, vr.weaponangles[PITCH], vr.weaponangles[YAW], vr.hmdorientation[ROLL]);
|
|
|
|
|
|
|
|
//Set "view" Angles
|
|
|
|
VectorCopy(currentScopeAngles, vr.hmdorientation);
|
|
|
|
|
|
|
|
//Orientation
|
|
|
|
VectorSubtract(lastScopeAngles, currentScopeAngles, vr.hmdorientation_delta);
|
|
|
|
|
|
|
|
//Keep this for our records
|
|
|
|
VectorCopy(currentScopeAngles, lastScopeAngles);
|
|
|
|
} else {
|
|
|
|
VectorSet(currentScopeAngles, vr.weaponangles[PITCH], vr.weaponangles[YAW], vr.hmdorientation[ROLL]);
|
|
|
|
VectorCopy(currentScopeAngles, lastScopeAngles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (reset || fabs(sinf(DEG2RAD(vr.weaponangles[YAW]-centerYaw))) > 0.5f)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|