// The following code is licensed under Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0)
// See: http://creativecommons.org/licenses/by-nc/3.0/
// Credit MUST be given to Saul Rennison and the CSProMod Team.
static ConVar cl_player_shadows("cl_player_shadows", "1", FCVAR_CHEAT, "Enable player shadows", true, 0, true, 1);
ShadowType_t C_BasePlayer::ShadowCastType()
{
if(cl_player_shadows.GetBool())
return SHADOWS_SIMPLE; // blob shadows
return SHADOWS_NONE;
}
bool C_BasePlayer::GetShadowCastDirection(Vector *pDirection, ShadowType_t shadowType ) const
{
// Force player shadows to be straight down
*pDirection = Vector(0, 0, -1);
return true;
}
bool C_BasePlayer::ShouldDraw()
{
return BaseClass::ShouldDraw();
}
static ConVar cl_legs("cl_legs", "1", FCVAR_CHEAT, "Enable or disable player leg rendering", true, 0, true, 1);
static ConVar cl_legs_origin_shift("cl_legs_origin_shift", "-16.5", FCVAR_CHEAT, "Amount in game units to shift the player model relative to the direction the player is facing");
static ConVar cl_legs_clip_height("cl_legs_clip_height", "0", FCVAR_CHEAT, "Amount in game units of the player model to render up to [0 = disable]", true, 0, false, 0);
const Vector& C_BasePlayer::GetRenderOrigin( void )
{
// If we're not observing this player, or if we're not drawing it at the
// moment then use the normal absolute origin.
// NOTE: the GetCurrentlyDrawingEntity check is here to make sure the
// shadow is rendered from the correct origin
if(!IsInEye() || view->GetCurrentlyDrawingEntity() != this)
return BaseClass::GetRenderOrigin();
// Get the forward vector
static Vector forward; // static because this method returns a reference
AngleVectors(GetRenderAngles(), &forward);
// Shift the render origin by a fixed amount
forward *= cl_legs_origin_shift.GetFloat();
forward += GetAbsOrigin();
return forward;
}
int C_BasePlayer::DrawModel( int flags )
{
// No need for clipping or render origin shifting if we aren't a local
// player
if(!IsInEye())
return BaseClass::DrawModel(flags);
// If we aren't drawing legs, return
if(!cl_legs.GetBool())
return 0;
CMatRenderContextPtr context(materials);
// Don't render above a certain height of the body
if(cl_legs_clip_height.GetInt() > 0)
{
context->SetHeightClipMode(MATERIAL_HEIGHTCLIPMODE_RENDER_BELOW_HEIGHT);
context->SetHeightClipZ(GetAbsOrigin().z+cl_legs_clip_height.GetFloat());
}
// Draw the model
int nDrawRes = BaseClass::DrawModel(flags);
// Remove height clipping
context->SetHeightClipMode(MATERIAL_HEIGHTCLIPMODE_DISABLE);
return nDrawRes;
}