Start of 6DoF weapons..

Not there yet, but good progress!
This commit is contained in:
Simon 2020-07-05 23:24:18 +01:00
parent f92f75e136
commit 062682addd
9 changed files with 109 additions and 36 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="1"
android:versionName="0.1.0" android:installLocation="auto" >
android:versionCode="2"
android:versionName="0.2.0" android:installLocation="auto" >
<!-- Tell the system this app requires OpenGL ES 3.1. -->
<uses-feature android:glEsVersion="0x00030001" android:required="true"/>

View file

@ -13,6 +13,7 @@ typedef struct {
vec3_t hmdorientation_last; // Don't use this, it is just for calculating delta!
vec3_t hmdorientation_delta;
vec3_t weaponangles_unadjusted;
vec3_t weaponangles;
vec3_t weaponangles_last; // Don't use this, it is just for calculating delta!
vec3_t weaponangles_delta;

View file

@ -54,7 +54,7 @@ qboolean between(float min, float val, float max);
void rotateAboutOrigin(float v1, float v2, float rotation, vec2_t out);
void QuatToYawPitchRoll(ovrQuatf q, vec3_t rotation, vec3_t out);
void handleTrackedControllerButton(ovrInputStateTrackedRemote * trackedRemoteState, ovrInputStateTrackedRemote * prevTrackedRemoteState, uint32_t button, int key);
void interactWithTouchScreen(ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemote *oldState);
void interactWithTouchScreen(qboolean reset, ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemote *oldState);
//Called from engine code

View file

@ -143,21 +143,26 @@ void acquireTrackedRemotesData(const ovrMobile *Ovr, double displayTime) {//The
}
}
float initialTouchX, initialTouchY;
void PortableMouseAbs(float x,float y);
inline float clamp(float _min, float _val, float _max)
{
return max(min(_val, _max), _min);
}
void interactWithTouchScreen(ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemote *oldState) {
void interactWithTouchScreen(qboolean reset, ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemote *oldState) {
static float cursorX = 0.25f;
static float cursorY = 0.125f;
cursorX += (float)(vr.weaponangles_delta[YAW] / 220.0);
if (reset)
{
cursorX = 0.25f;
cursorY = 0.125f;
}
cursorX += (float)(vr.weaponangles_delta[YAW] / 180.0);
cursorX = clamp(0.0, cursorX, 0.5);
cursorY += (float)(-vr.weaponangles_delta[PITCH] / 220.0);
cursorY = clamp(0.0, cursorY, 0.5);
cursorY = clamp(0.0, cursorY, 0.4);
PortableMouseAbs(cursorX, cursorY);
}

View file

@ -49,9 +49,9 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
{
//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};
QuatToYawPitchRoll(pDominantTracking->HeadPose.Pose.Orientation, rotation, vr.weaponangles_unadjusted);
rotation[PITCH] = vr_weapon_pitchadjust->value;
QuatToYawPitchRoll(pDominantTracking->HeadPose.Pose.Orientation, rotation, vr.weaponangles);
vr.weaponangles[ROLL] *= -1.0f;
VectorSubtract(vr.weaponangles_last, vr.weaponangles, vr.weaponangles_delta);
VectorCopy(vr.weaponangles, vr.weaponangles_last);
@ -65,9 +65,11 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
//Menu button
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, ovrButton_Enter, K_ESCAPE);
static qboolean resetCursor = qtrue;
if ( RTCWVR_useScreenLayer() )
{
interactWithTouchScreen(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld);
interactWithTouchScreen(resetCursor, pDominantTrackedRemoteNew, pDominantTrackedRemoteOld);
resetCursor = qfalse;
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, K_MOUSE1);
handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, ovrButton_Trigger, K_MOUSE1);
@ -75,6 +77,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
}
else
{
resetCursor = qtrue;
static bool canUseQuickSave = false;
if (pOffTracking->Status & (VRAPI_TRACKING_STATUS_POSITION_TRACKED | VRAPI_TRACKING_STATUS_POSITION_VALID)) {
@ -133,7 +136,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
{
vec2_t v;
rotateAboutOrigin(-vr.weaponoffset[0], vr.weaponoffset[2], (cl.viewangles[YAW] - vr.hmdorientation[YAW]), v);
rotateAboutOrigin(vr.weaponoffset[0], vr.weaponoffset[2], -snapTurn, v);
vr.weaponoffset[0] = v[0];
vr.weaponoffset[2] = v[1];
}
@ -146,7 +149,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
float zxDist = length(x, z);
if (zxDist != 0.0f && z != 0.0f) {
VectorSet(vr.weaponangles, -degrees(atanf(y / zxDist)), (cl.viewangles[YAW] - vr.hmdorientation[YAW]) - degrees(atan2f(x, -z)), vr.weaponangles[ROLL]);
VectorSet(vr.weaponangles, -degrees(atanf(y / zxDist)), -snapTurn - degrees(atan2f(x, -z)), vr.weaponangles[ROLL]);
}
}

View file

@ -1704,6 +1704,7 @@ extern vmCvar_t cg_thirdPersonAngle;
extern vmCvar_t cg_thirdPerson;
extern vmCvar_t cg_stereoSeparation;
extern vmCvar_t cg_worldScale;
extern vmCvar_t cg_weaponScale;
extern vmCvar_t cg_lagometer;
extern vmCvar_t cg_drawAttacker;
extern vmCvar_t cg_synchronousClients;

View file

@ -191,6 +191,7 @@ vmCvar_t cg_thirdPersonRange;
vmCvar_t cg_thirdPersonAngle;
vmCvar_t cg_stereoSeparation;
vmCvar_t cg_worldScale;
vmCvar_t cg_weaponScale;
vmCvar_t cg_lagometer;
vmCvar_t cg_drawAttacker;
vmCvar_t cg_synchronousClients;
@ -312,6 +313,7 @@ cvarTable_t cvarTable[] = {
{ &cg_letterbox, "cg_letterbox", "0", CVAR_TEMP }, //----(SA) added
{ &cg_stereoSeparation, "cg_stereoSeparation", "0.065", CVAR_ARCHIVE },
{ &cg_worldScale, "cg_worldScale", "35.0", CVAR_ARCHIVE },
{ &cg_weaponScale, "cg_weaponScale", "0.5", CVAR_ARCHIVE },
{ &cg_shadows, "cg_shadows", "1", CVAR_ARCHIVE },
{ &cg_gibs, "cg_gibs", "1", CVAR_ARCHIVE },
{ &cg_draw2D, "cg_draw2D", "1", CVAR_ARCHIVE },

View file

@ -1759,7 +1759,7 @@ static void CG_WeaponAnimation( playerState_t *ps, weaponInfo_t *weapon, int *we
void convertFromVR(vec3_t in, vec3_t offset, vec3_t out)
{
vec3_t vrSpace;
VectorSet(vrSpace, in[0], in[1], in[2]);
VectorSet(vrSpace, in[2], in[0], in[1] );
vec3_t temp;
VectorScale(vrSpace, cg_worldScale.value, temp);
@ -1780,9 +1780,18 @@ CG_CalculateWeaponPosition
static void CG_CalculateWeaponPosition( vec3_t origin, vec3_t angles ) {
convertFromVR(cgVR->weaponoffset, cg.refdef.vieworg, origin);
VectorCopy(cgVR->weaponangles, angles);
origin[2] -= 64;
origin[2] += (cgVR->hmdposition[1] /*+ vr_height_adjust->value*/) * cg_worldScale.value;
angles[YAW] = cg.refdefViewAngles[YAW] + (cgVR->hmdorientation[YAW] - cgVR->weaponangles[YAW]);
VectorCopy(cgVR->weaponangles, angles);
angles[YAW] = cg.refdefViewAngles[YAW] + (cgVR->weaponangles[YAW] - cgVR->hmdorientation[YAW]);
//Now move weapon closer to proper origin
vec3_t forward, right, up;
AngleVectors( angles, forward, right, up );
VectorMA( origin, -16, forward, origin );
VectorMA( origin, 9, up, origin );
VectorMA( origin, -4.5, right, origin );
return;
float scale;
@ -2661,7 +2670,6 @@ void CG_AddPlayerWeapon( refEntity_t *parent, playerState_t *ps, centity_t *cent
// this will affect any parts attached to the gun as well (barrel/bolt/flash/brass/etc.)
VectorScale( gun.axis[i], 1.0 / ( cgs.clientinfo[ cent->currentState.clientNum ].playermodelScale[i] ), gun.axis[i] );
}
}
// characters that draw their own special weapon model will not draw the standard ones
@ -6066,9 +6074,13 @@ static qboolean CG_CalcMuzzlePoint( int entityNum, vec3_t muzzle ) {
int anim;
if ( entityNum == cg.snap->ps.clientNum ) {
VectorCopy( cg.snap->ps.origin, muzzle );
convertFromVR(cgVR->weaponoffset, cg.snap->ps.origin, muzzle);
muzzle[2] += cg.snap->ps.viewheight;
AngleVectors( cg.snap->ps.viewangles, forward, NULL, NULL );
vec3_t angles;
VectorCopy(cgVR->weaponangles, angles);
angles[YAW] = cg.refdefViewAngles[YAW] + (cgVR->weaponangles[YAW] - cgVR->hmdorientation[YAW]);
AngleVectors( angles, forward, NULL, NULL );
VectorMA( muzzle, 14, forward, muzzle );
return qtrue;
}

View file

@ -35,12 +35,14 @@ If you have questions concerning this license or the applicable additional terms
#include "g_local.h"
#include "../../../RTCWVR/VrClientInfo.h"
static float s_quadFactor;
static vec3_t forward, right, up;
static vec3_t muzzleEffect;
static vec3_t muzzleTrace;
extern vr_client_info_t* gVR;
// forward dec
void weapon_zombiespit( gentity_t *ent );
@ -52,6 +54,24 @@ int G_GetWeaponDamage( int weapon ); // JPW
#define NUM_NAILSHOTS 10
void convertFromVR(float worldscale, vec3_t in, vec3_t offset, vec3_t out)
{
vec3_t vrSpace;
VectorSet(vrSpace, in[2], in[0], in[1]);
vec3_t temp;
VectorScale(vrSpace, worldscale, temp);
if (offset) {
VectorAdd(temp, offset, out);
} else {
VectorCopy(temp, out);
}
}
/*
======================================================================
@ -77,8 +97,14 @@ void Weapon_Knife( gentity_t *ent ) {
mod = MOD_KNIFE;
AngleVectors( ent->client->ps.viewangles, forward, right, up );
vec3_t angles;
VectorCopy(gVR->weaponangles_unadjusted, angles);
angles[YAW] = ent->client->ps.viewangles[YAW] + (gVR->weaponangles[YAW] - gVR->hmdorientation[YAW]);
AngleVectors( angles, forward, right, up );
CalcMuzzlePoint( ent, ent->s.weapon, forward, right, up, muzzleTrace );
VectorMA( muzzleTrace, KNIFE_DIST, forward, end );
trap_Trace( &tr, muzzleTrace, NULL, NULL, end, ent->s.number, MASK_SHOT );
@ -1634,8 +1660,20 @@ set muzzle location relative to pivoting eye
===============
*/
void CalcMuzzlePoint( gentity_t *ent, int weapon, vec3_t forward, vec3_t right, vec3_t up, vec3_t muzzlePoint ) {
VectorCopy( ent->r.currentOrigin, muzzlePoint );
muzzlePoint[2] += ent->client->ps.viewheight;
if ( ( ent->r.svFlags & SVF_CASTAI ) )
{
VectorCopy(ent->r.currentOrigin, muzzlePoint);
muzzlePoint[2] += ent->client->ps.viewheight;
}
else
{
float worldscale = trap_Cvar_VariableIntegerValue("cg_worldScale");
convertFromVR(worldscale, gVR->weaponoffset, ent->r.currentOrigin, muzzlePoint);
muzzlePoint[2] += ent->client->ps.viewheight;
return;
}
// Ridah, this puts the start point outside the bounding box, isn't necessary
// VectorMA( muzzlePoint, 14, forward, muzzlePoint );
// done.
@ -1671,35 +1709,41 @@ void CalcMuzzlePoint( gentity_t *ent, int weapon, vec3_t forward, vec3_t right,
// (SA) actually, this is sort of moot right now since
// you're not allowed to fire when leaning. Leave in
// in case we decide to enable some lean-firing.
AddLean( ent, muzzlePoint );
//AddLean( ent, muzzlePoint );
// snap to integer coordinates for more efficient network bandwidth usage
SnapVector( muzzlePoint );
//SnapVector( muzzlePoint );
}
// Rafael - for activate
void CalcMuzzlePointForActivate( gentity_t *ent, vec3_t forward, vec3_t right, vec3_t up, vec3_t muzzlePoint ) {
VectorCopy( ent->s.pos.trBase, muzzlePoint );
muzzlePoint[2] += ent->client->ps.viewheight;
AddLean( ent, muzzlePoint );
// snap to integer coordinates for more efficient network bandwidth usage
// SnapVector( muzzlePoint );
// (SA) /\ only used server-side, so leaving the accuracy in is fine (and means things that show a cursorhint will be hit when activated)
// (there were differing views of activatable stuff between cursorhint and activatable)
if ( ( ent->r.svFlags & SVF_CASTAI ) )
{
VectorCopy(ent->r.currentOrigin, muzzlePoint);
muzzlePoint[2] += ent->client->ps.viewheight;
AddLean( ent, muzzlePoint );
}
else
{
float worldscale = trap_Cvar_VariableIntegerValue("cg_worldScale");
convertFromVR(worldscale, gVR->weaponoffset, ent->r.currentOrigin, muzzlePoint);
muzzlePoint[2] += ent->client->ps.viewheight;
return;
}
}
// done.
// Ridah
void CalcMuzzlePoints( gentity_t *ent, int weapon ) {
vec3_t viewang;
VectorCopy( ent->client->ps.viewangles, viewang );
if ( !( ent->r.svFlags & SVF_CASTAI ) ) {
if ( !( ent->r.svFlags & SVF_CASTAI ) ) { // non ai's take into account scoped weapon 'sway' (just another way aimspread is visualized/utilized)
float spreadfrac, phase;
/*
// non ai's take into account scoped weapon 'sway' (just another way aimspread is visualized/utilized)
float spreadfrac, phase;
if ( weapon == WP_SNIPERRIFLE || weapon == WP_SNOOPERSCOPE || weapon == WP_FG42SCOPE ) {
spreadfrac = ent->client->currentAimSpreadScale;
@ -1710,9 +1754,14 @@ void CalcMuzzlePoints( gentity_t *ent, int weapon ) {
phase = level.time / 1000.0 * ZOOM_YAW_FREQUENCY * M_PI * 2;
viewang[YAW] += ZOOM_YAW_AMPLITUDE * sin( phase ) * ( spreadfrac + ZOOM_YAW_MIN_AMPLITUDE );
}
}
*/
VectorCopy(gVR->weaponangles, viewang);
viewang[YAW] = ent->client->ps.viewangles[YAW] + (gVR->weaponangles[YAW] - gVR->hmdorientation[YAW]);
} else {
VectorCopy( ent->client->ps.viewangles, viewang );
}
// set aiming directions
AngleVectors( viewang, forward, right, up );