Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Saul Rennison

By: a guest on Apr 24th, 2011  |  syntax: C++  |  size: 2.63 KB  |  views: 1,262  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // The following code is licensed under Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0)
  2. // See: http://creativecommons.org/licenses/by-nc/3.0/
  3. // Credit MUST be given to Saul Rennison and the CSProMod Team.
  4.  
  5. static ConVar cl_player_shadows("cl_player_shadows", "1", FCVAR_CHEAT, "Enable player shadows", true, 0, true, 1);
  6.  
  7. ShadowType_t C_BasePlayer::ShadowCastType()
  8. {
  9.         if(cl_player_shadows.GetBool())
  10.                 return SHADOWS_SIMPLE; // blob shadows
  11.        
  12.         return SHADOWS_NONE;
  13. }
  14.  
  15. bool C_BasePlayer::GetShadowCastDirection(Vector *pDirection, ShadowType_t shadowType ) const
  16. {
  17.         // Force player shadows to be straight down
  18.         *pDirection = Vector(0, 0, -1);
  19.         return true;
  20. }
  21.  
  22. bool C_BasePlayer::ShouldDraw()
  23. {
  24.         return BaseClass::ShouldDraw();
  25. }
  26.  
  27. static ConVar cl_legs("cl_legs", "1", FCVAR_CHEAT, "Enable or disable player leg rendering", true, 0, true, 1);
  28. 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");
  29. 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);
  30.  
  31. const Vector& C_BasePlayer::GetRenderOrigin( void )
  32. {
  33.         // If we're not observing this player, or if we're not drawing it at the
  34.         // moment then use the normal absolute origin.
  35.         // NOTE: the GetCurrentlyDrawingEntity check is here to make sure the
  36.         // shadow is rendered from the correct origin
  37.         if(!IsInEye() || view->GetCurrentlyDrawingEntity() != this)
  38.                 return BaseClass::GetRenderOrigin();
  39.  
  40.         // Get the forward vector
  41.         static Vector forward; // static because this method returns a reference
  42.         AngleVectors(GetRenderAngles(), &forward);
  43.  
  44.         // Shift the render origin by a fixed amount
  45.         forward *= cl_legs_origin_shift.GetFloat();
  46.         forward += GetAbsOrigin();
  47.  
  48.         return forward;
  49. }
  50.  
  51. int C_BasePlayer::DrawModel( int flags )
  52. {
  53.         // No need for clipping or render origin shifting if we aren't a local
  54.         // player
  55.         if(!IsInEye())
  56.                 return BaseClass::DrawModel(flags);
  57.  
  58.         // If we aren't drawing legs, return
  59.         if(!cl_legs.GetBool())
  60.                 return 0;
  61.  
  62.         CMatRenderContextPtr context(materials);
  63.  
  64.         // Don't render above a certain height of the body
  65.         if(cl_legs_clip_height.GetInt() > 0)
  66.         {
  67.                 context->SetHeightClipMode(MATERIAL_HEIGHTCLIPMODE_RENDER_BELOW_HEIGHT);
  68.                 context->SetHeightClipZ(GetAbsOrigin().z+cl_legs_clip_height.GetFloat());
  69.         }
  70.  
  71.         // Draw the model
  72.         int nDrawRes = BaseClass::DrawModel(flags);
  73.        
  74.         // Remove height clipping
  75.         context->SetHeightClipMode(MATERIAL_HEIGHTCLIPMODE_DISABLE);
  76.  
  77.         return nDrawRes;
  78. }