2022-09-18 15:37:21 +00:00
|
|
|
/************************************************************************************
|
|
|
|
|
|
|
|
Filename : VrInputDefault.c
|
|
|
|
Content : Handles default controller input
|
|
|
|
Created : August 2019
|
|
|
|
Authors : Simon Brown
|
|
|
|
|
|
|
|
*************************************************************************************/
|
|
|
|
|
2022-10-03 21:19:00 +00:00
|
|
|
#include <VrApi.h>
|
|
|
|
#include <VrApi_Helpers.h>
|
|
|
|
#include <VrApi_SystemUtils.h>
|
|
|
|
#include <VrApi_Input.h>
|
|
|
|
#include <VrApi_Types.h>
|
|
|
|
|
2022-09-18 15:37:21 +00:00
|
|
|
#include <android/keycodes.h>
|
|
|
|
|
|
|
|
#include "VrInput.h"
|
|
|
|
#include "VrCvars.h"
|
|
|
|
|
2022-10-03 21:19:00 +00:00
|
|
|
#include "qcommon/q_shared.h"
|
2022-09-19 21:46:47 +00:00
|
|
|
#include <qcommon/qcommon.h>
|
|
|
|
#include <client/client.h>
|
2022-10-03 21:19:00 +00:00
|
|
|
#include "android/sys_local.h"
|
2022-10-10 20:56:08 +00:00
|
|
|
#include "weapons.h"
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SV_Trace( trace_t *results, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int passEntityNum, int contentmask, int capsule );
|
|
|
|
|
|
|
|
void JKVR_HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight );
|
|
|
|
|
|
|
|
static inline float AngleBetweenVectors(const vec3_t a, const vec3_t b)
|
|
|
|
{
|
|
|
|
return degrees(acosf(DotProduct(a, b)/(VectorLength(a) * VectorLength(b))));
|
|
|
|
}
|
|
|
|
|
|
|
|
void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateGamepad *pFootTrackingOld,
|
|
|
|
ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
|
|
|
|
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking,
|
|
|
|
int domButton1, int domButton2, int offButton1, int offButton2 )
|
|
|
|
|
|
|
|
{
|
|
|
|
//Ensure handedness is set correctly
|
|
|
|
vr.right_handed = vr_control_scheme->value < 10 ||
|
|
|
|
vr_control_scheme->value == 99; // Always right-handed for weapon calibration
|
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
static bool dominantGripPushed = false;
|
2022-09-18 15:37:21 +00:00
|
|
|
static float dominantGripPushTime = 0.0f;
|
|
|
|
static bool canUseBackpack = false;
|
|
|
|
static bool canUseQuickSave = false;
|
|
|
|
|
|
|
|
//Need this for the touch screen
|
|
|
|
ovrTracking * pWeapon = pDominantTracking;
|
|
|
|
ovrTracking * pOff = pOffTracking;
|
|
|
|
|
|
|
|
//All this to allow stick and button switching!
|
|
|
|
ovrVector2f *pPrimaryJoystick;
|
|
|
|
ovrVector2f *pSecondaryJoystick;
|
|
|
|
uint32_t primaryButtonsNew;
|
|
|
|
uint32_t primaryButtonsOld;
|
|
|
|
uint32_t secondaryButtonsNew;
|
|
|
|
uint32_t secondaryButtonsOld;
|
|
|
|
int primaryButton1;
|
|
|
|
int primaryButton2;
|
|
|
|
int secondaryButton1;
|
|
|
|
int secondaryButton2;
|
2022-09-29 19:18:23 +00:00
|
|
|
int primaryThumb = vr_control_scheme->value == RIGHT_HANDED_DEFAULT ? ovrButton_RThumb : ovrButton_LThumb;
|
|
|
|
int secondaryThumb = vr_control_scheme->value == RIGHT_HANDED_DEFAULT ? ovrButton_LThumb : ovrButton_RThumb;
|
2022-09-18 15:37:21 +00:00
|
|
|
if (vr_switch_sticks->integer)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// This will switch the joystick and A/B/X/Y button functions only
|
|
|
|
// Move, Strafe, Turn, Jump, Crouch, Notepad, HUD mode, Weapon Switch
|
|
|
|
pSecondaryJoystick = &pDominantTrackedRemoteNew->Joystick;
|
|
|
|
pPrimaryJoystick = &pOffTrackedRemoteNew->Joystick;
|
|
|
|
secondaryButtonsNew = pDominantTrackedRemoteNew->Buttons;
|
|
|
|
secondaryButtonsOld = pDominantTrackedRemoteOld->Buttons;
|
|
|
|
primaryButtonsNew = pOffTrackedRemoteNew->Buttons;
|
|
|
|
primaryButtonsOld = pOffTrackedRemoteOld->Buttons;
|
|
|
|
primaryButton1 = offButton1;
|
|
|
|
primaryButton2 = offButton2;
|
|
|
|
secondaryButton1 = domButton1;
|
|
|
|
secondaryButton2 = domButton2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pPrimaryJoystick = &pDominantTrackedRemoteNew->Joystick;
|
|
|
|
pSecondaryJoystick = &pOffTrackedRemoteNew->Joystick;
|
|
|
|
primaryButtonsNew = pDominantTrackedRemoteNew->Buttons;
|
|
|
|
primaryButtonsOld = pDominantTrackedRemoteOld->Buttons;
|
|
|
|
secondaryButtonsNew = pOffTrackedRemoteNew->Buttons;
|
|
|
|
secondaryButtonsOld = pOffTrackedRemoteOld->Buttons;
|
|
|
|
primaryButton1 = domButton1;
|
|
|
|
primaryButton2 = domButton2;
|
|
|
|
secondaryButton1 = offButton1;
|
|
|
|
secondaryButton2 = offButton2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
//Set gun angles - We need to calculate all those we might need (including adjustments) for the client to then take its pick
|
|
|
|
vec3_t rotation = {0};
|
2022-10-02 22:17:51 +00:00
|
|
|
rotation[PITCH] = 45;
|
|
|
|
QuatToYawPitchRoll(pWeapon->HeadPose.Pose.Orientation, rotation, vr.weaponangles_saber);
|
2022-09-29 22:38:22 +00:00
|
|
|
rotation[PITCH] = vr_weapon_pitchadjust->value;
|
2022-09-18 15:37:21 +00:00
|
|
|
QuatToYawPitchRoll(pWeapon->HeadPose.Pose.Orientation, rotation, vr.weaponangles);
|
|
|
|
|
|
|
|
VectorSubtract(vr.weaponangles_last, vr.weaponangles, vr.weaponangles_delta);
|
|
|
|
VectorCopy(vr.weaponangles, vr.weaponangles_last);
|
|
|
|
|
2022-10-04 21:48:30 +00:00
|
|
|
// ALOGV(" weaponangles_last: %f, %f, %f",
|
|
|
|
// vr.weaponangles_last[0], vr.weaponangles_last[1], vr.weaponangles_last[2]);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
//GB Also set offhand angles just in case we want to use those.
|
|
|
|
vec3_t rotation_off = {0};
|
|
|
|
rotation_off[PITCH] = vr_weapon_pitchadjust->value;
|
|
|
|
QuatToYawPitchRoll(pOff->HeadPose.Pose.Orientation, rotation_off, vr.offhandangles);
|
|
|
|
|
|
|
|
VectorSubtract(vr.offhandangles_last, vr.offhandangles, vr.offhandangles_delta);
|
|
|
|
VectorCopy(vr.offhandangles, vr.offhandangles_last);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Menu button
|
2022-09-19 21:46:47 +00:00
|
|
|
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, ovrButton_Enter, A_ESCAPE);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
static bool resetCursor = qtrue;
|
2022-09-18 15:37:21 +00:00
|
|
|
if ( JKVR_useScreenLayer() )
|
|
|
|
{
|
|
|
|
interactWithTouchScreen(resetCursor, pDominantTrackedRemoteNew, pDominantTrackedRemoteOld);
|
|
|
|
resetCursor = qfalse;
|
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, A_MOUSE1);
|
|
|
|
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, ovrButton_Trigger, A_MOUSE1);
|
|
|
|
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, A_ESCAPE);
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resetCursor = qtrue;
|
|
|
|
|
|
|
|
float distance = sqrtf(powf(pOff->HeadPose.Pose.Position.x - pWeapon->HeadPose.Pose.Position.x, 2) +
|
|
|
|
powf(pOff->HeadPose.Pose.Position.y - pWeapon->HeadPose.Pose.Position.y, 2) +
|
|
|
|
powf(pOff->HeadPose.Pose.Position.z - pWeapon->HeadPose.Pose.Position.z, 2));
|
|
|
|
|
|
|
|
float distanceToHMD = sqrtf(powf(vr.hmdposition[0] - pWeapon->HeadPose.Pose.Position.x, 2) +
|
|
|
|
powf(vr.hmdposition[1] - pWeapon->HeadPose.Pose.Position.y, 2) +
|
|
|
|
powf(vr.hmdposition[2] - pWeapon->HeadPose.Pose.Position.z, 2));
|
|
|
|
|
|
|
|
float distanceToHMDOff = sqrtf(powf(vr.hmdposition[0] - pOff->HeadPose.Pose.Position.x, 2) +
|
|
|
|
powf(vr.hmdposition[1] - pOff->HeadPose.Pose.Position.y, 2) +
|
|
|
|
powf(vr.hmdposition[2] - pOff->HeadPose.Pose.Position.z, 2));
|
|
|
|
|
|
|
|
float controllerYawHeading = 0.0f;
|
|
|
|
//Turn on weapon stabilisation?
|
2022-09-19 21:46:47 +00:00
|
|
|
bool stabilised = qfalse;
|
2022-09-30 23:02:49 +00:00
|
|
|
bool offhandGripPushed = (pOffTrackedRemoteNew->Buttons & ovrButton_GripTrigger);
|
|
|
|
if ( (offhandGripPushed != (pOffTrackedRemoteOld->Buttons & ovrButton_GripTrigger)) &&
|
|
|
|
offhandGripPushed && (distance < STABILISATION_DISTANCE))
|
2022-10-12 17:00:26 +00:00
|
|
|
//#ifndef DEBUG
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
|
|
|
stabilised = qtrue;
|
|
|
|
}
|
2022-10-12 17:00:26 +00:00
|
|
|
//#else
|
|
|
|
// {
|
|
|
|
// Cvar_Set("vr_control_scheme", "99");
|
|
|
|
// }
|
|
|
|
//#endif
|
|
|
|
|
|
|
|
dominantGripPushed = (pDominantTrackedRemoteNew->Buttons &
|
|
|
|
ovrButton_GripTrigger) != 0;
|
|
|
|
bool dominantButton1Pushed = (pDominantTrackedRemoteNew->Buttons &
|
|
|
|
domButton1) != 0;
|
|
|
|
bool dominantButton2Pushed = (pDominantTrackedRemoteNew->Buttons &
|
|
|
|
domButton2) != 0;
|
|
|
|
|
|
|
|
//Do this early so we can suppress other button actions when item selector is up
|
2022-09-30 23:02:49 +00:00
|
|
|
{
|
2022-10-12 17:00:26 +00:00
|
|
|
if (dominantGripPushed) {
|
|
|
|
if (dominantGripPushTime == 0) {
|
|
|
|
dominantGripPushTime = GetTimeInMilliSeconds();
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
2022-10-12 17:00:26 +00:00
|
|
|
vr.item_selector = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dominantGripPushTime = 0;
|
|
|
|
if (vr.item_selector)
|
|
|
|
{
|
|
|
|
sendButtonActionSimple("itemselectorselect");
|
|
|
|
vr.item_selector = false;
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
#define JOYX_SAMPLE_COUNT 4
|
|
|
|
static float joyx[JOYX_SAMPLE_COUNT] = {0};
|
|
|
|
for (int j = JOYX_SAMPLE_COUNT - 1; j > 0; --j)
|
|
|
|
joyx[j] = joyx[j - 1];
|
|
|
|
joyx[0] = pPrimaryJoystick->x;
|
|
|
|
float sum = 0.0f;
|
|
|
|
for (int j = 0; j < JOYX_SAMPLE_COUNT; ++j)
|
|
|
|
sum += joyx[j];
|
|
|
|
float primaryJoystickX = sum / 4.0f;
|
|
|
|
|
2022-10-02 22:17:51 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//Left/right to switch between which selector we are using
|
|
|
|
if (vr.item_selector) {
|
|
|
|
static bool itemSwitched = false;
|
|
|
|
if (between(-0.2f, pPrimaryJoystick->y, 0.2f) &&
|
|
|
|
(between(0.8f, primaryJoystickX, 1.0f) ||
|
|
|
|
between(-1.0f, primaryJoystickX, -0.8f))) {
|
|
|
|
if (!itemSwitched) {
|
|
|
|
if (between(0.8f, primaryJoystickX, 1.0f)) {
|
|
|
|
sendButtonActionSimple("itemselectornext");
|
|
|
|
} else {
|
|
|
|
sendButtonActionSimple("itemselectorprev");
|
2022-10-04 21:48:30 +00:00
|
|
|
}
|
2022-10-12 17:00:26 +00:00
|
|
|
itemSwitched = true;
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
2022-10-12 17:00:26 +00:00
|
|
|
} else {
|
|
|
|
itemSwitched = false;
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
2022-10-12 17:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vr.weapon_stabilised = stabilised;
|
|
|
|
|
|
|
|
//if (!vr.item_selector)
|
|
|
|
{
|
|
|
|
//Engage scope / virtual stock if conditions are right
|
|
|
|
bool scopeready = vr.weapon_stabilised && (distanceToHMD < SCOPE_ENGAGE_DISTANCE);
|
|
|
|
static bool lastScopeReady = qfalse;
|
|
|
|
if (scopeready != lastScopeReady) {
|
|
|
|
if (vr.scopedweapon && !vr.scopedetached) {
|
|
|
|
if (!vr.scopeengaged && scopeready) {
|
|
|
|
ALOGV("**WEAPON EVENT** trigger scope mode");
|
|
|
|
sendButtonActionSimple("weapalt");
|
|
|
|
} else if (vr.scopeengaged && !scopeready) {
|
|
|
|
ALOGV("**WEAPON EVENT** disable scope mode");
|
|
|
|
sendButtonActionSimple("weapalt");
|
2022-10-10 20:56:08 +00:00
|
|
|
}
|
2022-10-12 17:00:26 +00:00
|
|
|
lastScopeReady = scopeready;
|
2022-10-10 20:56:08 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//ALOGV("**GB WEAPON ACTIVE** %i",vr.weaponid);
|
|
|
|
if (!scopeready && vr.weaponid >= 15 && vr.weaponid <= 17) {
|
|
|
|
lastScopeReady = false;
|
|
|
|
ALOGV("**WEAPON EVENT** disable scope mode forced");
|
|
|
|
sendButtonActionSimple("weapalt");
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//Engage scope / virtual stock (iron sight lock) if conditions are right
|
|
|
|
static bool scopeEngaged = qfalse;
|
|
|
|
if (scopeEngaged != vr.scopeengaged) {
|
|
|
|
scopeEngaged = vr.scopeengaged;
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//dominant hand stuff first
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
2022-10-12 17:00:26 +00:00
|
|
|
//Record recent weapon position for trajectory based stuff
|
|
|
|
for (int i = (NUM_WEAPON_SAMPLES - 1); i != 0; --i) {
|
|
|
|
VectorCopy(vr.weaponoffset_history[i - 1], vr.weaponoffset_history[i]);
|
|
|
|
vr.weaponoffset_history_timestamp[i] = vr.weaponoffset_history_timestamp[i - 1];
|
|
|
|
}
|
|
|
|
VectorCopy(vr.weaponoffset, vr.weaponoffset_history[0]);
|
|
|
|
vr.weaponoffset_history_timestamp[0] = vr.weaponoffset_timestamp;
|
|
|
|
|
|
|
|
VectorSet(vr.weaponposition, pWeapon->HeadPose.Pose.Position.x,
|
|
|
|
pWeapon->HeadPose.Pose.Position.y, pWeapon->HeadPose.Pose.Position.z);
|
|
|
|
|
|
|
|
///Weapon location relative to view
|
|
|
|
VectorSet(vr.weaponoffset, pWeapon->HeadPose.Pose.Position.x,
|
|
|
|
pWeapon->HeadPose.Pose.Position.y, pWeapon->HeadPose.Pose.Position.z);
|
|
|
|
VectorSubtract(vr.weaponoffset, vr.hmdposition, vr.weaponoffset);
|
|
|
|
vr.weaponoffset_timestamp = Sys_Milliseconds();
|
|
|
|
|
|
|
|
vec3_t velocity;
|
|
|
|
VectorSet(velocity, pWeapon->HeadPose.LinearVelocity.x,
|
|
|
|
pWeapon->HeadPose.LinearVelocity.y, pWeapon->HeadPose.LinearVelocity.z);
|
|
|
|
vr.primaryswingvelocity = VectorLength(velocity);
|
|
|
|
|
|
|
|
VectorSet(velocity, pOff->HeadPose.LinearVelocity.x,
|
|
|
|
pOff->HeadPose.LinearVelocity.y, pOff->HeadPose.LinearVelocity.z);
|
|
|
|
vr.secondaryswingvelocity = VectorLength(velocity);
|
|
|
|
|
|
|
|
|
|
|
|
//For melee right hand is alt attack and left hand is attack
|
|
|
|
if (vr.weaponid == WP_MELEE) {
|
|
|
|
//Does weapon velocity trigger attack (melee) and is it fast enough
|
|
|
|
if (vr.velocitytriggered) {
|
|
|
|
static bool fired = false;
|
|
|
|
vr.primaryVelocityTriggeredAttack = (vr.primaryswingvelocity >
|
|
|
|
vr_weapon_velocity_trigger->value);
|
|
|
|
|
|
|
|
if (fired != vr.primaryVelocityTriggeredAttack) {
|
|
|
|
ALOGV("**WEAPON EVENT** veocity triggered %s",
|
|
|
|
vr.primaryVelocityTriggeredAttack ? "+altattack" : "-altattack");
|
|
|
|
//normal attack is a punch with the left hand
|
|
|
|
sendButtonAction("+altattack", vr.primaryVelocityTriggeredAttack);
|
|
|
|
fired = vr.primaryVelocityTriggeredAttack;
|
|
|
|
}
|
|
|
|
} else if (vr.primaryVelocityTriggeredAttack) {
|
|
|
|
//send a stop attack as we have an unfinished velocity attack
|
|
|
|
vr.primaryVelocityTriggeredAttack = false;
|
|
|
|
ALOGV("**WEAPON EVENT** veocity triggered -altattack");
|
|
|
|
sendButtonAction("+altattack", vr.primaryVelocityTriggeredAttack);
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
if (vr.velocitytriggered) {
|
|
|
|
static bool fired = false;
|
|
|
|
vr.secondaryVelocityTriggeredAttack = (vr.secondaryswingvelocity >
|
|
|
|
vr_weapon_velocity_trigger->value);
|
|
|
|
|
|
|
|
if (fired != vr.secondaryVelocityTriggeredAttack) {
|
|
|
|
ALOGV("**WEAPON EVENT** veocity triggered %s",
|
|
|
|
vr.secondaryVelocityTriggeredAttack ? "+attack" : "-attack");
|
|
|
|
//normal attack is a punch with the left hand
|
|
|
|
sendButtonAction("+attack", vr.secondaryVelocityTriggeredAttack);
|
|
|
|
fired = vr.secondaryVelocityTriggeredAttack;
|
|
|
|
}
|
|
|
|
} else if (vr.secondaryVelocityTriggeredAttack) {
|
|
|
|
//send a stop attack as we have an unfinished velocity attack
|
|
|
|
vr.secondaryVelocityTriggeredAttack = qfalse;
|
|
|
|
ALOGV("**WEAPON EVENT** veocity triggered -attack");
|
|
|
|
sendButtonAction("+attack", vr.secondaryVelocityTriggeredAttack);
|
|
|
|
}
|
|
|
|
} else if (vr.weaponid == WP_SABER) {
|
|
|
|
//Does weapon velocity trigger attack
|
|
|
|
if (vr.velocitytriggered) {
|
|
|
|
static bool fired = false;
|
|
|
|
vr.primaryVelocityTriggeredAttack = (vr.primaryswingvelocity >
|
|
|
|
vr_weapon_velocity_trigger->value);
|
|
|
|
|
|
|
|
if (fired != vr.primaryVelocityTriggeredAttack) {
|
|
|
|
ALOGV("**WEAPON EVENT** veocity triggered %s",
|
|
|
|
vr.primaryVelocityTriggeredAttack ? "+attack" : "-attack");
|
|
|
|
//normal attack is a punch with the left hand
|
|
|
|
sendButtonAction("+attack", vr.primaryVelocityTriggeredAttack);
|
|
|
|
fired = vr.primaryVelocityTriggeredAttack;
|
|
|
|
}
|
|
|
|
} else if (vr.primaryVelocityTriggeredAttack) {
|
|
|
|
//send a stop attack as we have an unfinished velocity attack
|
|
|
|
vr.primaryVelocityTriggeredAttack = false;
|
|
|
|
ALOGV("**WEAPON EVENT** veocity triggered -attack");
|
|
|
|
sendButtonAction("+attack", vr.primaryVelocityTriggeredAttack);
|
|
|
|
}
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
if (vr.weapon_stabilised) {
|
|
|
|
if (vr.scopeengaged || vr_virtual_stock->integer == 1) {
|
|
|
|
//offset to the appropriate eye a little bit
|
|
|
|
vec2_t xy;
|
|
|
|
rotateAboutOrigin(Cvar_VariableValue("cg_stereoSeparation") / 2.0f, 0.0f,
|
|
|
|
-vr.hmdorientation[YAW], xy);
|
|
|
|
float x = pOff->HeadPose.Pose.Position.x - (vr.hmdposition[0] + xy[0]);
|
|
|
|
float y = pOff->HeadPose.Pose.Position.y -
|
|
|
|
(vr.hmdposition[1] - 0.1f); // Use a point lower
|
|
|
|
float z = pOff->HeadPose.Pose.Position.z - (vr.hmdposition[2] + xy[1]);
|
|
|
|
float zxDist = length(x, z);
|
|
|
|
|
|
|
|
if (zxDist != 0.0f && z != 0.0f) {
|
|
|
|
VectorSet(vr.weaponangles, -degrees(atanf(y / zxDist)),
|
|
|
|
-degrees(atan2f(x, -z)), 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
float x =
|
|
|
|
pOff->HeadPose.Pose.Position.x - pWeapon->HeadPose.Pose.Position.x;
|
|
|
|
float y =
|
|
|
|
pOff->HeadPose.Pose.Position.y - pWeapon->HeadPose.Pose.Position.y;
|
|
|
|
float z =
|
|
|
|
pOff->HeadPose.Pose.Position.z - pWeapon->HeadPose.Pose.Position.z;
|
|
|
|
float zxDist = length(x, z);
|
|
|
|
|
|
|
|
if (zxDist != 0.0f && z != 0.0f) {
|
|
|
|
VectorSet(vr.weaponangles, -degrees(atanf(y / zxDist)),
|
|
|
|
-degrees(atan2f(x, -z)), vr.weaponangles[ROLL] /
|
|
|
|
2.0f); //Dampen roll on stabilised weapon
|
|
|
|
}
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
// Calculate if player tries to reach backpack
|
|
|
|
bool handInBackpack = false;
|
|
|
|
bool bpDistToHMDOk = false, bpWeaponHeightOk = false, bpWeaponAngleOk = false, bpHmdToWeaponAngleOk = false;
|
|
|
|
vec3_t hmdForwardXY = {}, weaponForwardXY = {};
|
|
|
|
float weaponToDownAngle = 0, hmdToWeaponDotProduct = 0;
|
|
|
|
static vec3_t downVector = {0.0, 0.0, -1.0};
|
|
|
|
|
|
|
|
bool bpTrackOk = pOffTracking->Status &
|
|
|
|
VRAPI_TRACKING_STATUS_POSITION_TRACKED; // 1) Position must be tracked
|
|
|
|
if (bpTrackOk && (bpDistToHMDOk = distanceToHMD >= 0.2 && distanceToHMD <=
|
|
|
|
0.35) // 2) Weapon-to-HMD distance must be within <0.2-0.35> range
|
|
|
|
&& (bpWeaponHeightOk = vr.weaponoffset[1] >= -0.10 && vr.weaponoffset[1] <=
|
|
|
|
0.10)) // 3) Weapon height in relation to HMD must be within <-0.10, 0.10> range
|
|
|
|
{
|
|
|
|
AngleVectors(vr.hmdorientation, hmdForwardXY, NULL, NULL);
|
|
|
|
AngleVectors(vr.weaponangles, weaponForwardXY, NULL, NULL);
|
2022-09-27 22:19:12 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
float weaponToDownAngle = AngleBetweenVectors(downVector, weaponForwardXY);
|
|
|
|
// 4) Angle between weapon forward vector and a down vector must be within 80-140 degrees
|
|
|
|
if (bpWeaponAngleOk = weaponToDownAngle >= 80.0 && weaponToDownAngle <= 140.0) {
|
|
|
|
hmdForwardXY[2] = 0;
|
|
|
|
VectorNormalize(hmdForwardXY);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
weaponForwardXY[2] = 0;
|
|
|
|
VectorNormalize(weaponForwardXY);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
hmdToWeaponDotProduct = DotProduct(hmdForwardXY, weaponForwardXY);
|
|
|
|
// 5) HMD and weapon forward on XY plane must go in opposite directions (i.e. dot product < 0)
|
|
|
|
handInBackpack = bpHmdToWeaponAngleOk = hmdToWeaponDotProduct < 0;
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
2022-10-12 17:00:26 +00:00
|
|
|
|
|
|
|
//off-hand stuff (done here as I reference it in the save state thing
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
2022-10-12 17:00:26 +00:00
|
|
|
vr.offhandposition[0] = pOff->HeadPose.Pose.Position.x;
|
|
|
|
vr.offhandposition[1] = pOff->HeadPose.Pose.Position.y;
|
|
|
|
vr.offhandposition[2] = pOff->HeadPose.Pose.Position.z;
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
vr.offhandoffset[0] = pOff->HeadPose.Pose.Position.x - vr.hmdposition[0];
|
|
|
|
vr.offhandoffset[1] = pOff->HeadPose.Pose.Position.y - vr.hmdposition[1];
|
|
|
|
vr.offhandoffset[2] = pOff->HeadPose.Pose.Position.z - vr.hmdposition[2];
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
vec3_t rotation = {0};
|
|
|
|
QuatToYawPitchRoll(pOff->HeadPose.Pose.Orientation, rotation, vr.offhandangles);
|
|
|
|
|
|
|
|
if (vr_walkdirection->value == 0) {
|
|
|
|
controllerYawHeading = vr.offhandangles[YAW] - vr.hmdorientation[YAW];
|
|
|
|
} else {
|
|
|
|
controllerYawHeading = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
// Use off hand as well to trigger save condition
|
|
|
|
canUseQuickSave = false;
|
|
|
|
bool bpOffhandDistToHMDOk = false, bpOffhandHeightOk = false, bpOffhandAngleOk = false, bpHmdToOffhandAngleOk = false;
|
|
|
|
vec3_t offhandForwardXY = {};
|
|
|
|
float hmdToOffhandDotProduct = 0;
|
|
|
|
float offhandToDownAngle = 0;
|
|
|
|
if (bpTrackOk && (bpOffhandDistToHMDOk = distanceToHMDOff >= 0.2 &&
|
|
|
|
distanceToHMDOff <=
|
|
|
|
0.35) // 2) Off-to-HMD distance must be within <0.2-0.35> range
|
|
|
|
&& (bpOffhandHeightOk = vr.offhandoffset[1] >= -0.10 && vr.offhandoffset[1] <=
|
|
|
|
0.10)) // 3) Offhand height in relation to HMD must be within <-0.10, 0.10> range
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
2022-10-12 17:00:26 +00:00
|
|
|
//Need to do this again as might not have done it above and cant be bothered to refactor
|
|
|
|
AngleVectors(vr.hmdorientation, hmdForwardXY, NULL, NULL);
|
|
|
|
AngleVectors(vr.offhandangles, offhandForwardXY, NULL, NULL);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
offhandToDownAngle = AngleBetweenVectors(downVector, offhandForwardXY);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
// 4) Angle between weapon forward vector and a down vector must be within 80-140 degrees
|
|
|
|
if (bpOffhandAngleOk =
|
|
|
|
offhandToDownAngle >= 80.0 && offhandToDownAngle <= 140.0) {
|
|
|
|
hmdForwardXY[2] = 0;
|
|
|
|
VectorNormalize(hmdForwardXY);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
offhandForwardXY[2] = 0;
|
|
|
|
VectorNormalize(offhandForwardXY);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
hmdToOffhandDotProduct = DotProduct(hmdForwardXY, offhandForwardXY);
|
|
|
|
// 5) HMD and weapon forward on XY plane must go in opposite directions (i.e. dot product < 0)
|
|
|
|
canUseQuickSave = bpHmdToOffhandAngleOk = hmdToOffhandDotProduct < 0;
|
|
|
|
}
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
// Uncomment to debug offhand reaching
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
ALOGV("Quick Save> Dist: %f | OffHandToDownAngle: %f | HandOffs: %f %f %f\nHmdHandDot: %f | HmdFwdXY: %f %f | WpnFwdXY: %f %f\nTrackOk: %i, DistOk: %i, HeightOk: %i, HnadAngleOk: %i, HmdHandDotOk: %i",
|
|
|
|
distanceToHMDOff, offhandToDownAngle, vr.offhandoffset[0],
|
|
|
|
vr.offhandoffset[1], vr.offhandoffset[2],
|
|
|
|
hmdToOffhandDotProduct, hmdForwardXY[0], hmdForwardXY[1], offhandForwardXY[0],
|
|
|
|
offhandForwardXY[1],
|
|
|
|
bpTrackOk, bpOffhandDistToHMDOk, bpOffhandHeightOk, bpOffhandAngleOk,
|
|
|
|
bpHmdToOffhandAngleOk);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
// Check quicksave
|
|
|
|
if (canUseQuickSave) {
|
|
|
|
int channel = (vr_control_scheme->integer >= 10) ? 1 : 0;
|
|
|
|
JKVR_Vibrate(40, channel, 0.5); // vibrate to let user know they can switch
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
if (((pOffTrackedRemoteNew->Buttons & offButton1) !=
|
|
|
|
(pOffTrackedRemoteOld->Buttons & offButton1)) &&
|
|
|
|
(pOffTrackedRemoteNew->Buttons & offButton1)) {
|
|
|
|
sendButtonActionSimple("savegame quicksave");
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
if (((pOffTrackedRemoteNew->Buttons & offButton2) !=
|
|
|
|
(pOffTrackedRemoteOld->Buttons & offButton2)) &&
|
|
|
|
(pOffTrackedRemoteNew->Buttons & offButton2)) {
|
|
|
|
sendButtonActionSimple("loadgame quicksave");
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//Right-hand specific stuff
|
2022-09-29 22:38:22 +00:00
|
|
|
{
|
2022-10-12 17:00:26 +00:00
|
|
|
//This section corrects for the fact that the controller actually controls direction of movement, but we want to move relative to the direction the
|
|
|
|
//player is facing for positional tracking
|
|
|
|
|
|
|
|
//Positional movement speed correction for when we are not hitting target framerate
|
|
|
|
static double lastframetime = 0;
|
|
|
|
int refresh = GetRefresh();
|
|
|
|
double newframetime = GetTimeInMilliSeconds();
|
|
|
|
float multiplier = (float) ((1000.0 / refresh) / (newframetime - lastframetime));
|
|
|
|
lastframetime = newframetime;
|
|
|
|
|
|
|
|
vec2_t v;
|
|
|
|
float factor = (refresh / 72.0F) *
|
|
|
|
vr_positional_factor->value; // adjust positional factor based on refresh rate
|
|
|
|
rotateAboutOrigin(-vr.hmdposition_delta[0] * factor * multiplier,
|
|
|
|
vr.hmdposition_delta[2] * factor * multiplier,
|
|
|
|
-vr.hmdorientation[YAW], v);
|
|
|
|
positional_movementSideways = v[0];
|
|
|
|
positional_movementForward = v[1];
|
|
|
|
|
|
|
|
ALOGV(" positional_movementSideways: %f, positional_movementForward: %f",
|
|
|
|
positional_movementSideways,
|
|
|
|
positional_movementForward);
|
|
|
|
|
|
|
|
|
|
|
|
//Jump (A Button)
|
|
|
|
if ((primaryButtonsNew & primaryButton1) != (primaryButtonsOld & primaryButton1)) {
|
|
|
|
sendButtonAction("+moveup", (primaryButtonsNew & primaryButton1));
|
|
|
|
}
|
2022-09-29 22:38:22 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//Alt Fire (B Button)
|
|
|
|
if ((primaryButtonsNew & primaryButton2) != (primaryButtonsOld & primaryButton2)) {
|
|
|
|
sendButtonAction("+altattack", (primaryButtonsNew & primaryButton2));
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
static bool firing = false;
|
2022-09-27 22:19:12 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
{
|
|
|
|
//Fire Primary - Doesn't trigger the saber
|
|
|
|
if (!vr.velocitytriggered && // Don't fire velocity triggered weapons
|
|
|
|
(pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) !=
|
|
|
|
(pDominantTrackedRemoteOld->Buttons & ovrButton_Trigger)) {
|
|
|
|
|
|
|
|
ALOGV("**WEAPON EVENT** Not Grip Pushed %sattack",
|
|
|
|
(pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) ? "+" : "-");
|
|
|
|
firing = (pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger);
|
|
|
|
sendButtonAction("+attack", firing);
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 19:18:23 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//Duck - off hand joystick
|
|
|
|
if ((secondaryButtonsNew & secondaryThumb) !=
|
|
|
|
(secondaryButtonsOld & secondaryThumb)) {
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
sendButtonAction("+movedown", (secondaryButtonsNew & secondaryThumb));
|
|
|
|
}
|
2022-09-28 22:07:22 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//Use
|
|
|
|
if ((pDominantTrackedRemoteNew->Buttons & primaryThumb) !=
|
|
|
|
(pDominantTrackedRemoteOld->Buttons & primaryThumb)) {
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
sendButtonAction("+use", (pDominantTrackedRemoteNew->Buttons & primaryThumb));
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
{
|
|
|
|
//Apply a filter and quadratic scaler so small movements are easier to make
|
|
|
|
float dist = length(pSecondaryJoystick->x, pSecondaryJoystick->y);
|
|
|
|
float nlf = nonLinearFilter(dist);
|
|
|
|
float x = (nlf * pSecondaryJoystick->x) + pFootTrackingNew->LeftJoystick.x;
|
|
|
|
float y = (nlf * pSecondaryJoystick->y) - pFootTrackingNew->LeftJoystick.y;
|
|
|
|
|
|
|
|
vr.player_moving = (fabs(x) + fabs(y)) > 0.05f;
|
|
|
|
|
|
|
|
//Adjust to be off-hand controller oriented
|
|
|
|
vec2_t v;
|
|
|
|
rotateAboutOrigin(x, y, controllerYawHeading, v);
|
|
|
|
|
|
|
|
//Move a lot slower if scope is engaged
|
|
|
|
remote_movementSideways =
|
|
|
|
v[0] * (vr.scopeengaged ? 0.3f : 1.0f) * vr_movement_multiplier->value;
|
|
|
|
remote_movementForward =
|
|
|
|
v[1] * (vr.scopeengaged ? 0.3f : 1.0f) * vr_movement_multiplier->value;
|
|
|
|
ALOGV(" remote_movementSideways: %f, remote_movementForward: %f",
|
|
|
|
remote_movementSideways,
|
|
|
|
remote_movementForward);
|
|
|
|
|
|
|
|
|
|
|
|
if (!canUseQuickSave) {
|
|
|
|
if ((secondaryButtonsNew & secondaryButton1) !=
|
|
|
|
(secondaryButtonsOld & secondaryButton1)) {
|
|
|
|
//Toggle walk/run somehow?!
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//Open the datapad
|
|
|
|
if (!canUseQuickSave) {
|
|
|
|
if (((secondaryButtonsNew & secondaryButton2) !=
|
|
|
|
(secondaryButtonsOld & secondaryButton2)) &&
|
|
|
|
(secondaryButtonsNew & secondaryButton2)) {
|
|
|
|
Sys_QueEvent(0, SE_KEY, A_TAB, true, 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//Use Force - off hand trigger
|
|
|
|
{
|
|
|
|
if ((pOffTrackedRemoteNew->Buttons & ovrButton_Trigger) !=
|
|
|
|
(pOffTrackedRemoteOld->Buttons & ovrButton_Trigger)) {
|
|
|
|
sendButtonAction("+useforce", (pOffTrackedRemoteNew->Buttons & ovrButton_Trigger));
|
|
|
|
}
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//Resync Yaw on mounted gun transition
|
|
|
|
static int usingMountedGun = false;
|
|
|
|
if (vr.mountedgun != usingMountedGun) {
|
|
|
|
usingMountedGun = vr.mountedgun;
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//No snap turn when using mounted gun
|
|
|
|
static int syncCount = 0;
|
|
|
|
static int increaseSnap = true;
|
|
|
|
if (!vr.item_selector && !vr.mountedgun && !vr.scopeengaged) {
|
|
|
|
if (primaryJoystickX > 0.7f) {
|
|
|
|
if (increaseSnap) {
|
|
|
|
float turnAngle = vr_turn_mode->integer ? (vr_turn_angle->value / 9.0f)
|
|
|
|
: vr_turn_angle->value;
|
|
|
|
vr.snapTurn -= turnAngle;
|
|
|
|
|
|
|
|
if (vr_turn_mode->integer == 0) {
|
|
|
|
increaseSnap = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vr.snapTurn < -180.0f) {
|
|
|
|
vr.snapTurn += 360.f;
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
2022-10-12 17:00:26 +00:00
|
|
|
} else if (primaryJoystickX < 0.3f) {
|
|
|
|
increaseSnap = true;
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
static int decreaseSnap = true;
|
|
|
|
if (primaryJoystickX < -0.7f) {
|
|
|
|
if (decreaseSnap) {
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
float turnAngle = vr_turn_mode->integer ? (vr_turn_angle->value / 9.0f)
|
|
|
|
: vr_turn_angle->value;
|
|
|
|
vr.snapTurn += turnAngle;
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
//If snap turn configured for less than 10 degrees
|
|
|
|
if (vr_turn_mode->integer == 0) {
|
|
|
|
decreaseSnap = false;
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
if (vr.snapTurn > 180.0f) {
|
|
|
|
vr.snapTurn -= 360.f;
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
2022-10-12 17:00:26 +00:00
|
|
|
} else if (primaryJoystickX > -0.3f) {
|
|
|
|
decreaseSnap = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fabs(primaryJoystickX) > 0.5f) {
|
|
|
|
increaseSnap = false;
|
|
|
|
} else {
|
|
|
|
increaseSnap = true;
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:00:26 +00:00
|
|
|
updateScopeAngles();
|
|
|
|
}
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Save state
|
|
|
|
rightTrackedRemoteState_old = rightTrackedRemoteState_new;
|
|
|
|
leftTrackedRemoteState_old = leftTrackedRemoteState_new;
|
|
|
|
}
|