2022-09-18 15:37:21 +00:00
|
|
|
/************************************************************************************
|
|
|
|
|
|
|
|
Filename : VrInputWeaponAlign.c
|
|
|
|
Content : Handles default controller input
|
|
|
|
Created : August 2019
|
|
|
|
Authors : Simon Brown
|
|
|
|
|
|
|
|
*************************************************************************************/
|
|
|
|
|
|
|
|
#include <android/keycodes.h>
|
|
|
|
|
|
|
|
#include "VrInput.h"
|
|
|
|
#include "VrCvars.h"
|
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
#include "client/client.h"
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
cvar_t *sv_cheats;
|
|
|
|
|
|
|
|
void CG_CenterPrint( const char *str, int y, int charWidth );
|
|
|
|
|
2022-12-04 11:46:32 +00:00
|
|
|
void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTrackedController* pDominantTracking,
|
|
|
|
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTrackedController* pOffTracking,
|
2022-09-18 15:37:21 +00:00
|
|
|
int domButton1, int domButton2, int offButton1, int offButton2 )
|
|
|
|
|
|
|
|
{
|
|
|
|
//always right handed for this
|
|
|
|
vr.right_handed = true;
|
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
static bool dominantGripPushed = false;
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
char cvar_name[64];
|
2022-11-08 21:43:12 +00:00
|
|
|
Com_sprintf(cvar_name, sizeof(cvar_name), "vr_weapon_adjustment_%i", cl.frame.ps.weapon);
|
2022-09-18 15:37:21 +00:00
|
|
|
char weapon_adjustment[256];
|
|
|
|
Cvar_VariableStringBuffer(cvar_name, weapon_adjustment, 256);
|
|
|
|
sscanf(weapon_adjustment, "%f,%f,%f,%f,%f,%f,%f", &vr.test_scale,
|
|
|
|
&(vr.test_offset[0]), &(vr.test_offset[1]), &(vr.test_offset[2]),
|
|
|
|
&(vr.test_angles[PITCH]), &(vr.test_angles[YAW]), &(vr.test_angles[ROLL]));
|
|
|
|
VectorScale(vr.test_offset, vr.test_scale, vr.test_offset);
|
|
|
|
*/
|
|
|
|
|
|
|
|
//Need this for the touch screen
|
|
|
|
{
|
|
|
|
//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};
|
2023-02-02 22:53:34 +00:00
|
|
|
rotation[PITCH] = 45;
|
2022-12-04 11:46:32 +00:00
|
|
|
QuatToYawPitchRoll(pDominantTracking->Pose.orientation, rotation, vr.weaponangles_saber);
|
2023-02-02 22:53:34 +00:00
|
|
|
QuatToYawPitchRoll(pOffTracking->Pose.orientation, rotation, vr.offhandangles_saber);
|
2022-09-18 15:37:21 +00:00
|
|
|
rotation[PITCH] = vr_weapon_pitchadjust->value;
|
2022-12-04 11:46:32 +00:00
|
|
|
QuatToYawPitchRoll(pDominantTracking->Pose.orientation, rotation, vr.weaponangles);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
VectorSubtract(vr.weaponangles_last, vr.weaponangles, vr.weaponangles_delta);
|
|
|
|
VectorCopy(vr.weaponangles, vr.weaponangles_last);
|
|
|
|
|
|
|
|
ALOGV(" weaponangles_last: %f, %f, %f",
|
|
|
|
vr.weaponangles_last[0], vr.weaponangles_last[1], vr.weaponangles_last[2]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Menu button
|
2022-12-04 11:46:32 +00:00
|
|
|
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, xrButton_Enter, A_ESCAPE);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
static bool resetCursor = qtrue;
|
2022-12-19 21:23:28 +00:00
|
|
|
if (VR_UseScreenLayer() )
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
|
|
|
interactWithTouchScreen(resetCursor, pDominantTrackedRemoteNew, pDominantTrackedRemoteOld);
|
|
|
|
resetCursor = qfalse;
|
|
|
|
|
2022-09-19 21:46:47 +00:00
|
|
|
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, A_MOUSE1);
|
2022-12-04 11:46:32 +00:00
|
|
|
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, xrButton_Trigger, A_MOUSE1);
|
2022-09-19 21:46:47 +00:00
|
|
|
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, A_ESCAPE);
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resetCursor = qtrue;
|
|
|
|
|
|
|
|
//dominant hand stuff first
|
|
|
|
{
|
2022-12-04 11:46:32 +00:00
|
|
|
vr.weaponposition[0] = pDominantTracking->Pose.position.x;
|
|
|
|
vr.weaponposition[1] = pDominantTracking->Pose.position.y;
|
|
|
|
vr.weaponposition[2] = pDominantTracking->Pose.position.z;
|
2022-09-18 15:37:21 +00:00
|
|
|
///Weapon location relative to view
|
2022-12-04 11:46:32 +00:00
|
|
|
vr.weaponoffset[0] = pDominantTracking->Pose.position.x - vr.hmdposition[0];
|
|
|
|
vr.weaponoffset[1] = pDominantTracking->Pose.position.y - vr.hmdposition[1];
|
|
|
|
vr.weaponoffset[2] = pDominantTracking->Pose.position.z - vr.hmdposition[2];
|
2022-09-27 22:19:12 +00:00
|
|
|
vr.weaponoffset_timestamp = Sys_Milliseconds( );
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float controllerYawHeading = 0.0f;
|
|
|
|
//off-hand stuff
|
|
|
|
{
|
2022-12-04 11:46:32 +00:00
|
|
|
vr.offhandposition[0][0] = pOffTracking->Pose.position.x;
|
|
|
|
vr.offhandposition[0][1] = pOffTracking->Pose.position.y;
|
|
|
|
vr.offhandposition[0][2] = pOffTracking->Pose.position.z;
|
2022-09-27 22:19:12 +00:00
|
|
|
|
2022-12-04 11:46:32 +00:00
|
|
|
vr.offhandoffset[0] = pOffTracking->Pose.position.x - vr.hmdposition[0];
|
|
|
|
vr.offhandoffset[1] = pOffTracking->Pose.position.y - vr.hmdposition[1];
|
|
|
|
vr.offhandoffset[2] = pOffTracking->Pose.position.z - vr.hmdposition[2];
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
vec3_t rotation = {0};
|
2022-12-04 11:46:32 +00:00
|
|
|
QuatToYawPitchRoll(pOffTracking->Pose.orientation, rotation, vr.offhandangles);
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ALOGV(" Right-Controller-Position: %f, %f, %f",
|
2022-12-04 11:46:32 +00:00
|
|
|
pDominantTracking->Pose.position.x,
|
|
|
|
pDominantTracking->Pose.position.y,
|
|
|
|
pDominantTracking->Pose.position.z);
|
2022-09-18 15:37:21 +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
|
|
|
|
vec2_t v;
|
|
|
|
rotateAboutOrigin(-vr.hmdposition_delta[0] * vr_positional_factor->value,
|
|
|
|
vr.hmdposition_delta[2] * vr_positional_factor->value, - vr.hmdorientation[YAW], v);
|
|
|
|
positional_movementSideways = v[0];
|
|
|
|
positional_movementForward = v[1];
|
|
|
|
|
|
|
|
ALOGV(" positional_movementSideways: %f, positional_movementForward: %f",
|
|
|
|
positional_movementSideways,
|
|
|
|
positional_movementForward);
|
|
|
|
|
|
|
|
dominantGripPushed = (pDominantTrackedRemoteNew->Buttons &
|
2022-12-04 11:46:32 +00:00
|
|
|
xrButton_GripTrigger) != 0;
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
//We need to record if we have started firing primary so that releasing trigger will stop firing, if user has pushed grip
|
|
|
|
//in meantime, then it wouldn't stop the gun firing and it would get stuck
|
|
|
|
if (dominantGripPushed)
|
|
|
|
{
|
|
|
|
//Fire Secondary
|
2022-12-04 11:46:32 +00:00
|
|
|
if (((pDominantTrackedRemoteNew->Buttons & xrButton_Trigger) !=
|
|
|
|
(pDominantTrackedRemoteOld->Buttons & xrButton_Trigger))
|
|
|
|
&& (pDominantTrackedRemoteNew->Buttons & xrButton_Trigger))
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
|
|
|
sendButtonActionSimple("weapalt");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Fire Primary
|
|
|
|
if (!vr.velocitytriggered && // Don't fire velocity triggered weapons
|
2022-12-04 11:46:32 +00:00
|
|
|
(pDominantTrackedRemoteNew->Buttons & xrButton_Trigger) !=
|
|
|
|
(pDominantTrackedRemoteOld->Buttons & xrButton_Trigger)) {
|
2022-09-18 15:37:21 +00:00
|
|
|
|
2022-12-04 11:46:32 +00:00
|
|
|
sendButtonAction("+attack", (pDominantTrackedRemoteNew->Buttons & xrButton_Trigger));
|
2022-09-18 15:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-04 11:46:32 +00:00
|
|
|
bool offhandGripPushed = (pOffTrackedRemoteNew->Buttons & xrButton_GripTrigger);
|
|
|
|
if ( (offhandGripPushed != (pOffTrackedRemoteOld->Buttons & xrButton_GripTrigger)) &&
|
2022-09-30 23:02:49 +00:00
|
|
|
offhandGripPushed)
|
|
|
|
#ifndef DEBUG
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
Cvar_Set("vr_control_scheme", "0");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2022-09-18 15:37:21 +00:00
|
|
|
//Next Weapon with A
|
|
|
|
if (((pDominantTrackedRemoteNew->Buttons & domButton1) !=
|
|
|
|
(pDominantTrackedRemoteOld->Buttons & domButton1)) &&
|
|
|
|
(pDominantTrackedRemoteOld->Buttons & domButton1)){
|
|
|
|
sendButtonActionSimple("weapnext");
|
|
|
|
}
|
|
|
|
|
|
|
|
//Prev Weapon with B
|
|
|
|
if (((pDominantTrackedRemoteNew->Buttons & domButton2) !=
|
|
|
|
(pDominantTrackedRemoteOld->Buttons & domButton2)) &&
|
|
|
|
(pDominantTrackedRemoteOld->Buttons & domButton2)){
|
|
|
|
sendButtonActionSimple("weapprev");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int item_index = 0;
|
|
|
|
float* items[7] = {&vr.test_scale, &(vr.test_offset[0]), &(vr.test_offset[1]), &(vr.test_offset[2]),
|
|
|
|
&(vr.test_angles[PITCH]), &(vr.test_angles[YAW]), &(vr.test_angles[ROLL])};
|
|
|
|
char* item_names[7] = {"scale", "right", "up", "forward", "pitch", "yaw", "roll"};
|
|
|
|
float item_inc[7] = {0.002, 0.02, 0.02, 0.02, 0.1, 0.1, 0.1};
|
|
|
|
|
2022-09-30 23:02:49 +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] = pDominantTrackedRemoteNew->Joystick.x;
|
|
|
|
float sum = 0.0f;
|
|
|
|
for (int j = 0; j < JOYX_SAMPLE_COUNT; ++j)
|
|
|
|
sum += joyx[j];
|
|
|
|
float primaryJoystickX = sum / 4.0f;
|
|
|
|
|
|
|
|
|
2022-09-18 15:37:21 +00:00
|
|
|
//Weapon/Inventory Chooser
|
2022-09-19 21:46:47 +00:00
|
|
|
static bool itemSwitched = false;
|
2022-09-18 15:37:21 +00:00
|
|
|
if (between(-0.2f, pDominantTrackedRemoteNew->Joystick.y, 0.2f) &&
|
2022-09-30 23:02:49 +00:00
|
|
|
(between(0.8f, primaryJoystickX, 1.0f) ||
|
|
|
|
between(-1.0f, primaryJoystickX, -0.8f)))
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
|
|
|
if (!itemSwitched) {
|
2022-09-30 23:02:49 +00:00
|
|
|
if (between(0.8f, primaryJoystickX, 1.0f))
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
|
|
|
item_index++;
|
|
|
|
if (item_index == 7)
|
|
|
|
item_index = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item_index--;
|
|
|
|
if (item_index < 0)
|
|
|
|
item_index = 6;
|
|
|
|
}
|
|
|
|
itemSwitched = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
itemSwitched = false;
|
|
|
|
}
|
|
|
|
|
2022-12-04 11:46:32 +00:00
|
|
|
if (((pDominantTrackedRemoteNew->Buttons & xrButton_Joystick) !=
|
|
|
|
(pDominantTrackedRemoteOld->Buttons & xrButton_Joystick)) &&
|
|
|
|
(pDominantTrackedRemoteOld->Buttons & xrButton_Joystick))
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
|
|
|
*(items[item_index]) = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Left-hand specific stuff
|
|
|
|
{
|
|
|
|
if (((pOffTrackedRemoteNew->Buttons & offButton1) !=
|
|
|
|
(pOffTrackedRemoteOld->Buttons & offButton1)) &&
|
|
|
|
(pOffTrackedRemoteOld->Buttons & offButton1)){
|
|
|
|
//If cheats enabled, give all weapons/pickups to player
|
|
|
|
Cbuf_AddText("give all\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-30 23:02:49 +00:00
|
|
|
if (between(-0.2f, primaryJoystickX, 0.2f))
|
2022-09-18 15:37:21 +00:00
|
|
|
{
|
|
|
|
if (pDominantTrackedRemoteNew->Joystick.y > 0.6f) {
|
|
|
|
*(items[item_index]) += item_inc[item_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pDominantTrackedRemoteNew->Joystick.y < -0.6f) {
|
|
|
|
*(items[item_index]) -= item_inc[item_index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_sprintf(vr.test_name, sizeof(vr.test_name), "%s: %.3f", item_names[item_index], *(items[item_index]));
|
|
|
|
|
|
|
|
char cvar_name[64];
|
2022-11-08 21:43:12 +00:00
|
|
|
Com_sprintf(cvar_name, sizeof(cvar_name), "vr_weapon_adjustment_%i", cl.frame.ps.weapon);
|
2022-09-18 15:37:21 +00:00
|
|
|
|
|
|
|
char buffer[256];
|
|
|
|
Com_sprintf(buffer, sizeof(buffer), "%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f", vr.test_scale, (vr.test_offset[0] / vr.test_scale), (vr.test_offset[1] / vr.test_scale), (vr.test_offset[2] / vr.test_scale),
|
|
|
|
(vr.test_angles[PITCH]), (vr.test_angles[YAW]), (vr.test_angles[ROLL]));
|
|
|
|
Cvar_Set(cvar_name, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Save state
|
|
|
|
rightTrackedRemoteState_old = rightTrackedRemoteState_new;
|
|
|
|
leftTrackedRemoteState_old = leftTrackedRemoteState_new;
|
|
|
|
}
|