📄 cg_players.c
字号:
ent.reType = RT_SPRITE;
ent.customShader = shader;
ent.radius = 10;
ent.renderfx = rf;
ent.shaderRGBA[0] = 255;
ent.shaderRGBA[1] = 255;
ent.shaderRGBA[2] = 255;
ent.shaderRGBA[3] = 255;
trap_R_AddRefEntityToScene( &ent );
}
/*
===============
CG_PlayerSprites
Float sprites over the player's head
===============
*/
static void CG_PlayerSprites( centity_t *cent ) {
int team;
if ( cent->currentState.eFlags & EF_CONNECTION ) {
CG_PlayerFloatSprite( cent, cgs.media.connectionShader );
return;
}
if ( cent->currentState.eFlags & EF_TALK ) {
CG_PlayerFloatSprite( cent, cgs.media.balloonShader );
return;
}
if ( cent->currentState.eFlags & EF_AWARD_IMPRESSIVE ) {
CG_PlayerFloatSprite( cent, cgs.media.medalImpressive );
return;
}
if ( cent->currentState.eFlags & EF_AWARD_EXCELLENT ) {
CG_PlayerFloatSprite( cent, cgs.media.medalExcellent );
return;
}
if ( cent->currentState.eFlags & EF_AWARD_GAUNTLET ) {
CG_PlayerFloatSprite( cent, cgs.media.medalGauntlet );
return;
}
if ( cent->currentState.eFlags & EF_AWARD_DEFEND ) {
CG_PlayerFloatSprite( cent, cgs.media.medalDefend );
return;
}
if ( cent->currentState.eFlags & EF_AWARD_ASSIST ) {
CG_PlayerFloatSprite( cent, cgs.media.medalAssist );
return;
}
if ( cent->currentState.eFlags & EF_AWARD_CAP ) {
CG_PlayerFloatSprite( cent, cgs.media.medalCapture );
return;
}
team = cgs.clientinfo[ cent->currentState.clientNum ].team;
if ( !(cent->currentState.eFlags & EF_DEAD) &&
cg.snap->ps.persistant[PERS_TEAM] == team &&
cgs.gametype >= GT_TEAM) {
if (cg_drawFriend.integer) {
CG_PlayerFloatSprite( cent, cgs.media.friendShader );
}
return;
}
}
/*
===============
CG_PlayerShadow
Returns the Z component of the surface being shadowed
should it return a full plane instead of a Z?
===============
*/
#define SHADOW_DISTANCE 128
static qboolean CG_PlayerShadow( centity_t *cent, float *shadowPlane ) {
vec3_t end, mins = {-15, -15, 0}, maxs = {15, 15, 2};
trace_t trace;
float alpha;
*shadowPlane = 0;
if ( cg_shadows.integer == 0 ) {
return qfalse;
}
// no shadows when invisible
if ( cent->currentState.powerups & ( 1 << PW_INVIS ) ) {
return qfalse;
}
// send a trace down from the player to the ground
VectorCopy( cent->lerpOrigin, end );
end[2] -= SHADOW_DISTANCE;
trap_CM_BoxTrace( &trace, cent->lerpOrigin, end, mins, maxs, 0, MASK_PLAYERSOLID );
// no shadow if too high
if ( trace.fraction == 1.0 || trace.startsolid || trace.allsolid ) {
return qfalse;
}
*shadowPlane = trace.endpos[2] + 1;
if ( cg_shadows.integer != 1 ) { // no mark for stencil or projection shadows
return qtrue;
}
// fade the shadow out with height
alpha = 1.0 - trace.fraction;
// bk0101022 - hack / FPE - bogus planes?
//assert( DotProduct( trace.plane.normal, trace.plane.normal ) != 0.0f )
// add the mark as a temporary, so it goes directly to the renderer
// without taking a spot in the cg_marks array
CG_ImpactMark( cgs.media.shadowMarkShader, trace.endpos, trace.plane.normal,
cent->pe.legs.yawAngle, alpha,alpha,alpha,1, qfalse, 24, qtrue );
return qtrue;
}
/*
===============
CG_PlayerSplash
Draw a mark at the water surface
===============
*/
static void CG_PlayerSplash( centity_t *cent ) {
vec3_t start, end;
trace_t trace;
int contents;
polyVert_t verts[4];
if ( !cg_shadows.integer ) {
return;
}
VectorCopy( cent->lerpOrigin, end );
end[2] -= 24;
// if the feet aren't in liquid, don't make a mark
// this won't handle moving water brushes, but they wouldn't draw right anyway...
contents = trap_CM_PointContents( end, 0 );
if ( !( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) ) {
return;
}
VectorCopy( cent->lerpOrigin, start );
start[2] += 32;
// if the head isn't out of liquid, don't make a mark
contents = trap_CM_PointContents( start, 0 );
if ( contents & ( CONTENTS_SOLID | CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
return;
}
// trace down to find the surface
trap_CM_BoxTrace( &trace, start, end, NULL, NULL, 0, ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) );
if ( trace.fraction == 1.0 ) {
return;
}
// create a mark polygon
VectorCopy( trace.endpos, verts[0].xyz );
verts[0].xyz[0] -= 32;
verts[0].xyz[1] -= 32;
verts[0].st[0] = 0;
verts[0].st[1] = 0;
verts[0].modulate[0] = 255;
verts[0].modulate[1] = 255;
verts[0].modulate[2] = 255;
verts[0].modulate[3] = 255;
VectorCopy( trace.endpos, verts[1].xyz );
verts[1].xyz[0] -= 32;
verts[1].xyz[1] += 32;
verts[1].st[0] = 0;
verts[1].st[1] = 1;
verts[1].modulate[0] = 255;
verts[1].modulate[1] = 255;
verts[1].modulate[2] = 255;
verts[1].modulate[3] = 255;
VectorCopy( trace.endpos, verts[2].xyz );
verts[2].xyz[0] += 32;
verts[2].xyz[1] += 32;
verts[2].st[0] = 1;
verts[2].st[1] = 1;
verts[2].modulate[0] = 255;
verts[2].modulate[1] = 255;
verts[2].modulate[2] = 255;
verts[2].modulate[3] = 255;
VectorCopy( trace.endpos, verts[3].xyz );
verts[3].xyz[0] += 32;
verts[3].xyz[1] -= 32;
verts[3].st[0] = 1;
verts[3].st[1] = 0;
verts[3].modulate[0] = 255;
verts[3].modulate[1] = 255;
verts[3].modulate[2] = 255;
verts[3].modulate[3] = 255;
trap_R_AddPolyToScene( cgs.media.wakeMarkShader, 4, verts );
}
/*
===============
CG_AddRefEntityWithPowerups
Adds a piece with modifications or duplications for powerups
Also called by CG_Missile for quad rockets, but nobody can tell...
===============
*/
void CG_AddRefEntityWithPowerups( refEntity_t *ent, entityState_t *state, int team ) {
if ( state->powerups & ( 1 << PW_INVIS ) ) {
ent->customShader = cgs.media.invisShader;
trap_R_AddRefEntityToScene( ent );
} else {
/*
if ( state->eFlags & EF_KAMIKAZE ) {
if (team == TEAM_BLUE)
ent->customShader = cgs.media.blueKamikazeShader;
else
ent->customShader = cgs.media.redKamikazeShader;
trap_R_AddRefEntityToScene( ent );
}
else {*/
trap_R_AddRefEntityToScene( ent );
//}
if ( state->powerups & ( 1 << PW_QUAD ) )
{
if (team == TEAM_RED)
ent->customShader = cgs.media.redQuadShader;
else
ent->customShader = cgs.media.quadShader;
trap_R_AddRefEntityToScene( ent );
}
if ( state->powerups & ( 1 << PW_REGEN ) ) {
if ( ( ( cg.time / 100 ) % 10 ) == 1 ) {
ent->customShader = cgs.media.regenShader;
trap_R_AddRefEntityToScene( ent );
}
}
if ( state->powerups & ( 1 << PW_BATTLESUIT ) ) {
ent->customShader = cgs.media.battleSuitShader;
trap_R_AddRefEntityToScene( ent );
}
}
}
/*
=================
CG_LightVerts
=================
*/
int CG_LightVerts( vec3_t normal, int numVerts, polyVert_t *verts )
{
int i, j;
float incoming;
vec3_t ambientLight;
vec3_t lightDir;
vec3_t directedLight;
trap_R_LightForPoint( verts[0].xyz, ambientLight, directedLight, lightDir );
for (i = 0; i < numVerts; i++) {
incoming = DotProduct (normal, lightDir);
if ( incoming <= 0 ) {
verts[i].modulate[0] = ambientLight[0];
verts[i].modulate[1] = ambientLight[1];
verts[i].modulate[2] = ambientLight[2];
verts[i].modulate[3] = 255;
continue;
}
j = ( ambientLight[0] + incoming * directedLight[0] );
if ( j > 255 ) {
j = 255;
}
verts[i].modulate[0] = j;
j = ( ambientLight[1] + incoming * directedLight[1] );
if ( j > 255 ) {
j = 255;
}
verts[i].modulate[1] = j;
j = ( ambientLight[2] + incoming * directedLight[2] );
if ( j > 255 ) {
j = 255;
}
verts[i].modulate[2] = j;
verts[i].modulate[3] = 255;
}
return qtrue;
}
/*
===============
CG_Player
===============
*/
void CG_Player( centity_t *cent ) {
clientInfo_t *ci;
refEntity_t legs;
refEntity_t torso;
refEntity_t head;
int clientNum;
int renderfx;
qboolean shadow;
float shadowPlane;
#ifdef MISSIONPACK
refEntity_t skull;
refEntity_t powerup;
int t;
float c;
float angle;
vec3_t dir, angles;
#endif
// the client number is stored in clientNum. It can't be derived
// from the entity number, because a single client may have
// multiple corpses on the level using the same clientinfo
clientNum = cent->currentState.clientNum;
if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) {
CG_Error( "Bad clientNum on player entity");
}
ci = &cgs.clientinfo[ clientNum ];
// it is possible to see corpses from disconnected players that may
// not have valid clientinfo
if ( !ci->infoValid ) {
return;
}
// get the player model information
renderfx = 0;
if ( cent->currentState.number == cg.snap->ps.clientNum) {
if (!cg.renderingThirdPerson) {
renderfx = RF_THIRD_PERSON; // only draw in mirrors
} else {
if (cg_cameraMode.integer) {
return;
}
}
}
memset( &legs, 0, sizeof(legs) );
memset( &torso, 0, sizeof(torso) );
memset( &head, 0, sizeof(head) );
// get the rotation information
CG_PlayerAngles( cent, legs.axis, torso.axis, head.axis );
// get the animation state (after rotation, to allow feet shuffle)
CG_PlayerAnimation( cent, &legs.oldframe, &legs.frame, &legs.backlerp,
&torso.oldframe, &torso.frame, &torso.backlerp );
// add the talk baloon or disconnect icon
CG_PlayerSprites( cent );
// add the shadow
shadow = CG_PlayerShadow( cent, &shadowPlane );
// add a water splash if partially in and out of water
CG_PlayerSplash( cent );
if ( cg_shadows.integer == 3 && shadow ) {
renderfx |= RF_SHADOW_PLANE;
}
renderfx |= RF_LIGHTING_ORIGIN; // use the same origin for all
#ifdef MISSIONPACK
if( cgs.gametype == GT_HARVESTER ) {
CG_PlayerTokens( cent, renderfx );
}
#endif
//
// add the legs
//
legs.hModel = ci->legsModel;
legs.customSkin = ci->legsSkin;
VectorCopy( cent->lerpOrigin, legs.origin );
VectorCopy( cent->lerpOrigin, legs.lightingOrigin );
legs.shadowPlane = shadowPlane;
legs.renderfx = renderfx;
VectorCopy (legs.origin, legs.oldorigin); // don't positionally lerp at all
CG_AddRefEntityWithPowerups( &legs, ¢->currentState, ci->team );
// if the model failed, allow the default nullmodel to be displayed
if (!legs.hModel) {
return;
}
//
// add the torso
//
torso.hModel = ci->torsoModel;
if (!torso.hModel) {
return;
}
torso.customSkin = ci->torsoSkin;
VectorCopy( cent->lerpOrigin, torso.lightingOrigin );
CG_PositionRotatedEntityOnTag( &torso, &legs, ci->legsModel, "tag_torso");
torso.shadowPlane = shadowPlane;
torso.renderfx = renderfx;
CG_AddRefEntityWithPowerups( &torso, ¢->currentState, ci->team );
#ifdef MISSIONPACK
if ( cent->currentState.eFlags & EF_KAMIKAZE ) {
memset( &skull, 0, sizeof(skull) );
VectorCopy( cent->lerpOrigin, skull.lightingOrigin );
skull.shadowPlane = shadowPlane;
skull.renderfx = renderfx;
if ( cent->currentState.eFlags & EF_DEAD ) {
// one skull bobbing above the dead body
angle = ((cg.time / 7) & 255) * (M_PI * 2) / 255;
if (angle > M_PI * 2)
angle -= (float)M_PI * 2;
dir[0] = sin(angle) * 20;
dir[1] = cos(angle) * 20;
angle = ((cg.time / 4) & 255) * (M_PI * 2) / 255;
dir[2] = 15 + sin(angle) * 8;
VectorAdd(torso.origin, dir, skull.origin);
dir[2] = 0;
VectorCopy(dir, skull.axis[1]);
VectorNormalize(skull.axis[1]);
VectorSet(skull.axis[2], 0, 0, 1);
CrossProduct(skull.axis[1], skull.axis[2], skull.axis[0]);
skull.hModel = cgs.media.kamikazeHeadModel;
trap_R_AddRefEntityToScene( &skull );
skull.hModel = cgs.media.kamikazeHeadTrail;
trap_R_AddRefEntityToScene( &skull );
}
else {
// three skulls spinning around the player
angle = ((cg.time / 4) & 255) * (M_PI * 2) / 255;
dir[0] = cos(angle) * 20;
dir[1] = sin(angle) * 20;
dir[2] = cos(angle) * 20;
VectorAdd(torso.origin, dir, skull.origin);
angles[0] = sin(angle) * 30;
angles[1] = (angle * 180 / M_P
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -