aboutsummaryrefslogtreecommitdiffstats
path: root/code/cgame
diff options
context:
space:
mode:
Diffstat (limited to 'code/cgame')
-rw-r--r--code/cgame/cg_draw.c123
-rw-r--r--code/cgame/cg_local.h3
-rw-r--r--code/cgame/cg_main.c2
3 files changed, 90 insertions, 38 deletions
diff --git a/code/cgame/cg_draw.c b/code/cgame/cg_draw.c
index a525e5c..7fe0558 100644
--- a/code/cgame/cg_draw.c
+++ b/code/cgame/cg_draw.c
@@ -1861,7 +1861,8 @@ CROSSHAIR
CG_DrawCrosshair
=================
*/
-static void CG_DrawCrosshair(void) {
+static void CG_DrawCrosshair(void)
+{
float w, h;
qhandle_t hShader;
float f;
@@ -1915,6 +1916,82 @@ static void CG_DrawCrosshair(void) {
w, h, 0, 0, 1, 1, hShader );
}
+/*
+=================
+CG_DrawCrosshair3D
+=================
+*/
+static void CG_DrawCrosshair3D(void)
+{
+ float w, h;
+ qhandle_t hShader;
+ float f;
+ int ca;
+
+ trace_t trace;
+ vec3_t endpos;
+ float stereoSep, zProj, maxdist, xmax;
+ char rendererinfos[128];
+ refEntity_t ent;
+
+ if ( !cg_drawCrosshair.integer ) {
+ return;
+ }
+
+ if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR) {
+ return;
+ }
+
+ if ( cg.renderingThirdPerson ) {
+ return;
+ }
+
+ w = h = cg_crosshairSize.value;
+
+ // pulse the size of the crosshair when picking up items
+ f = cg.time - cg.itemPickupBlendTime;
+ if ( f > 0 && f < ITEM_BLOB_TIME ) {
+ f /= ITEM_BLOB_TIME;
+ w *= ( 1 + f );
+ h *= ( 1 + f );
+ }
+
+ ca = cg_drawCrosshair.integer;
+ if (ca < 0) {
+ ca = 0;
+ }
+ hShader = cgs.media.crosshairShader[ ca % NUM_CROSSHAIRS ];
+
+ // Use a different method rendering the crosshair so players don't see two of them when
+ // focusing their eyes at distant objects with high stereo separation
+ // We are going to trace to the next shootable object and place the crosshair in front of it.
+
+ // first get all the important renderer information
+ trap_Cvar_VariableStringBuffer("r_zProj", rendererinfos, sizeof(rendererinfos));
+ zProj = atof(rendererinfos);
+ trap_Cvar_VariableStringBuffer("r_stereoSeparation", rendererinfos, sizeof(rendererinfos));
+ stereoSep = zProj / atof(rendererinfos);
+
+ xmax = zProj * tan(cg.refdef.fov_x * M_PI / 360.0f);
+
+ // let the trace run through until a change in stereo separation of the crosshair becomes less than one pixel.
+ maxdist = cgs.glconfig.vidWidth * stereoSep * zProj / (2 * xmax);
+ VectorMA(cg.refdef.vieworg, maxdist, cg.refdef.viewaxis[0], endpos);
+ CG_Trace(&trace, cg.refdef.vieworg, NULL, NULL, endpos, 0, MASK_SHOT);
+
+ memset(&ent, 0, sizeof(ent));
+ ent.reType = RT_SPRITE;
+ ent.renderfx = RF_DEPTHHACK | RF_CROSSHAIR;
+
+ VectorCopy(trace.endpos, ent.origin);
+
+ // scale the crosshair so it appears the same size for all distances
+ ent.radius = w / 640 * xmax * trace.fraction * maxdist / zProj;
+ ent.customShader = hShader;
+
+ trap_R_AddRefEntityToScene(&ent);
+}
+
/*
@@ -2439,7 +2516,8 @@ void CG_DrawTimedMenus( void ) {
CG_Draw2D
=================
*/
-static void CG_Draw2D( void ) {
+static void CG_Draw2D(stereoFrame_t stereoFrame)
+{
#ifdef MISSIONPACK
if (cgs.orderPending && cg.time > cgs.orderTime) {
CG_CheckOrderPending();
@@ -2466,7 +2544,10 @@ static void CG_Draw2D( void ) {
*/
if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR ) {
CG_DrawSpectator();
- CG_DrawCrosshair();
+
+ if(stereoFrame == STEREO_CENTER)
+ CG_DrawCrosshair();
+
CG_DrawCrosshairNames();
} else {
// don't draw any status if dead or the scoreboard is being explicitly shown
@@ -2486,7 +2567,8 @@ static void CG_Draw2D( void ) {
#ifdef MISSIONPACK
CG_DrawProxWarning();
#endif
- CG_DrawCrosshair();
+ if(stereoFrame == STEREO_CENTER)
+ CG_DrawCrosshair();
CG_DrawCrosshairNames();
CG_DrawWeaponSelect();
@@ -2550,9 +2632,6 @@ Perform all drawing needed to completely fill the screen
=====================
*/
void CG_DrawActive( stereoFrame_t stereoView ) {
- float separation;
- vec3_t baseOrg;
-
// optionally draw the info screen instead
if ( !cg.snap ) {
CG_DrawInformation();
@@ -2566,41 +2645,17 @@ void CG_DrawActive( stereoFrame_t stereoView ) {
return;
}
- switch ( stereoView ) {
- case STEREO_CENTER:
- separation = 0;
- break;
- case STEREO_LEFT:
- separation = -cg_stereoSeparation.value / 2;
- break;
- case STEREO_RIGHT:
- separation = cg_stereoSeparation.value / 2;
- break;
- default:
- separation = 0;
- CG_Error( "CG_DrawActive: Undefined stereoView" );
- }
-
-
// clear around the rendered view if sized down
CG_TileClear();
- // offset vieworg appropriately if we're doing stereo separation
- VectorCopy( cg.refdef.vieworg, baseOrg );
- if ( separation != 0 ) {
- VectorMA( cg.refdef.vieworg, -separation, cg.refdef.viewaxis[1], cg.refdef.vieworg );
- }
+ if(stereoView != STEREO_CENTER)
+ CG_DrawCrosshair3D();
// draw 3D view
trap_R_RenderScene( &cg.refdef );
- // restore original viewpoint if running stereo
- if ( separation != 0 ) {
- VectorCopy( baseOrg, cg.refdef.vieworg );
- }
-
// draw status bar and other floating elements
- CG_Draw2D();
+ CG_Draw2D(stereoView);
}
diff --git a/code/cgame/cg_local.h b/code/cgame/cg_local.h
index 71598a6..d000916 100644
--- a/code/cgame/cg_local.h
+++ b/code/cgame/cg_local.h
@@ -1134,7 +1134,6 @@ extern vmCvar_t cg_zoomFov;
extern vmCvar_t cg_thirdPersonRange;
extern vmCvar_t cg_thirdPersonAngle;
extern vmCvar_t cg_thirdPerson;
-extern vmCvar_t cg_stereoSeparation;
extern vmCvar_t cg_lagometer;
extern vmCvar_t cg_drawAttacker;
extern vmCvar_t cg_synchronousClients;
@@ -1288,7 +1287,7 @@ void CG_InitTeamChat( void );
void CG_GetTeamColor(vec4_t *color);
const char *CG_GetGameStatusText( void );
const char *CG_GetKillerText( void );
-void CG_Draw3DModel( float x, float y, float w, float h, qhandle_t model, qhandle_t skin, vec3_t origin, vec3_t angles );
+void CG_Draw3DModel(float x, float y, float w, float h, qhandle_t model, qhandle_t skin, vec3_t origin, vec3_t angles);
void CG_Text_PaintChar(float x, float y, float width, float height, float scale, float s, float t, float s2, float t2, qhandle_t hShader);
void CG_CheckOrderPending( void );
const char *CG_GameTypeString( void );
diff --git a/code/cgame/cg_main.c b/code/cgame/cg_main.c
index 15f4db5..15a5539 100644
--- a/code/cgame/cg_main.c
+++ b/code/cgame/cg_main.c
@@ -142,7 +142,6 @@ vmCvar_t cg_zoomFov;
vmCvar_t cg_thirdPerson;
vmCvar_t cg_thirdPersonRange;
vmCvar_t cg_thirdPersonAngle;
-vmCvar_t cg_stereoSeparation;
vmCvar_t cg_lagometer;
vmCvar_t cg_drawAttacker;
vmCvar_t cg_synchronousClients;
@@ -211,7 +210,6 @@ static cvarTable_t cvarTable[] = {
{ &cg_zoomFov, "cg_zoomfov", "22.5", CVAR_ARCHIVE },
{ &cg_fov, "cg_fov", "90", CVAR_ARCHIVE },
{ &cg_viewsize, "cg_viewsize", "100", CVAR_ARCHIVE },
- { &cg_stereoSeparation, "cg_stereoSeparation", "0.4", CVAR_ARCHIVE },
{ &cg_shadows, "cg_shadows", "1", CVAR_ARCHIVE },
{ &cg_gibs, "cg_gibs", "1", CVAR_ARCHIVE },
{ &cg_draw2D, "cg_draw2D", "1", CVAR_ARCHIVE },