diff --git a/android/app/src/main/cpp/code/cgame/cg_draw.c b/android/app/src/main/cpp/code/cgame/cg_draw.c index 118844bf..802cc146 100644 --- a/android/app/src/main/cpp/code/cgame/cg_draw.c +++ b/android/app/src/main/cpp/code/cgame/cg_draw.c @@ -1991,7 +1991,7 @@ static void CG_DrawCrosshair3D(void) vec3_t viewaxis[3]; vec3_t weaponangles; vec3_t origin; - CG_CalculateVRWeaponPosition(origin, weaponangles, qfalse); + CG_CalculateVRWeaponPosition(origin, weaponangles); AnglesToAxis(weaponangles, viewaxis); maxdist = (cgs.glconfig.vidWidth * stereoSep * zProj / (2 * xmax)) * 1.5f; VectorMA(origin, maxdist, viewaxis[0], endpos); diff --git a/android/app/src/main/cpp/code/cgame/cg_event.c b/android/app/src/main/cpp/code/cgame/cg_event.c index 9189ad8e..dc21f42d 100644 --- a/android/app/src/main/cpp/code/cgame/cg_event.c +++ b/android/app/src/main/cpp/code/cgame/cg_event.c @@ -1026,7 +1026,7 @@ void CG_EntityEvent( centity_t *cent, vec3_t position ) { if(es->clientNum == cg.snap->ps.clientNum && !cg.renderingThirdPerson) { vec3_t angles; - CG_CalculateVRWeaponPosition(es->origin2, angles, qfalse); + CG_CalculateVRWeaponPosition(es->origin2, angles); /* if(cg_drawGun.integer == 2) VectorMA(es->origin2, 8, cg.refdef.viewaxis[1], es->origin2); diff --git a/android/app/src/main/cpp/code/cgame/cg_local.h b/android/app/src/main/cpp/code/cgame/cg_local.h index fcbc9d3f..517f321d 100644 --- a/android/app/src/main/cpp/code/cgame/cg_local.h +++ b/android/app/src/main/cpp/code/cgame/cg_local.h @@ -1379,7 +1379,7 @@ void CG_PrevWeapon_f( void ); void CG_Weapon_f( void ); void rotateAboutOrigin(float x, float y, float rotation, vec2_t out); -void CG_CalculateVRWeaponPosition( vec3_t origin, vec3_t angles, qboolean crosshair ); +void CG_CalculateVRWeaponPosition( vec3_t origin, vec3_t angles ); void CG_ConvertFromVR(vec3_t in, vec3_t offset, vec3_t out); void CG_RegisterWeapon( int weaponNum ); diff --git a/android/app/src/main/cpp/code/cgame/cg_players.c b/android/app/src/main/cpp/code/cgame/cg_players.c index 65febd31..c680c1fc 100644 --- a/android/app/src/main/cpp/code/cgame/cg_players.c +++ b/android/app/src/main/cpp/code/cgame/cg_players.c @@ -1646,17 +1646,14 @@ void CG_CalculateVROffHandPosition( vec3_t origin, vec3_t angles ) origin[2] += vr->hmdposition[1] * worldscale; } + VectorCopy(vr->offhandangles, angles); if ( !cgs.localServer ) { //Calculate the offhand angles from "first principles" float deltaYaw = SHORT2ANGLE(cg.predictedPlayerState.delta_angles[YAW]); angles[YAW] = deltaYaw + (vr->clientviewangles[YAW] - vr->hmdorientation[YAW]) + vr->offhandangles[YAW]; - float deltaPitch = SHORT2ANGLE(cg.predictedPlayerState.delta_angles[PITCH]); - angles[PITCH] = vr->realign_pitch + deltaPitch + (vr->clientviewangles[PITCH] - vr->hmdorientation[PITCH]) + vr->offhandangles[PITCH]; - angles[ROLL] = vr->offhandangles[ROLL]; } else { - VectorCopy(vr->offhandangles, angles); angles[YAW] += (cg.refdefViewAngles[YAW] - vr->hmdorientation[YAW]); } } diff --git a/android/app/src/main/cpp/code/cgame/cg_view.c b/android/app/src/main/cpp/code/cgame/cg_view.c index ea0b6162..811a5902 100644 --- a/android/app/src/main/cpp/code/cgame/cg_view.c +++ b/android/app/src/main/cpp/code/cgame/cg_view.c @@ -707,18 +707,10 @@ static int CG_CalcViewValues( stereoFrame_t stereoView ) { if (stereoView == STEREO_LEFT) { - //Have to do this here so we can use the predicted player state - if (--vr->realign == 0) - { - VectorCopy(vr->hmdposition, vr->hmdorigin); - vr->realign_pitch -= (cg.predictedPlayerState.viewangles[PITCH]-vr->calculated_weaponangles[PITCH]) ; - vr->realign_pitch = AngleNormalize180(vr->realign_pitch); - } - VectorCopy(vr->calculated_weaponangles, vr->last_calculated_weaponangles); vec3_t weaponorigin, weaponangles; - CG_CalculateVRWeaponPosition(weaponorigin, weaponangles, qfalse); + CG_CalculateVRWeaponPosition(weaponorigin, weaponangles); vec3_t forward, end, dir; AngleVectors(weaponangles, forward, NULL, NULL); diff --git a/android/app/src/main/cpp/code/cgame/cg_weapons.c b/android/app/src/main/cpp/code/cgame/cg_weapons.c index 32c8f26a..15ff2865 100644 --- a/android/app/src/main/cpp/code/cgame/cg_weapons.c +++ b/android/app/src/main/cpp/code/cgame/cg_weapons.c @@ -255,28 +255,25 @@ void CG_ConvertFromVR(vec3_t in, vec3_t offset, vec3_t out) } } -void CG_CalculateVRWeaponPosition( vec3_t origin, vec3_t angles, qboolean crosshair ) +void CG_CalculateVRWeaponPosition( vec3_t origin, vec3_t angles ) { float worldscale = trap_Cvar_VariableValue("vr_worldscale"); if (!cgs.localServer) { - if (!crosshair) - { - //Use absolute position for the faked 6DoF for multiplayer - vec3_t weaponoffset; - VectorSubtract(vr->weaponposition, vr->hmdorigin, weaponoffset); - weaponoffset[1] = vr->weaponoffset[1]; // up/down is index 1 in this case - CG_ConvertFromVR(weaponoffset, cg.refdef.vieworg, origin); - origin[2] -= PLAYER_HEIGHT; - origin[2] += vr->hmdposition[1] * worldscale; - } - else - { - vec3_t weaponoffset; - VectorSet(weaponoffset, 0.0f, 0.0f, 0.0f); - CG_ConvertFromVR(weaponoffset, cg.refdef.vieworg, origin); - } + //Use absolute position for the faked 6DoF for multiplayer + vec3_t weaponoffset; + VectorSubtract(vr->weaponposition, vr->hmdorigin, weaponoffset); + weaponoffset[1] = vr->weaponoffset[1]; // up/down is index 1 in this case + CG_ConvertFromVR(weaponoffset, cg.refdef.vieworg, origin); + origin[2] -= PLAYER_HEIGHT; + origin[2] += vr->hmdposition[1] * worldscale; + + //Calculate the weapon angles from "first principles" + float deltaYaw = SHORT2ANGLE(cg.predictedPlayerState.delta_angles[YAW]); + angles[YAW] = deltaYaw + (vr->clientviewangles[YAW] - vr->hmdorientation[YAW]) + vr->weaponangles[YAW]; + angles[PITCH] = vr->weaponangles[PITCH]; + angles[ROLL] = vr->weaponangles[ROLL]; } else { @@ -284,22 +281,9 @@ void CG_CalculateVRWeaponPosition( vec3_t origin, vec3_t angles, qboolean crossh CG_ConvertFromVR(vr->weaponoffset, cg.refdef.vieworg, origin); origin[2] -= PLAYER_HEIGHT; origin[2] += vr->hmdposition[1] * worldscale; - } - - - if ( !cgs.localServer ) - { - //Calculate the weapon angles from "first principles" - float deltaYaw = SHORT2ANGLE(cg.predictedPlayerState.delta_angles[YAW]); - angles[YAW] = deltaYaw + (vr->clientviewangles[YAW] - vr->hmdorientation[YAW]) + vr->weaponangles[YAW]; - float deltaPitch = SHORT2ANGLE(cg.predictedPlayerState.delta_angles[PITCH]); - angles[PITCH] = vr->realign_pitch + deltaPitch + vr->weaponangles[PITCH]; - angles[ROLL] = vr->weaponangles[ROLL]; - } else - { VectorCopy(vr->weaponangles, angles); - angles[YAW] += (cg.refdefViewAngles[YAW] - vr->hmdorientation[YAW]); + angles[YAW] += (cg.refdefViewAngles[YAW] - vr->hmdorientation[YAW]); } } @@ -1307,7 +1291,7 @@ static void CG_LightningBolt( centity_t *cent, vec3_t origin ) { if (cent->currentState.number == cg.predictedPlayerState.clientNum)// && (cg_trueLightning.value != 0)) { vec3_t angle; - CG_CalculateVRWeaponPosition(muzzlePoint, angle, qfalse); + CG_CalculateVRWeaponPosition(muzzlePoint, angle); AngleVectors(angle, forward, NULL, NULL ); } else { // !CPMA @@ -1717,7 +1701,7 @@ void CG_AddViewWeapon( playerState_t *ps ) { memset (&hand, 0, sizeof(hand)); // set up gun position - CG_CalculateVRWeaponPosition( hand.origin, angles, qfalse ); + CG_CalculateVRWeaponPosition( hand.origin, angles ); //Scale / Move gun etc float scale = 1.0f; diff --git a/android/app/src/main/cpp/code/client/cl_input.c b/android/app/src/main/cpp/code/client/cl_input.c index e25c01cc..7a84a590 100644 --- a/android/app/src/main/cpp/code/client/cl_input.c +++ b/android/app/src/main/cpp/code/client/cl_input.c @@ -604,13 +604,18 @@ void CL_FinishMove( usercmd_t *cmd ) { { vr.local_server = qfalse; - vec3_t angles; + //Realign in playspace + if (--vr.realign == 0) + { + VectorCopy(vr.hmdposition, vr.hmdorigin); + } + + vec3_t angles; VectorCopy(vr.calculated_weaponangles, angles); + //Adjust for difference in server angles float deltaPitch = SHORT2ANGLE(cl.snap.ps.delta_angles[PITCH]); - Com_Printf("realign_pitch: %f, delta pitch: %f", vr.realign_pitch, deltaPitch); - - angles[PITCH] += vr.realign_pitch; + angles[PITCH] -= deltaPitch; angles[YAW] += (cl.viewangles[YAW] - vr.hmdorientation[YAW]); angles[ROLL] = 0; // suppress roll diff --git a/android/app/src/main/cpp/code/vr/vr_clientinfo.h b/android/app/src/main/cpp/code/vr/vr_clientinfo.h index 1f8402c1..5a2430a1 100644 --- a/android/app/src/main/cpp/code/vr/vr_clientinfo.h +++ b/android/app/src/main/cpp/code/vr/vr_clientinfo.h @@ -13,8 +13,7 @@ typedef struct { qboolean virtual_screen; qboolean local_server; // used in bg_pmove.c - int realign; // used to realign the weapon/playspace in a multiplayer game - float realign_pitch; // used to realign the weapon pitch in a multiplayer game + int realign; // used to realign the fake 6DoF playspace in a multiplayer game int clientNum; vec3_t clientviewangles; //orientation in the client - we use this in the cgame