Trying to get guns to work..

..not much success so far
This commit is contained in:
Simon 2019-09-30 00:10:24 +01:00
parent 0c71e7b601
commit 0716496d65
8 changed files with 100 additions and 87 deletions

View file

@ -41,7 +41,7 @@ vec3_t positionDeltaThisFrame;
#define ADJUSTED 0
#define UNADJUSTED 1
#define MELEE 2
vec3_t weaponangles[3];
vec3_t weaponangles;
vec3_t weaponoffset;
vec3_t weaponvelocity;

View file

@ -115,9 +115,7 @@ void HandleInput_Left( ovrMobile * Ovr, double displayTime )
//Set gun angles
const ovrQuatf quatRemote = leftRemoteTracking_new.HeadPose.Pose.Orientation;
QuatToYawPitchRoll(quatRemote, vr_weapon_pitchadjust->value, weaponangles[ADJUSTED]);
QuatToYawPitchRoll(quatRemote, 0.0f, weaponangles[UNADJUSTED]);
QuatToYawPitchRoll(quatRemote, -30.0f, weaponangles[MELEE]);
QuatToYawPitchRoll(quatRemote, vr_weapon_pitchadjust->value, weaponangles);
if (vr_weapon_stabilised->value &&
@ -130,21 +128,13 @@ void HandleInput_Left( ovrMobile * Ovr, double displayTime )
float zxDist = length(x, z);
if (zxDist != 0.0f && z != 0.0f) {
VectorSet(weaponangles[ADJUSTED], degrees(atanf(y / zxDist)), (cl.viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[ADJUSTED][ROLL]);
VectorSet(weaponangles[UNADJUSTED], degrees(atanf(y / zxDist)), (cl.viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[UNADJUSTED][ROLL]);
VectorSet(weaponangles[MELEE], degrees(atanf(y / zxDist)), (cl.viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[MELEE][ROLL]);
VectorSet(weaponangles, degrees(atanf(y / zxDist)), (cl.viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[ROLL]);
}
}
else
{
weaponangles[ADJUSTED][YAW] += (cl.viewangles[YAW] - hmdorientation[YAW]);
weaponangles[ADJUSTED][PITCH] *= -1.0f;
weaponangles[UNADJUSTED][YAW] += (cl.viewangles[YAW] - hmdorientation[YAW]);
weaponangles[UNADJUSTED][PITCH] *= -1.0f;
weaponangles[MELEE][YAW] += (cl.viewangles[YAW] - hmdorientation[YAW]);
weaponangles[MELEE][PITCH] *= -1.0f;
//TODO: Do we need this??
//weaponangles[YAW] += (cl.viewangles[YAW] - hmdorientation[YAW]);
}
//Use (Action)
@ -216,7 +206,7 @@ void HandleInput_Left( ovrMobile * Ovr, double displayTime )
//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
float multiplier = vr_positional_factor->value / (cl_forwardspeed->value *
((rightTrackedRemoteState_new.Buttons & ovrButton_Trigger) ? /*cl_movespeedkey->value*/ 1.0f : 1.0f));
((rightTrackedRemoteState_new.Buttons & ovrButton_Trigger) ? 1.5f : 1.0f));
vec2_t v;
rotateAboutOrigin(-positionDeltaThisFrame[0] * multiplier,

View file

@ -136,9 +136,7 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime )
//Set gun angles - We need to calculate all those we might need (including adjustments) for the client to then take its pick
const ovrQuatf quatRemote = rightRemoteTracking_new.HeadPose.Pose.Orientation;
QuatToYawPitchRoll(quatRemote, vr_weapon_pitchadjust->value, weaponangles[ADJUSTED]);
QuatToYawPitchRoll(quatRemote, 0.0f, weaponangles[UNADJUSTED]);
QuatToYawPitchRoll(quatRemote, -30.0f, weaponangles[MELEE]);
QuatToYawPitchRoll(quatRemote, vr_weapon_pitchadjust->value, weaponangles);
if (vr_weapon_stabilised->value &&
@ -151,21 +149,12 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime )
float zxDist = length(x, z);
if (zxDist != 0.0f && z != 0.0f) {
VectorSet(weaponangles[ADJUSTED], degrees(atanf(y / zxDist)), (cl.viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[ADJUSTED][ROLL]);
VectorSet(weaponangles[UNADJUSTED], degrees(atanf(y / zxDist)), (cl.viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[UNADJUSTED][ROLL]);
VectorSet(weaponangles[MELEE], degrees(atanf(y / zxDist)), (cl.viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[MELEE][ROLL]);
VectorSet(weaponangles, degrees(atanf(y / zxDist)), (cl.viewangles[YAW] - hmdorientation[YAW]) - degrees(atan2f(x, -z)), weaponangles[ROLL]);
}
}
else
{
weaponangles[ADJUSTED][YAW] += (cl.viewangles[YAW] - hmdorientation[YAW]);
weaponangles[ADJUSTED][PITCH] *= -1.0f;
weaponangles[UNADJUSTED][YAW] += (cl.viewangles[YAW] - hmdorientation[YAW]);
weaponangles[UNADJUSTED][PITCH] *= -1.0f;
weaponangles[MELEE][YAW] += (cl.viewangles[YAW] - hmdorientation[YAW]);
weaponangles[MELEE][PITCH] *= -1.0f;
weaponangles[YAW] += (cl.viewangles[YAW] - hmdorientation[YAW]);
}
//Use (Action)
@ -237,7 +226,7 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime )
//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
float multiplier = vr_positional_factor->value / (cl_forwardspeed->value *
((leftTrackedRemoteState_new.Buttons & ovrButton_Trigger) ? /*cl_movespeedkey->value*/ 1.0f : 1.0f));
((leftTrackedRemoteState_new.Buttons & ovrButton_Trigger) ? 1.5f : 1.0f));
vec2_t v;
rotateAboutOrigin(-positionDeltaThisFrame[0] * multiplier,

View file

@ -1356,10 +1356,6 @@ void CL_AddViewWeapon (player_state_t *ps, player_state_t *ops)
if (!cl_gun->value)
return;
// don't draw gun if in wide angle view
if (ps->fov > 90)
return;
memset (&gun, 0, sizeof(gun));
if (gun_model)
@ -1372,11 +1368,14 @@ void CL_AddViewWeapon (player_state_t *ps, player_state_t *ops)
// set up gun position
for (i=0 ; i<3 ; i++)
{
gun.origin[i] = cl.refdef.vieworg[i] + ops->gunoffset[i]
gun.origin[i] = cl.refdef.vieworg[i] + ps->gunoffset[i];
gun.angles[i] = ps->gunangles[i];
/* gun.origin[i] = cl.refdef.vieworg[i] + ops->gunoffset[i]
+ cl.lerpfrac * (ps->gunoffset[i] - ops->gunoffset[i]);
gun.angles[i] = cl.refdef.viewangles[i] + LerpAngle (ops->gunangles[i],
ps->gunangles[i], cl.lerpfrac);
}
*/ }
if (gun_frame)
{

View file

@ -520,6 +520,12 @@ V_RenderView
==================
*/
extern vec3_t hmdPosition;
extern cvar_t *vr_worldscale;
#define QUAKE_MARINE_HEIGHT 1.57
void V_RenderView( float stereo_separation )
{
@ -574,6 +580,11 @@ void V_RenderView( float stereo_separation )
VectorAdd( cl.refdef.vieworg, tmp, cl.refdef.vieworg );
}
//subtract standard height of player
cl.refdef.vieworg[2] -= (QUAKE_MARINE_HEIGHT * vr_worldscale->value);
//add player actual real world height
cl.refdef.vieworg[2] += (hmdPosition[1] * vr_worldscale->value);
// never let it sit exactly on a node line, because a water plane can
// dissapear when viewed with the eye exactly on it.
// the server protocol only specifies to 1/8 pixel, so add 1/16 in each axis
@ -626,7 +637,7 @@ void V_RenderView( float stereo_separation )
SCR_AddDirtyPoint (scr_vrect.x+scr_vrect.width-1,
scr_vrect.y+scr_vrect.height-1);
SCR_DrawCrosshair (stereo_separation );
//SCR_DrawCrosshair (stereo_separation );
}

View file

@ -1572,36 +1572,37 @@ void PrintPmove (pmove_t *pm)
vec3_t origin_b;
vec3_t angles_b;
extern vec3_t weaponangles[3];
extern vec3_t weaponangles;
extern vec3_t weaponoffset;
static void SV_SetWeapon_ClientOrigin(edict_t *ent)
extern cvar_t *vr_worldscale;
static void convertFromVRtoQ2(vec3_t in, vec3_t out)
{
vec3_t vrSpace;
VectorSet(vrSpace, -in[2], in[0], in[1]);
VectorScale(vrSpace, vr_worldscale->value, out);
out[2] += 16;
}
static void SV_SetWeapon_Client6DOF(edict_t *ent)
{
//Backup origin
VectorCopy(ent->s.origin, origin_b);
VectorCopy(ent->s.angles, angles_b);
VectorCopy(ent->client->v_angle, angles_b);
/* //Check gun origin validity
for (int i = 0; i < 3; ++i)
{
//Check for valid number
if (PRVM_IS_NAN(gunorg[i]) || (fabsf(gunorg[i]) > 1000000.0f)) {
Con_Printf("Got a NaN origin for weapon on entity #%i (%s)\n", PRVM_NUM_FOR_EDICT(ent),
PRVM_GetString(prog, PRVM_serveredictstring(ent, classname)));
//Just drop out, normal origin will be used in this case
return;
}
}
*/
VectorAdd(weaponoffset, ent->s.origin, ent->s.origin);
VectorCopy(weaponangles[0], ent->s.angles); // use adjusted angles
vec3_t origin;
vec3_t offset;
convertFromVRtoQ2(weaponoffset, offset);
VectorCopy(ent->s.origin, origin);
VectorAdd(offset, origin, ent->s.origin);
VectorCopy(weaponangles, ent->client->v_angle); // use adjusted angles
}
static void SV_Restore_ClientOrigin(edict_t *ent)
static void SV_Restore_Client6DOF(edict_t *ent)
{
VectorCopy(origin_b, ent->s.origin);
VectorCopy(angles_b, ent->s.angles);
VectorCopy(angles_b, ent->client->v_angle);
}
/*
@ -1766,11 +1767,11 @@ void ClientThink (edict_t *ent, usercmd_t *ucmd)
} else if (!client->weapon_thunk) {
client->weapon_thunk = true;
SV_SetWeapon_ClientOrigin(ent);
SV_SetWeapon_Client6DOF(ent);
Think_Weapon (ent);
SV_Restore_ClientOrigin(ent);
SV_Restore_Client6DOF(ent);
}
}
@ -1823,11 +1824,11 @@ void ClientBeginServerFrame (edict_t *ent)
// run weapon animations if it hasn't been done by a ucmd_t
if (!client->weapon_thunk && !client->resp.spectator) {
SV_SetWeapon_ClientOrigin(ent);
SV_SetWeapon_Client6DOF(ent);
Think_Weapon (ent);
SV_Restore_ClientOrigin(ent);
SV_Restore_Client6DOF(ent);
}
else
client->weapon_thunk = false;

View file

@ -238,11 +238,11 @@ void SV_CalcViewOffset (edict_t *ent)
{
VectorClear (angles);
ent->client->ps.viewangles[ROLL] = 40;
ent->client->ps.viewangles[PITCH] = -15;
ent->client->ps.viewangles[ROLL] = 0;
ent->client->ps.viewangles[PITCH] = 0;
ent->client->ps.viewangles[YAW] = ent->client->killer_yaw;
}
else
/* else
{
// add angles based on weapon kick
@ -287,7 +287,7 @@ void SV_CalcViewOffset (edict_t *ent)
if (bobcycle & 1)
delta = -delta;
angles[ROLL] += delta;
}
}*/
//===================================
@ -312,11 +312,11 @@ void SV_CalcViewOffset (edict_t *ent)
if (bob > 6)
bob = 6;
//gi.DebugGraph (bob *2, 255);
v[2] += bob;
//v[2] += bob;
// add kick offset
VectorAdd (v, ent->client->kick_origin, v);
//VectorAdd (v, ent->client->kick_origin, v);
// absolutely bound offsets
// so the view can never be outside the player box
@ -337,6 +337,27 @@ void SV_CalcViewOffset (edict_t *ent)
VectorCopy (v, ent->client->ps.viewoffset);
}
extern cvar_t *vr_worldscale;
extern vec3_t weaponangles;
extern vec3_t weaponoffset;
static void convertFromVRtoQ2(vec3_t in, vec3_t out)
{
vec3_t vrSpace;
VectorSet(vrSpace, -in[2], in[0], in[1]);
VectorScale(vrSpace, vr_worldscale->value, out);
out[2] += 16;
}
static void SetWeapon_Client6DOF(edict_t *ent)
{
vec3_t origin;
vec3_t offset;
convertFromVRtoQ2(weaponoffset, ent->client->ps.gunoffset);
VectorCopy(weaponangles, ent->client->ps.gunangles);
}
/*
==============
SV_CalcGunOffset
@ -344,7 +365,7 @@ SV_CalcGunOffset
*/
void SV_CalcGunOffset (edict_t *ent)
{
int i;
/* int i;
float delta;
// gun angles from bobbing
@ -386,6 +407,9 @@ void SV_CalcGunOffset (edict_t *ent)
ent->client->ps.gunoffset[i] += right[i]*gun_x->value;
ent->client->ps.gunoffset[i] += up[i]* (-gun_z->value);
}
*/
SetWeapon_Client6DOF(ent);
}

View file

@ -557,8 +557,8 @@ void weapon_grenade_fire (edict_t *ent, qboolean held)
if (is_quad)
damage *= 4;
VectorSet(offset, 8, 8, ent->viewheight-8);
AngleVectors (ent->client->v_angle, forward, right, NULL);
VectorSet(offset, 0, 0, 0);
AngleVectors (ent->client->v_angle, forward, right, NULL);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
timer = ent->client->grenade_time - level.time;
@ -718,8 +718,8 @@ void weapon_grenadelauncher_fire (edict_t *ent)
if (is_quad)
damage *= 4;
VectorSet(offset, 8, 8, ent->viewheight-8);
AngleVectors (ent->client->v_angle, forward, right, NULL);
VectorSet(offset, 0, 0, 0);
AngleVectors (ent->client->v_angle, forward, right, NULL);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
VectorScale (forward, -2, ent->client->kick_origin);
@ -778,8 +778,8 @@ void Weapon_RocketLauncher_Fire (edict_t *ent)
VectorScale (forward, -2, ent->client->kick_origin);
ent->client->kick_angles[0] = -1;
VectorSet(offset, 8, 8, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
VectorSet(offset, 0, 0, 0);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
fire_rocket (ent, start, forward, damage, 650, damage_radius, radius_damage);
// send muzzle flash
@ -822,8 +822,7 @@ void Blaster_Fire (edict_t *ent, vec3_t g_offset, int damage, qboolean hyper, in
if (is_quad)
damage *= 4;
AngleVectors (ent->client->v_angle, forward, right, NULL);
VectorSet(offset, 24, 8, ent->viewheight-8);
VectorAdd (offset, g_offset, offset);
VectorSet(offset, 0, 0, 0);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
VectorScale (forward, -2, ent->client->kick_origin);
@ -1009,8 +1008,8 @@ void Machinegun_Fire (edict_t *ent)
// get start / end positions
VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);
AngleVectors (angles, forward, right, NULL);
VectorSet(offset, 0, 8, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
VectorSet(offset, 0, 0, 0);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
gi.WriteByte (svc_muzzleflash);
@ -1200,8 +1199,8 @@ void weapon_shotgun_fire (edict_t *ent)
VectorScale (forward, -2, ent->client->kick_origin);
ent->client->kick_angles[0] = -2;
VectorSet(offset, 0, 8, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
VectorSet(offset, 0, 0, 0);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
if (is_quad)
{
@ -1250,8 +1249,8 @@ void weapon_supershotgun_fire (edict_t *ent)
VectorScale (forward, -2, ent->client->kick_origin);
ent->client->kick_angles[0] = -2;
VectorSet(offset, 0, 8, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
VectorSet(offset, 0, 0, 0);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
if (is_quad)
{
@ -1329,8 +1328,8 @@ void weapon_railgun_fire (edict_t *ent)
VectorScale (forward, -3, ent->client->kick_origin);
ent->client->kick_angles[0] = -3;
VectorSet(offset, 0, 7, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
VectorSet(offset, 0, 0, 0);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
fire_rail (ent, start, forward, damage, kick);
// send muzzle flash
@ -1410,8 +1409,8 @@ void weapon_bfg_fire (edict_t *ent)
ent->client->v_dmg_roll = crandom()*8;
ent->client->v_dmg_time = level.time + DAMAGE_TIME;
VectorSet(offset, 8, 8, ent->viewheight-8);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
VectorSet(offset, 0, 0, 0);
P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
fire_bfg (ent, start, forward, damage, 400, damage_radius);
ent->client->ps.gunframe++;