Skip to content

Commit

Permalink
VR in first-person view, you can look through walls
Browse files Browse the repository at this point in the history
  • Loading branch information
pelya committed Mar 20, 2016
1 parent 4135ad4 commit 333d593
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
6 changes: 3 additions & 3 deletions code/cgame/cg_draw.c
Expand Up @@ -2607,7 +2607,7 @@ static void CG_DrawCrosshair(stereoFrame_t stereoFrame) {
return;
}

if (stereoFrame != STEREO_CENTER && cg.renderingThirdPerson) {
if (stereoFrame != STEREO_CENTER) {
return;
}

Expand Down Expand Up @@ -2645,7 +2645,7 @@ static void CG_DrawCrosshair3D(stereoFrame_t stereoFrame) {
return;
}

if (stereoFrame == STEREO_CENTER || !cg.renderingThirdPerson) {
if (stereoFrame == STEREO_CENTER) {
return;
}

Expand All @@ -2664,7 +2664,7 @@ static void CG_DrawCrosshair3D(stereoFrame_t stereoFrame) {

VectorCopy( cg.aimingSpot, ent.origin );
// scale the crosshair so it appears the same size for all distances
ent.radius = 1.9f * coords[2] / cgs.glconfig.vidWidth * dist;
ent.radius = 1.9f * coords[2] / cgs.glconfig.vidWidth * dist * cg.refdef.fov_x / 90.0f;

// Set appropriate color, scale it because level lighting makes all 2D entities dimmer
ent.shaderRGBA[0] = color[0] * 1000.0f;
Expand Down
29 changes: 27 additions & 2 deletions code/cgame/cg_view.c
Expand Up @@ -419,7 +419,7 @@ CG_OffsetFirstPersonView
===============
*/
static void CG_OffsetFirstPersonView( void ) {
static void CG_OffsetFirstPersonView( stereoFrame_t stereoView ) {
float *origin;
float *angles;
float bob;
Expand Down Expand Up @@ -549,6 +549,31 @@ static void CG_OffsetFirstPersonView( void ) {
VectorMA( cg.refdef.vieworg, NECK_LENGTH, up, cg.refdef.vieworg );
}
#endif

if (stereoView != STEREO_CENTER) {
vec3_t forward;
vec3_t right;
AngleVectors( angles, forward, right, NULL );

if (stereoView == STEREO_LEFT) {
trace_t trace;

// Calculate player aiming, that will bump against level walls and other players
// First we calculate a distant point, where we'd be aiming if there are no walls around
VectorMA( origin, 10000.0f, forward, cg.aimingSpot );

// Bump it against the level walls
CG_Trace( &trace, origin, NULL, NULL, cg.aimingSpot, cg.predictedPlayerState.clientNum, MASK_SHOT );
VectorCopy( trace.endpos, cg.aimingSpot ); // Save for later, to draw crosshair

VectorMA( origin, -r_stereoSeparation.value, right, origin );
angles[YAW] += r_stereoAngle.value;
}
if (stereoView == STEREO_RIGHT) {
VectorMA( origin, r_stereoSeparation.value, right, origin );
angles[YAW] -= r_stereoAngle.value;
}
}
}

//======================================================================
Expand Down Expand Up @@ -906,7 +931,7 @@ static int CG_CalcViewValues( stereoFrame_t stereoView ) {
CG_OffsetThirdPersonView(stereoView);
} else {
// offset for local bobbing and kicks
CG_OffsetFirstPersonView();
CG_OffsetFirstPersonView(stereoView);
}

if ( cg_touchscreenControls.integer == TOUCHSCREEN_FLOATING_CROSSHAIR )
Expand Down
5 changes: 0 additions & 5 deletions code/q3_ui/ui_menu.c
Expand Up @@ -185,11 +185,6 @@ void Main_MenuEvent (void* ptr, int event) {

case ID_CARDBOARDVR:
trap_Cvar_SetValue( "r_cardboardStereo", s_main.cardboardVR.curvalue );
if (s_main.cardboardVR.curvalue) {
s_main.firstperson.curvalue = 0;
trap_Cvar_SetValue( "cg_thirdPersonConfigOptionInSettings", !s_main.firstperson.curvalue );
trap_Cvar_SetValue( "cg_thirdperson", !s_main.firstperson.curvalue );
}
break;
}
}
Expand Down

0 comments on commit 333d593

Please sign in to comment.