Weapon Alignment Mode

set control options to 99
This commit is contained in:
Simon 2020-07-13 23:58:12 +01:00
parent 20ea9c6817
commit f019166c08
12 changed files with 334 additions and 39 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.drbeef.rtcwquest"
android:versionCode="9"
android:versionName="0.9.0" android:installLocation="auto" >
android:versionCode="10"
android:versionName="0.10.0" android:installLocation="auto" >
<!-- Tell the system this app requires OpenGL ES 3.1. -->
<uses-feature android:glEsVersion="0x00030001" android:required="true"/>

View file

@ -105,7 +105,7 @@ extern cvar_t *cl_paused;
enum control_scheme {
RIGHT_HANDED_DEFAULT = 0,
LEFT_HANDED_DEFAULT = 10,
GAMEPAD = 20 //Not implemented, someone else can do this!
WEAPON_ALIGN = 99
};
/*
@ -1306,11 +1306,14 @@ void RTCWVR_Init()
vr_positional_factor = Cvar_Get( "vr_positional_factor", "12", CVAR_ARCHIVE);
vr_walkdirection = Cvar_Get( "vr_walkdirection", "0", CVAR_ARCHIVE);
vr_weapon_pitchadjust = Cvar_Get( "vr_weapon_pitchadjust", "-20.0", CVAR_ARCHIVE);
vr_control_scheme = Cvar_Get( "vr_control_scheme", "0", CVAR_ARCHIVE);
vr_height_adjust = Cvar_Get( "vr_height_adjust", "0.0", CVAR_ARCHIVE);
vr_weaponscale = Cvar_Get( "vr_weaponscale", "0.56", CVAR_ARCHIVE);
vr_lasersight = Cvar_Get( "vr_lasersight", "0", CVAR_LATCH);
vr_comfort_mask = Cvar_Get( "vr_comfort_mask", "0.0", CVAR_ARCHIVE);
//Defaults
vr_control_scheme = Cvar_Get( "vr_control_scheme", "0", CVAR_ARCHIVE);
vr_weapon_test_values = Cvar_Get( "vr_weapon_test_values", "0.0,0.0,0.0,0.0,0.0,0.0,0.0", CVAR_ARCHIVE);
}
@ -1621,6 +1624,11 @@ void RTCWVR_getTrackedRemotesOrientation() {//Get info for tracked remotes
&rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new,
ovrButton_X, ovrButton_Y, ovrButton_A, ovrButton_B);
break;
case WEAPON_ALIGN:
HandleInput_WeaponAlign(&rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new,
&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, &leftRemoteTracking_new,
ovrButton_A, ovrButton_B, ovrButton_X, ovrButton_Y);
break;
}
}

View file

@ -32,10 +32,19 @@ typedef struct {
qboolean velocitytriggered; // Weapon attack triggered by velocity (knife)
vec3_t offhandangles;
vec3_t offhandoffset;
//////////////////////////////////////
// Test stuff for weapon alignment
//////////////////////////////////////
char test_name[256];
float test_scale;
vec3_t test_angles;
vec3_t test_offset;
} vr_client_info_t;
#endif //vr_client_info_h

View file

@ -8,3 +8,4 @@ cvar_t *vr_control_scheme;
cvar_t *vr_height_adjust;
cvar_t *vr_weaponscale;
cvar_t *vr_comfort_mask;
cvar_t *vr_weapon_test_values;

View file

@ -36,6 +36,12 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking,
int domButton1, int domButton2, int offButton1, int offButton2 );
void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking,
int domButton1, int domButton2, int offButton1, int offButton2 );
void updateScopeAngles();
#endif //vrinput_h

View file

@ -0,0 +1,223 @@
/************************************************************************************
Filename : VrInputWeaponAlign.c
Content : Handles default controller input
Created : August 2019
Authors : Simon Brown
*************************************************************************************/
#include <VrApi.h>
#include <VrApi_Helpers.h>
#include <VrApi_SystemUtils.h>
#include <VrApi_Input.h>
#include <VrApi_Types.h>
#include <android/keycodes.h>
#include "VrInput.h"
#include "VrCvars.h"
#include "../rtcw/src/client/client.h"
cvar_t *sv_cheats;
void CG_CenterPrint( const char *str, int y, int charWidth );
void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking,
int domButton1, int domButton2, int offButton1, int offButton2 )
{
//always right handed for this
vr.right_handed = qtrue;
//Get the cvar
sv_cheats = Cvar_Get("cheats", "1", CVAR_ARCHIVE);
static qboolean dominantGripPushed = false;
static float dominantGripPushTime = 0.0f;
//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};
rotation[PITCH] = 10;
QuatToYawPitchRoll(pDominantTracking->HeadPose.Pose.Orientation, rotation, vr.weaponangles_knife);
rotation[PITCH] = vr_weapon_pitchadjust->value;
QuatToYawPitchRoll(pDominantTracking->HeadPose.Pose.Orientation, rotation, vr.weaponangles);
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
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, ovrButton_Enter, K_ESCAPE);
static qboolean resetCursor = qtrue;
if ( RTCWVR_useScreenLayer() )
{
interactWithTouchScreen(resetCursor, pDominantTrackedRemoteNew, pDominantTrackedRemoteOld);
resetCursor = qfalse;
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, K_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, ovrButton_Trigger, K_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, K_ESCAPE);
}
else
{
resetCursor = qtrue;
//dominant hand stuff first
{
///Weapon location relative to view
vr.weaponoffset[0] = pDominantTracking->HeadPose.Pose.Position.x - vr.hmdposition[0];
vr.weaponoffset[1] = pDominantTracking->HeadPose.Pose.Position.y - vr.hmdposition[1];
vr.weaponoffset[2] = pDominantTracking->HeadPose.Pose.Position.z - vr.hmdposition[2];
vr.weaponoffset_timestamp = Sys_Milliseconds( );
}
float controllerYawHeading = 0.0f;
//off-hand stuff
{
vr.offhandoffset[0] = pOffTracking->HeadPose.Pose.Position.x - vr.hmdposition[0];
vr.offhandoffset[1] = pOffTracking->HeadPose.Pose.Position.y - vr.hmdposition[1];
vr.offhandoffset[2] = pOffTracking->HeadPose.Pose.Position.z - vr.hmdposition[2];
vec3_t rotation = {0};
QuatToYawPitchRoll(pOffTracking->HeadPose.Pose.Orientation, rotation, vr.offhandangles);
}
ALOGV(" Right-Controller-Position: %f, %f, %f",
pDominantTracking->HeadPose.Pose.Position.x,
pDominantTracking->HeadPose.Pose.Position.y,
pDominantTracking->HeadPose.Pose.Position.z);
//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);
//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
static bool firingPrimary = false;
if (!firingPrimary && dominantGripPushed && (GetTimeInMilliSeconds() - dominantGripPushTime) > vr_reloadtimeoutms->integer && !vr.scopedweapon)
{
//Fire Secondary
if (((pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) !=
(pDominantTrackedRemoteOld->Buttons & ovrButton_Trigger))
&& (pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger))
{
sendButtonActionSimple("weapalt");
}
}
else
{
//Fire Primary
if (!vr.velocitytriggered && // Don't fire velocity triggered weapons
(pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) !=
(pDominantTrackedRemoteOld->Buttons & ovrButton_Trigger)) {
firingPrimary = (pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger);
sendButtonAction("+attack", firingPrimary);
}
}
//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.2, 0.2, 0.2};
//Weapon/Inventory Chooser
static qboolean itemSwitched = false;
if (between(-0.2f, pDominantTrackedRemoteNew->Joystick.y, 0.2f) &&
(between(0.8f, pDominantTrackedRemoteNew->Joystick.x, 1.0f) ||
between(-1.0f, pDominantTrackedRemoteNew->Joystick.x, -0.8f)))
{
if (!itemSwitched) {
if (between(0.8f, pDominantTrackedRemoteNew->Joystick.x, 1.0f))
{
item_index = (item_index+1)%7;
}
else
{
item_index--;
if (item_index < 0)
item_index = 6;
}
itemSwitched = true;
}
} else {
itemSwitched = false;
}
if (((pDominantTrackedRemoteNew->Buttons & ovrButton_Joystick) !=
(pDominantTrackedRemoteOld->Buttons & ovrButton_Joystick)) &&
(pDominantTrackedRemoteOld->Buttons & ovrButton_Joystick))
{
*(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");
}
if (pDominantTrackedRemoteNew->Joystick.y > 0.5f)
{
*(items[item_index]) += item_inc[item_index];
}
if (pDominantTrackedRemoteNew->Joystick.y < -0.5f)
{
*(items[item_index]) -= item_inc[item_index];
}
}
sprintf(vr.test_name, "%s: %.2f", item_names[item_index], *(items[item_index]));
char buffer[256];
sprintf(buffer, "%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f", 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("vr_weapon_test_values", buffer );
}
//Save state
rightTrackedRemoteState_old = rightTrackedRemoteState_new;
leftTrackedRemoteState_old = leftTrackedRemoteState_new;
}

