- replace a few constant values with GL macros in tr_cmds.c

- tidy up top of tr_types.h a bit, change flags to hex representation
- make ROM cvar enforcing really work
- remove cg_stereoSeparation from cgame as it is obsolete.
- Add CG_DrawCrosshair3D so people see crosshair correctly when stereoseparation is enabled
This commit is contained in:
Thilo Schulz 2008-05-01 14:56:57 +00:00
parent 65938da5ae
commit 10ed996784
10 changed files with 173 additions and 89 deletions

View file

@ -1861,7 +1861,8 @@ CROSSHAIR
CG_DrawCrosshair CG_DrawCrosshair
================= =================
*/ */
static void CG_DrawCrosshair(void) { static void CG_DrawCrosshair(void)
{
float w, h; float w, h;
qhandle_t hShader; qhandle_t hShader;
float f; float f;
@ -1915,6 +1916,82 @@ static void CG_DrawCrosshair(void) {
w, h, 0, 0, 1, 1, hShader ); 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 CG_Draw2D
================= =================
*/ */
static void CG_Draw2D( void ) { static void CG_Draw2D(stereoFrame_t stereoFrame)
{
#ifdef MISSIONPACK #ifdef MISSIONPACK
if (cgs.orderPending && cg.time > cgs.orderTime) { if (cgs.orderPending && cg.time > cgs.orderTime) {
CG_CheckOrderPending(); CG_CheckOrderPending();
@ -2466,7 +2544,10 @@ static void CG_Draw2D( void ) {
*/ */
if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR ) { if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR ) {
CG_DrawSpectator(); CG_DrawSpectator();
if(stereoFrame == STEREO_CENTER)
CG_DrawCrosshair(); CG_DrawCrosshair();
CG_DrawCrosshairNames(); CG_DrawCrosshairNames();
} else { } else {
// don't draw any status if dead or the scoreboard is being explicitly shown // don't draw any status if dead or the scoreboard is being explicitly shown
@ -2486,6 +2567,7 @@ static void CG_Draw2D( void ) {
#ifdef MISSIONPACK #ifdef MISSIONPACK
CG_DrawProxWarning(); CG_DrawProxWarning();
#endif #endif
if(stereoFrame == STEREO_CENTER)
CG_DrawCrosshair(); CG_DrawCrosshair();
CG_DrawCrosshairNames(); CG_DrawCrosshairNames();
CG_DrawWeaponSelect(); CG_DrawWeaponSelect();
@ -2550,9 +2632,6 @@ Perform all drawing needed to completely fill the screen
===================== =====================
*/ */
void CG_DrawActive( stereoFrame_t stereoView ) { void CG_DrawActive( stereoFrame_t stereoView ) {
float separation;
vec3_t baseOrg;
// optionally draw the info screen instead // optionally draw the info screen instead
if ( !cg.snap ) { if ( !cg.snap ) {
CG_DrawInformation(); CG_DrawInformation();
@ -2566,41 +2645,17 @@ void CG_DrawActive( stereoFrame_t stereoView ) {
return; 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 // clear around the rendered view if sized down
CG_TileClear(); CG_TileClear();
// offset vieworg appropriately if we're doing stereo separation if(stereoView != STEREO_CENTER)
VectorCopy( cg.refdef.vieworg, baseOrg ); CG_DrawCrosshair3D();
if ( separation != 0 ) {
VectorMA( cg.refdef.vieworg, -separation, cg.refdef.viewaxis[1], cg.refdef.vieworg );
}
// draw 3D view // draw 3D view
trap_R_RenderScene( &cg.refdef ); 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 // draw status bar and other floating elements
CG_Draw2D(); CG_Draw2D(stereoView);
} }

View file

@ -1134,7 +1134,6 @@ extern vmCvar_t cg_zoomFov;
extern vmCvar_t cg_thirdPersonRange; extern vmCvar_t cg_thirdPersonRange;
extern vmCvar_t cg_thirdPersonAngle; extern vmCvar_t cg_thirdPersonAngle;
extern vmCvar_t cg_thirdPerson; extern vmCvar_t cg_thirdPerson;
extern vmCvar_t cg_stereoSeparation;
extern vmCvar_t cg_lagometer; extern vmCvar_t cg_lagometer;
extern vmCvar_t cg_drawAttacker; extern vmCvar_t cg_drawAttacker;
extern vmCvar_t cg_synchronousClients; extern vmCvar_t cg_synchronousClients;

View file

@ -142,7 +142,6 @@ vmCvar_t cg_zoomFov;
vmCvar_t cg_thirdPerson; vmCvar_t cg_thirdPerson;
vmCvar_t cg_thirdPersonRange; vmCvar_t cg_thirdPersonRange;
vmCvar_t cg_thirdPersonAngle; vmCvar_t cg_thirdPersonAngle;
vmCvar_t cg_stereoSeparation;
vmCvar_t cg_lagometer; vmCvar_t cg_lagometer;
vmCvar_t cg_drawAttacker; vmCvar_t cg_drawAttacker;
vmCvar_t cg_synchronousClients; vmCvar_t cg_synchronousClients;
@ -211,7 +210,6 @@ static cvarTable_t cvarTable[] = {
{ &cg_zoomFov, "cg_zoomfov", "22.5", CVAR_ARCHIVE }, { &cg_zoomFov, "cg_zoomfov", "22.5", CVAR_ARCHIVE },
{ &cg_fov, "cg_fov", "90", CVAR_ARCHIVE }, { &cg_fov, "cg_fov", "90", CVAR_ARCHIVE },
{ &cg_viewsize, "cg_viewsize", "100", 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_shadows, "cg_shadows", "1", CVAR_ARCHIVE },
{ &cg_gibs, "cg_gibs", "1", CVAR_ARCHIVE }, { &cg_gibs, "cg_gibs", "1", CVAR_ARCHIVE },
{ &cg_draw2D, "cg_draw2D", "1", CVAR_ARCHIVE }, { &cg_draw2D, "cg_draw2D", "1", CVAR_ARCHIVE },

View file

@ -2743,6 +2743,8 @@ void CL_Init( void ) {
// cgame might not be initialized before menu is used // cgame might not be initialized before menu is used
Cvar_Get ("cg_viewsize", "100", CVAR_ARCHIVE ); Cvar_Get ("cg_viewsize", "100", CVAR_ARCHIVE );
// Make sure cg_stereoSeparation is zero as that variable is deprecated and should not be used anymore.
Cvar_Get ("cg_stereoSeparation", "0", CVAR_ROM);
// //
// register our commands // register our commands

View file

@ -474,7 +474,7 @@ void SCR_DrawScreenField( stereoFrame_t stereoFrame ) {
case CA_LOADING: case CA_LOADING:
case CA_PRIMED: case CA_PRIMED:
// draw the game information screen and loading progress // draw the game information screen and loading progress
CL_CGameRendering(STEREO_CENTER); CL_CGameRendering(stereoFrame);
// also draw the connection information, so it doesn't // also draw the connection information, so it doesn't
// flash away too briefly on local or lan games // flash away too briefly on local or lan games
@ -484,7 +484,7 @@ void SCR_DrawScreenField( stereoFrame_t stereoFrame ) {
break; break;
case CA_ACTIVE: case CA_ACTIVE:
// always supply STEREO_CENTER as vieworg offset is now done by the engine. // always supply STEREO_CENTER as vieworg offset is now done by the engine.
CL_CGameRendering(STEREO_CENTER); CL_CGameRendering(stereoFrame);
SCR_DrawDemoRecording(); SCR_DrawDemoRecording();
break; break;
} }

View file

@ -228,6 +228,17 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
Z_Free( var->resetString ); Z_Free( var->resetString );
var->resetString = CopyString( var_value ); var->resetString = CopyString( var_value );
if(flags & CVAR_ROM)
{
// this variable was set by the user,
// so force it to value given by the engine.
if(var->latchedString)
Z_Free(var->latchedString);
var->latchedString = CopyString(var_value);
}
// ZOID--needs to be set so that cvars the game sets as // ZOID--needs to be set so that cvars the game sets as
// SERVERINFO get sent to clients // SERVERINFO get sent to clients
cvar_modifiedFlags |= flags; cvar_modifiedFlags |= flags;
@ -239,16 +250,6 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
// we don't have a reset string yet // we don't have a reset string yet
Z_Free( var->resetString ); Z_Free( var->resetString );
var->resetString = CopyString( var_value ); var->resetString = CopyString( var_value );
// if there is no reset string yet this means the variable was set by the user,
// so force it to value given by the engine.
if(var->flags & CVAR_ROM)
{
if(var->latchedString)
Z_Free(var->latchedString);
var->latchedString = CopyString(var_value);
}
} else if ( var_value[0] && strcmp( var->resetString, var_value ) ) { } else if ( var_value[0] && strcmp( var->resetString, var_value ) ) {
Com_DPrintf( "Warning: cvar \"%s\" given initial values: \"%s\" and \"%s\"\n", Com_DPrintf( "Warning: cvar \"%s\" given initial values: \"%s\" and \"%s\"\n",
var_name, var->resetString, var_value ); var_name, var->resetString, var_value );

View file

@ -521,7 +521,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
int fogNum, oldFogNum; int fogNum, oldFogNum;
int entityNum, oldEntityNum; int entityNum, oldEntityNum;
int dlighted, oldDlighted; int dlighted, oldDlighted;
qboolean depthRange, oldDepthRange; qboolean depthRange, oldDepthRange, isCrosshair, wasCrosshair;
int i; int i;
drawSurf_t *drawSurf; drawSurf_t *drawSurf;
int oldSort; int oldSort;
@ -539,6 +539,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
oldShader = NULL; oldShader = NULL;
oldFogNum = -1; oldFogNum = -1;
oldDepthRange = qfalse; oldDepthRange = qfalse;
wasCrosshair = qfalse;
oldDlighted = qfalse; oldDlighted = qfalse;
oldSort = -1; oldSort = -1;
depthRange = qfalse; depthRange = qfalse;
@ -573,7 +574,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
// change the modelview matrix if needed // change the modelview matrix if needed
// //
if ( entityNum != oldEntityNum ) { if ( entityNum != oldEntityNum ) {
depthRange = qfalse; depthRange = isCrosshair = qfalse;
if ( entityNum != ENTITYNUM_WORLD ) { if ( entityNum != ENTITYNUM_WORLD ) {
backEnd.currentEntity = &backEnd.refdef.entities[entityNum]; backEnd.currentEntity = &backEnd.refdef.entities[entityNum];
@ -590,9 +591,13 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
R_TransformDlights( backEnd.refdef.num_dlights, backEnd.refdef.dlights, &backEnd.or ); R_TransformDlights( backEnd.refdef.num_dlights, backEnd.refdef.dlights, &backEnd.or );
} }
if ( backEnd.currentEntity->e.renderfx & RF_DEPTHHACK ) { if(backEnd.currentEntity->e.renderfx & RF_DEPTHHACK)
{
// hack the depth range to prevent view model from poking into walls // hack the depth range to prevent view model from poking into walls
depthRange = qtrue; depthRange = qtrue;
if(backEnd.currentEntity->e.renderfx & RF_CROSSHAIR)
isCrosshair = qtrue;
} }
} else { } else {
backEnd.currentEntity = &tr.worldEntity; backEnd.currentEntity = &tr.worldEntity;
@ -610,11 +615,23 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
// change depthrange. Also change projection matrix so first person weapon does not look like coming // change depthrange. Also change projection matrix so first person weapon does not look like coming
// out of the screen. // out of the screen.
// //
if (oldDepthRange != depthRange) if (oldDepthRange != depthRange || wasCrosshair != isCrosshair)
{ {
if (depthRange) if (depthRange)
{ {
if(backEnd.viewParms.stereoFrame != STEREO_CENTER) if(backEnd.viewParms.stereoFrame != STEREO_CENTER)
{
if(isCrosshair)
{
if(oldDepthRange)
{
// was not a crosshair but now is, change back proj matrix
qglMatrixMode(GL_PROJECTION);
qglLoadMatrixf(backEnd.viewParms.projectionMatrix);
qglMatrixMode(GL_MODELVIEW);
}
}
else
{ {
viewParms_t temp = backEnd.viewParms; viewParms_t temp = backEnd.viewParms;
@ -624,12 +641,14 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
qglLoadMatrixf(temp.projectionMatrix); qglLoadMatrixf(temp.projectionMatrix);
qglMatrixMode(GL_MODELVIEW); qglMatrixMode(GL_MODELVIEW);
} }
}
if(!oldDepthRange)
qglDepthRange (0, 0.3); qglDepthRange (0, 0.3);
} }
else else
{ {
if(backEnd.viewParms.stereoFrame != STEREO_CENTER) if(!wasCrosshair && backEnd.viewParms.stereoFrame != STEREO_CENTER)
{ {
qglMatrixMode(GL_PROJECTION); qglMatrixMode(GL_PROJECTION);
qglLoadMatrixf(backEnd.viewParms.projectionMatrix); qglLoadMatrixf(backEnd.viewParms.projectionMatrix);
@ -640,6 +659,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
} }
oldDepthRange = depthRange; oldDepthRange = depthRange;
wasCrosshair = isCrosshair;
} }
oldEntityNum = entityNum; oldEntityNum = entityNum;

View file

@ -319,9 +319,9 @@ void R_SetColorMode(GLboolean *rgba, stereoFrame_t stereoFrame, int colormode)
rgba[0] = GL_FALSE; rgba[0] = GL_FALSE;
if(colormode == MODE_RED_BLUE) if(colormode == MODE_RED_BLUE)
rgba[1] = 0; rgba[1] = GL_FALSE;
else if(colormode == MODE_RED_GREEN) else if(colormode == MODE_RED_GREEN)
rgba[2] = 0; rgba[2] = GL_FALSE;
} }
} }

View file

@ -456,7 +456,7 @@ void R_SetupFrustum (viewParms_t *dest, float xmin, float xmax, float ymax, floa
float oppleg, adjleg, length; float oppleg, adjleg, length;
int i; int i;
if(stereoSep == 0) if(stereoSep == 0 && xmin != -xmax)
{ {
// symmetric case can be simplified // symmetric case can be simplified
VectorCopy(dest->or.origin, ofsorigin); VectorCopy(dest->or.origin, ofsorigin);
@ -513,19 +513,22 @@ R_SetupProjection
void R_SetupProjection(viewParms_t *dest, float zProj, qboolean computeFrustum) void R_SetupProjection(viewParms_t *dest, float zProj, qboolean computeFrustum)
{ {
float xmin, xmax, ymin, ymax; float xmin, xmax, ymin, ymax;
float width, height, stereoSep; float width, height, stereoSep = r_stereoSeparation->value;
/* /*
* offset the view origin of the viewer for stereo rendering * offset the view origin of the viewer for stereo rendering
* by setting the projection matrix appropriately. * by setting the projection matrix appropriately.
*/ */
if(stereoSep != 0)
{
if(dest->stereoFrame == STEREO_LEFT) if(dest->stereoFrame == STEREO_LEFT)
stereoSep = zProj / r_stereoSeparation->value; stereoSep = zProj / r_stereoSeparation->value;
else if(dest->stereoFrame == STEREO_RIGHT) else if(dest->stereoFrame == STEREO_RIGHT)
stereoSep = zProj / -r_stereoSeparation->value; stereoSep = zProj / -r_stereoSeparation->value;
else else
stereoSep = 0; stereoSep = 0;
}
ymax = zProj * tan(dest->fovY * M_PI / 360.0f); ymax = zProj * tan(dest->fovY * M_PI / 360.0f);
ymin = -ymax; ymin = -ymax;

View file

@ -28,23 +28,29 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define MAX_ENTITIES 1023 // can't be increased without changing drawsurf bit packing #define MAX_ENTITIES 1023 // can't be increased without changing drawsurf bit packing
// renderfx flags // renderfx flags
#define RF_MINLIGHT 1 // allways have some light (viewmodel, some items) #define RF_MINLIGHT 0x0001 // allways have some light (viewmodel, some items)
#define RF_THIRD_PERSON 2 // don't draw through eyes, only mirrors (player bodies, chat sprites) #define RF_THIRD_PERSON 0x0002 // don't draw through eyes, only mirrors (player bodies, chat sprites)
#define RF_FIRST_PERSON 4 // only draw through eyes (view weapon, damage blood blob) #define RF_FIRST_PERSON 0x0004 // only draw through eyes (view weapon, damage blood blob)
#define RF_DEPTHHACK 8 // for view weapon Z crunching #define RF_DEPTHHACK 0x0008 // for view weapon Z crunching
#define RF_NOSHADOW 64 // don't add stencil shadows
#define RF_LIGHTING_ORIGIN 128 // use refEntity->lightingOrigin instead of refEntity->origin #define RF_CROSSHAIR 0x0010 // This item is a cross hair and will draw over everything similar to
// DEPTHHACK in stereo rendering mode, with the difference that the
// projection matrix won't be hacked to reduce the stereo separation as
// is done for the gun.
#define RF_NOSHADOW 0x0040 // don't add stencil shadows
#define RF_LIGHTING_ORIGIN 0x0080 // use refEntity->lightingOrigin instead of refEntity->origin
// for lighting. This allows entities to sink into the floor // for lighting. This allows entities to sink into the floor
// with their origin going solid, and allows all parts of a // with their origin going solid, and allows all parts of a
// player to get the same lighting // player to get the same lighting
#define RF_SHADOW_PLANE 256 // use refEntity->shadowPlane
#define RF_WRAP_FRAMES 512 // mod the model frames by the maxframes to allow continuous #define RF_SHADOW_PLANE 0x0100 // use refEntity->shadowPlane
// animation without needing to know the frame count #define RF_WRAP_FRAMES 0x0200 // mod the model frames by the maxframes to allow continuous
// refdef flags // refdef flags
#define RDF_NOWORLDMODEL 1 // used for player configuration screen #define RDF_NOWORLDMODEL 0x0001 // used for player configuration screen
#define RDF_HYPERSPACE 4 // teleportation effect #define RDF_HYPERSPACE 0x0004 // teleportation effect
typedef struct { typedef struct {
vec3_t xyz; vec3_t xyz;