Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.2 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #include "cbase.h"
  9. #include "view.h"
  10. #include "model_types.h"
  11. #include "ivrenderview.h"
  12. #include "engine/ivmodelinfo.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. #define VIEWER_PADDING 80.0f
  16. class C_FuncAreaPortalWindow : public C_BaseEntity
  17. {
  18. public:
  19. DECLARE_CLIENTCLASS();
  20. DECLARE_CLASS( C_FuncAreaPortalWindow, C_BaseEntity );
  21. // Overrides.
  22. public:
  23. RenderableTranslucencyType_t ComputeTranslucencyType( void );
  24. virtual int DrawModel( int flags, const RenderableInstance_t &instance );
  25. virtual bool ShouldReceiveProjectedTextures( int flags );
  26. private:
  27. float GetDistanceBlend();
  28. public:
  29. float m_flFadeStartDist; // Distance at which it starts fading (when <= this, alpha=m_flTranslucencyLimit).
  30. float m_flFadeDist; // Distance at which it becomes solid.
  31. // 0-1 value - minimum translucency it's allowed to get to.
  32. float m_flTranslucencyLimit;
  33. int m_iBackgroundModelIndex;
  34. };
  35. IMPLEMENT_CLIENTCLASS_DT( C_FuncAreaPortalWindow, DT_FuncAreaPortalWindow, CFuncAreaPortalWindow )
  36. RecvPropFloat( RECVINFO( m_flFadeStartDist ) ),
  37. RecvPropFloat( RECVINFO( m_flFadeDist ) ),
  38. RecvPropFloat( RECVINFO( m_flTranslucencyLimit ) ),
  39. RecvPropInt( RECVINFO( m_iBackgroundModelIndex ) )
  40. END_RECV_TABLE()
  41. RenderableTranslucencyType_t C_FuncAreaPortalWindow::ComputeTranslucencyType( void )
  42. {
  43. return RENDERABLE_IS_TRANSLUCENT;
  44. }
  45. int C_FuncAreaPortalWindow::DrawModel( int flags, const RenderableInstance_t &instance )
  46. {
  47. if ( !m_bReadyToDraw )
  48. return 0;
  49. if( !GetModel() )
  50. return 0;
  51. // Make sure we're a brush model.
  52. int modelType = modelinfo->GetModelType( GetModel() );
  53. if( modelType != mod_brush )
  54. return 0;
  55. // Draw the fading version.
  56. float flBlendAlpha = GetDistanceBlend();
  57. if ( flBlendAlpha == 0.0f )
  58. return 0;
  59. render->SetBlend( flBlendAlpha );
  60. DrawBrushModelMode_t mode = DBM_DRAW_ALL;
  61. if ( flags & STUDIO_TWOPASS )
  62. {
  63. mode = ( flags & STUDIO_TRANSPARENCY ) ? DBM_DRAW_TRANSLUCENT_ONLY : DBM_DRAW_OPAQUE_ONLY;
  64. }
  65. render->DrawBrushModelEx(
  66. this,
  67. (model_t *)GetModel(),
  68. GetAbsOrigin(),
  69. GetAbsAngles(),
  70. mode );
  71. // Draw the optional foreground model next.
  72. // Only use the alpha in the texture from the thing in the front.
  73. if (m_iBackgroundModelIndex >= 0)
  74. {
  75. render->SetBlend( 1 );
  76. model_t *pBackground = ( model_t * )modelinfo->GetModel( m_iBackgroundModelIndex );
  77. if( pBackground && modelinfo->GetModelType( pBackground ) == mod_brush )
  78. {
  79. render->DrawBrushModelEx(
  80. this,
  81. pBackground,
  82. GetAbsOrigin(),
  83. GetAbsAngles(),
  84. mode );
  85. }
  86. }
  87. return 1;
  88. }
  89. float C_FuncAreaPortalWindow::GetDistanceBlend()
  90. {
  91. // Get the viewer's distance to us.
  92. float flDist = CollisionProp()->CalcDistanceFromPoint( CurrentViewOrigin() );
  93. C_BasePlayer *local = C_BasePlayer::GetLocalPlayer();
  94. if ( local )
  95. {
  96. flDist *= local->GetFOVDistanceAdjustFactor();
  97. }
  98. return RemapValClamped( flDist, m_flFadeStartDist, m_flFadeDist, m_flTranslucencyLimit, 1 );
  99. }
  100. bool C_FuncAreaPortalWindow::ShouldReceiveProjectedTextures( int flags )
  101. {
  102. return false;
  103. }