View file

@ -200,6 +200,7 @@ SERVER_FILES = \
RTCWVR_SRC_FILES := ../RTCWVR/RTCWVR_SurfaceView.c \
../RTCWVR/VrCompositor.c \
../RTCWVR/VrInputCommon.c \
../RTCWVR/VrInputWeaponAlign.c \
../RTCWVR/VrInputDefault.c \
../RTCWVR/mathlib.c \
../RTCWVR/matrixlib.c \

View file

@ -1994,37 +1994,64 @@ CG_CalculateWeaponPositionAndScale
*/
static float CG_CalculateWeaponPositionAndScale( vec3_t origin, vec3_t angles ) {
static float CG_CalculateWeaponPositionAndScale( playerState_t *ps, vec3_t origin, vec3_t angles ) {
CG_CalculateVRWeaponPosition(origin, angles);
//Now adjust weapon: scale, right, up, forward
vec3_t offset;
float scale=1.0f;
if (cg.predictedPlayerState.weapon != 0)
{
char cvar_name[64];
Com_sprintf(cvar_name, sizeof(cvar_name), "vr_weapon_adjustment_%i", cg.predictedPlayerState.weapon);
char weapon_adjustment[256];
trap_Cvar_VariableStringBuffer(cvar_name, weapon_adjustment, 256);
char buffer[32];
trap_Cvar_VariableStringBuffer("vr_control_scheme", buffer, 32);
vec3_t adjust;
vec3_t temp_offset;
VectorClear(temp_offset);
sscanf(weapon_adjustment, "%f,%f,%f,%f,%f,%f,%f", &scale, &(temp_offset[0]), &(temp_offset[1]), &(temp_offset[2]), &(adjust[PITCH]), &(adjust[YAW]), &(adjust[ROLL]));
VectorScale(temp_offset, scale, offset);
//Weapon offset debugging
float scale=1.0f;
if (strcmp(buffer, "99") == 0) {
scale = cgVR->test_scale;
//Adjust angles for weapon models that aren't aligned very well
matrix4x4 m1, m2, m3;
vec3_t zero;
VectorClear(zero);
Matrix4x4_CreateFromEntity(m1, angles,zero, 1.0);
Matrix4x4_CreateFromEntity(m2, adjust,zero, 1.0);
Matrix4x4_CreateFromEntity(m1, angles, zero, 1.0);
Matrix4x4_CreateFromEntity(m2, cgVR->test_angles, zero, 1.0);
Matrix4x4_Concat(m3, m1, m2);
Matrix4x4_ConvertToEntity(m3, angles, zero);
VectorCopy(cgVR->test_offset, offset);
CG_CenterPrint( cgVR->test_name, SCREEN_HEIGHT * 0.45, SMALLCHAR_WIDTH );
} else {
//Now adjust weapon: scale, right, up, forward
if (ps->weapon != 0)
{
char cvar_name[64];
Com_sprintf(cvar_name, sizeof(cvar_name), "vr_weapon_adjustment_%i", ps->weapon);
char weapon_adjustment[256];
trap_Cvar_VariableStringBuffer(cvar_name, weapon_adjustment, 256);
if (strlen(weapon_adjustment) > 0) {
vec3_t adjust;
vec3_t temp_offset;
VectorClear(temp_offset);
sscanf(weapon_adjustment, "%f,%f,%f,%f,%f,%f,%f", &scale,
&(temp_offset[0]), &(temp_offset[1]), &(temp_offset[2]),
&(adjust[PITCH]), &(adjust[YAW]), &(adjust[ROLL]));
VectorScale(temp_offset, scale, offset);
//Adjust angles for weapon models that aren't aligned very well
matrix4x4 m1, m2, m3;
vec3_t zero;
VectorClear(zero);
Matrix4x4_CreateFromEntity(m1, angles, zero, 1.0);
Matrix4x4_CreateFromEntity(m2, adjust, zero, 1.0);
Matrix4x4_Concat(m3, m1, m2);
Matrix4x4_ConvertToEntity(m3, angles, zero);
}
}
}
//Now move weapon closer to proper origin
vec3_t forward, right, up;
AngleVectors( angles, forward, right, up );
@ -3338,6 +3365,9 @@ void CG_AddViewWeapon( playerState_t *ps ) {
return;
}
char buffer[32];
trap_Cvar_VariableStringBuffer("vr_control_scheme", buffer, 32);
qboolean weaponDebugging = (strcmp(buffer, "99") == 0);
/* // drop gun lower at higher fov
if ( cg_fov.integer > 90 ) {
@ -3376,7 +3406,7 @@ void CG_AddViewWeapon( playerState_t *ps ) {
memset( &hand, 0, sizeof( hand ) );
// set up gun position
float scale = CG_CalculateWeaponPositionAndScale( hand.origin, angles );
float scale = CG_CalculateWeaponPositionAndScale( ps, hand.origin, angles );
gunoff[0] = cg_gun_x.value;
gunoff[1] = cg_gun_y.value;
@ -3399,7 +3429,15 @@ void CG_AddViewWeapon( playerState_t *ps ) {
hand.hModel = weapon->handsModel;
hand.renderfx = RF_DEPTHHACK | RF_FIRST_PERSON | RF_MINLIGHT; //----(SA)
//Weapon offset debugging
if (weaponDebugging)
{
hand.renderfx = RF_FIRST_PERSON | RF_MINLIGHT; //No depth hack for weapon adjusting mode
}
else
{
hand.renderfx = RF_DEPTHHACK | RF_FIRST_PERSON | RF_MINLIGHT; //----(SA)
}
//scale the whole model (hand and weapon)
for ( int i = 0; i < 3; i++ ) {
@ -3446,20 +3484,29 @@ void CG_AddViewWeapon( playerState_t *ps ) {
VectorMA(beam_entity.currentState.pos.trBase, 64, forward, beam_entity.currentState.origin2); //beam end
//Weapon offset debugging
if (weaponDebugging)
{
vec3_t origin;
vec3_t origin2;
vec3_t endForward, endRight, endUp;
vec3_t angles;
CG_CalculateVRWeaponPosition(
origin,
angles );
vec3_t forward;
AngleVectors(angles, forward, NULL, NULL);
VectorMA(origin, 48, forward, origin2); //beam end
CG_RailTrail2(NULL, origin, origin2);
}
clientInfo_t ci;
CG_CalculateVRWeaponPosition( origin, angles );
//CG_Beam(&beam_entity);
vec3_t forward, right, up;
AngleVectors(angles, forward, right, up);
VectorMA(origin, 24, forward, endForward);
VectorSet(ci.color, 1, 0, 0); // Forward is red
CG_RailTrail2(&ci, origin, endForward);
VectorMA(origin, 24, right, endRight);
VectorSet(ci.color, 0, 1, 0); // right is green
CG_RailTrail2(&ci, origin, endRight);
VectorMA(origin, 24, up, endUp);
VectorSet(ci.color, 0, 0, 1); // up is blue
CG_RailTrail2(&ci, origin, endUp);
}
cg.predictedPlayerEntity.lastWeaponClientFrame = cg.clientFrame;
}

View file

@ -42,7 +42,7 @@ If you have questions concerning this license or the applicable additional terms
// q_shared.h -- included first by ALL program modules.
// A user mod should never modify this file
#define Q3_VERSION "RTCWQuest 0.9.0 (Wolf 1.41)"
#define Q3_VERSION "RTCWQuest 0.10.0 (Wolf 1.41)"
// ver 1.0.0 - release
// ver 1.0.1 - post-release work
// ver 1.1.0 - patch 1 (12/12/01)

View file

@ -1113,7 +1113,7 @@ void R_Register( void ) {
r_facePlaneCull = ri.Cvar_Get( "r_facePlaneCull", "1", CVAR_ARCHIVE );
r_railWidth = ri.Cvar_Get( "r_railWidth", "16", CVAR_ARCHIVE );
r_railCoreWidth = ri.Cvar_Get( "r_railCoreWidth", "1", CVAR_ARCHIVE );
r_railCoreWidth = ri.Cvar_Get( "r_railCoreWidth", "0.25", CVAR_ARCHIVE );
r_railSegmentLength = ri.Cvar_Get( "r_railSegmentLength", "32", CVAR_ARCHIVE );
r_waterFogColor = ri.Cvar_Get( "r_waterFogColor", "0", CVAR_ROM ); //----(SA) added

View file

@ -663,7 +663,7 @@ void RB_SurfaceRailCore( void ) {
CrossProduct( v1, v2, right );
VectorNormalize( right );
DoRailCore( start, end, right, len, r_railCoreWidth->integer );
DoRailCore( start, end, right, len, r_railCoreWidth->value );
}
/*

View file

@ -36,7 +36,7 @@
// Default values are: "0.62,-9.8,11.3,-16.1,0.0,0.0,0.0"
// Knife
seta vr_weapon_adjustment_1 "0.5,-9.8,8.0,-20.0,10.0,-10.0,-40.0"
seta vr_weapon_adjustment_1 "0.58,-5.36,9.07,-10.87,23.20,-10.00,-21.20"
// Luger
seta vr_weapon_adjustment_2 "0.5,-14,17.0,-20.1,0.0,0.0,0.0"
@ -66,7 +66,7 @@ seta vr_weapon_adjustment_7 "0.9,-9.0,8.0,-5.0,0.0,0.0,0.0"
seta vr_weapon_adjustment_9 "0.7,-13.8,5.9,-9.0,0.0,0.0,0.0"
// Tesla Coil
seta vr_weapon_adjustment_10 "0.72,-13.8,11.3,-12.1,0.0,0.0,0.0"
seta vr_weapon_adjustment_10 "0.615999,-4.939996,2.919998,1.159999,0.000000,0.000000,0.000000"
// Garand (snooper scope sniper rifle)
seta vr_weapon_adjustment_13 "0.59,-13.8,10.0,-12.0,0.0,0.0,0.0"