?? r_alias.c
字號:
{
R_AliasProjectAndClipTestFinalVert( fv );
}
}
}
#endif
/*
================
R_AliasProjectAndClipTestFinalVert
================
*/
void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv )
{
float zi;
float x, y, z;
// project points
x = fv->xyz[0];
y = fv->xyz[1];
z = fv->xyz[2];
zi = 1.0 / z;
fv->zi = zi * s_ziscale;
fv->u = (x * aliasxscale * zi) + aliasxcenter;
fv->v = (y * aliasyscale * zi) + aliasycenter;
if (fv->u < r_refdef.aliasvrect.x)
fv->flags |= ALIAS_LEFT_CLIP;
if (fv->v < r_refdef.aliasvrect.y)
fv->flags |= ALIAS_TOP_CLIP;
if (fv->u > r_refdef.aliasvrectright)
fv->flags |= ALIAS_RIGHT_CLIP;
if (fv->v > r_refdef.aliasvrectbottom)
fv->flags |= ALIAS_BOTTOM_CLIP;
}
/*
===============
R_AliasSetupSkin
===============
*/
static qboolean R_AliasSetupSkin (void)
{
int skinnum;
image_t *pskindesc;
if (currententity->skin)
pskindesc = currententity->skin;
else
{
skinnum = currententity->skinnum;
if ((skinnum >= s_pmdl->num_skins) || (skinnum < 0))
{
ri.Con_Printf (PRINT_ALL, "R_AliasSetupSkin %s: no such skin # %d\n",
currentmodel->name, skinnum);
skinnum = 0;
}
pskindesc = currentmodel->skins[skinnum];
}
if ( !pskindesc )
return false;
r_affinetridesc.pskin = pskindesc->pixels[0];
r_affinetridesc.skinwidth = pskindesc->width;
r_affinetridesc.skinheight = pskindesc->height;
R_PolysetUpdateTables (); // FIXME: precalc edge lookups
return true;
}
/*
================
R_AliasSetupLighting
FIXME: put lighting into tables
================
*/
void R_AliasSetupLighting (void)
{
alight_t lighting;
float lightvec[3] = {-1, 0, 0};
vec3_t light;
int i, j;
// all components of light should be identical in software
if ( currententity->flags & RF_FULLBRIGHT )
{
for (i=0 ; i<3 ; i++)
light[i] = 1.0;
}
else
{
R_LightPoint (currententity->origin, light);
}
// save off light value for server to look at (BIG HACK!)
if ( currententity->flags & RF_WEAPONMODEL )
r_lightlevel->value = 150.0 * light[0];
if ( currententity->flags & RF_MINLIGHT )
{
for (i=0 ; i<3 ; i++)
if (light[i] < 0.1)
light[i] = 0.1;
}
if ( currententity->flags & RF_GLOW )
{ // bonus items will pulse with time
float scale;
float min;
scale = 0.1 * sin(r_newrefdef.time*7);
for (i=0 ; i<3 ; i++)
{
min = light[i] * 0.8;
light[i] += scale;
if (light[i] < min)
light[i] = min;
}
}
j = (light[0] + light[1] + light[2])*0.3333*255;
lighting.ambientlight = j;
lighting.shadelight = j;
lighting.plightvec = lightvec;
// clamp lighting so it doesn't overbright as much
if (lighting.ambientlight > 128)
lighting.ambientlight = 128;
if (lighting.ambientlight + lighting.shadelight > 192)
lighting.shadelight = 192 - lighting.ambientlight;
// guarantee that no vertex will ever be lit below LIGHT_MIN, so we don't have
// to clamp off the bottom
r_ambientlight = lighting.ambientlight;
if (r_ambientlight < LIGHT_MIN)
r_ambientlight = LIGHT_MIN;
r_ambientlight = (255 - r_ambientlight) << VID_CBITS;
if (r_ambientlight < LIGHT_MIN)
r_ambientlight = LIGHT_MIN;
r_shadelight = lighting.shadelight;
if (r_shadelight < 0)
r_shadelight = 0;
r_shadelight *= VID_GRADES;
// rotate the lighting vector into the model's frame of reference
r_plightvec[0] = DotProduct( lighting.plightvec, s_alias_forward );
r_plightvec[1] = -DotProduct( lighting.plightvec, s_alias_right );
r_plightvec[2] = DotProduct( lighting.plightvec, s_alias_up );
}
/*
=================
R_AliasSetupFrames
=================
*/
void R_AliasSetupFrames( dmdl_t *pmdl )
{
int thisframe = currententity->frame;
int lastframe = currententity->oldframe;
if ( ( thisframe >= pmdl->num_frames ) || ( thisframe < 0 ) )
{
ri.Con_Printf (PRINT_ALL, "R_AliasSetupFrames %s: no such thisframe %d\n",
currentmodel->name, thisframe);
thisframe = 0;
}
if ( ( lastframe >= pmdl->num_frames ) || ( lastframe < 0 ) )
{
ri.Con_Printf (PRINT_ALL, "R_AliasSetupFrames %s: no such lastframe %d\n",
currentmodel->name, lastframe);
lastframe = 0;
}
r_thisframe = (daliasframe_t *)((byte *)pmdl + pmdl->ofs_frames
+ thisframe * pmdl->framesize);
r_lastframe = (daliasframe_t *)((byte *)pmdl + pmdl->ofs_frames
+ lastframe * pmdl->framesize);
}
/*
** R_AliasSetUpLerpData
**
** Precomputes lerp coefficients used for the whole frame.
*/
void R_AliasSetUpLerpData( dmdl_t *pmdl, float backlerp )
{
float frontlerp;
vec3_t translation, vectors[3];
int i;
frontlerp = 1.0F - backlerp;
/*
** convert entity's angles into discrete vectors for R, U, and F
*/
AngleVectors (currententity->angles, vectors[0], vectors[1], vectors[2]);
/*
** translation is the vector from last position to this position
*/
VectorSubtract (currententity->oldorigin, currententity->origin, translation);
/*
** move should be the delta back to the previous frame * backlerp
*/
r_lerp_move[0] = DotProduct(translation, vectors[0]); // forward
r_lerp_move[1] = -DotProduct(translation, vectors[1]); // left
r_lerp_move[2] = DotProduct(translation, vectors[2]); // up
VectorAdd( r_lerp_move, r_lastframe->translate, r_lerp_move );
for (i=0 ; i<3 ; i++)
{
r_lerp_move[i] = backlerp*r_lerp_move[i] + frontlerp * r_thisframe->translate[i];
}
for (i=0 ; i<3 ; i++)
{
r_lerp_frontv[i] = frontlerp * r_thisframe->scale[i];
r_lerp_backv[i] = backlerp * r_lastframe->scale[i];
}
}
/*
================
R_AliasDrawModel
================
*/
void R_AliasDrawModel (void)
{
extern void (*d_pdrawspans)(void *);
extern void R_PolysetDrawSpans8_Opaque( void * );
extern void R_PolysetDrawSpans8_33( void * );
extern void R_PolysetDrawSpans8_66( void * );
extern void R_PolysetDrawSpansConstant8_33( void * );
extern void R_PolysetDrawSpansConstant8_66( void * );
s_pmdl = (dmdl_t *)currentmodel->extradata;
if ( r_lerpmodels->value == 0 )
currententity->backlerp = 0;
if ( currententity->flags & RF_WEAPONMODEL )
{
if ( r_lefthand->value == 1.0F )
aliasxscale = -aliasxscale;
else if ( r_lefthand->value == 2.0F )
return;
}
/*
** we have to set our frame pointers and transformations before
** doing any real work
*/
R_AliasSetupFrames( s_pmdl );
R_AliasSetUpTransform();
// see if the bounding box lets us trivially reject, also sets
// trivial accept status
if ( R_AliasCheckBBox() == BBOX_TRIVIAL_REJECT )
{
if ( ( currententity->flags & RF_WEAPONMODEL ) && ( r_lefthand->value == 1.0F ) )
{
aliasxscale = -aliasxscale;
}
return;
}
// set up the skin and verify it exists
if ( !R_AliasSetupSkin () )
{
ri.Con_Printf( PRINT_ALL, "R_AliasDrawModel %s: NULL skin found\n",
currentmodel->name);
return;
}
r_amodels_drawn++;
R_AliasSetupLighting ();
/*
** select the proper span routine based on translucency
*/
// PMM - added double damage shell
// PMM - reordered to handle blending
if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM) )
{
int color;
// PMM - added double
color = currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM);
// PMM - reordered, new shells after old shells (so they get overriden)
if ( color == RF_SHELL_RED )
r_aliasblendcolor = SHELL_RED_COLOR;
else if ( color == RF_SHELL_GREEN )
r_aliasblendcolor = SHELL_GREEN_COLOR;
else if ( color == RF_SHELL_BLUE )
r_aliasblendcolor = SHELL_BLUE_COLOR;
else if ( color == (RF_SHELL_RED | RF_SHELL_GREEN) )
r_aliasblendcolor = SHELL_RG_COLOR;
else if ( color == (RF_SHELL_RED | RF_SHELL_BLUE) )
r_aliasblendcolor = SHELL_RB_COLOR;
else if ( color == (RF_SHELL_BLUE | RF_SHELL_GREEN) )
r_aliasblendcolor = SHELL_BG_COLOR;
// PMM - added this .. it's yellowish
else if ( color == (RF_SHELL_DOUBLE) )
r_aliasblendcolor = SHELL_DOUBLE_COLOR;
else if ( color == (RF_SHELL_HALF_DAM) )
r_aliasblendcolor = SHELL_HALF_DAM_COLOR;
// pmm
else
r_aliasblendcolor = SHELL_WHITE_COLOR;
/* if ( color & RF_SHELL_RED )
{
if ( ( color & RF_SHELL_BLUE) && ( color & RF_SHELL_GREEN) )
r_aliasblendcolor = SHELL_WHITE_COLOR;
else if ( color & (RF_SHELL_BLUE | RF_SHELL_DOUBLE))
r_aliasblendcolor = SHELL_RB_COLOR;
else
r_aliasblendcolor = SHELL_RED_COLOR;
}
else if ( color & RF_SHELL_BLUE)
{
if ( color & RF_SHELL_DOUBLE )
r_aliasblendcolor = SHELL_CYAN_COLOR;
else
r_aliasblendcolor = SHELL_BLUE_COLOR;
}
else if ( color & (RF_SHELL_DOUBLE) )
r_aliasblendcolor = SHELL_DOUBLE_COLOR;
else if ( color & (RF_SHELL_HALF_DAM) )
r_aliasblendcolor = SHELL_HALF_DAM_COLOR;
else if ( color & RF_SHELL_GREEN )
r_aliasblendcolor = SHELL_GREEN_COLOR;
else
r_aliasblendcolor = SHELL_WHITE_COLOR;
*/
if ( currententity->alpha > 0.33 )
d_pdrawspans = R_PolysetDrawSpansConstant8_66;
else
d_pdrawspans = R_PolysetDrawSpansConstant8_33;
}
else if ( currententity->flags & RF_TRANSLUCENT )
{
if ( currententity->alpha > 0.66 )
d_pdrawspans = R_PolysetDrawSpans8_Opaque;
else if ( currententity->alpha > 0.33 )
d_pdrawspans = R_PolysetDrawSpans8_66;
else
d_pdrawspans = R_PolysetDrawSpans8_33;
}
else
{
d_pdrawspans = R_PolysetDrawSpans8_Opaque;
}
/*
** compute this_frame and old_frame addresses
*/
R_AliasSetUpLerpData( s_pmdl, currententity->backlerp );
if (currententity->flags & RF_DEPTHHACK)
s_ziscale = (float)0x8000 * (float)0x10000 * 3.0;
else
s_ziscale = (float)0x8000 * (float)0x10000;
R_AliasPreparePoints ();
if ( ( currententity->flags & RF_WEAPONMODEL ) && ( r_lefthand->value == 1.0F ) )
{
aliasxscale = -aliasxscale;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -