Team Fortress 2 Source Code as on 22/4/2020
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.

108 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef C_IMPACT_EFFECTS_H
  7. #define C_IMPACT_EFFECTS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier0/memdbgon.h"
  12. //-----------------------------------------------------------------------------
  13. // Purpose: DustParticle emitter
  14. //-----------------------------------------------------------------------------
  15. class CDustParticle : public CSimpleEmitter
  16. {
  17. public:
  18. CDustParticle( const char *pDebugName ) : CSimpleEmitter( pDebugName ) {}
  19. //Create
  20. static CDustParticle *Create( const char *pDebugName="dust" )
  21. {
  22. return new CDustParticle( pDebugName );
  23. }
  24. //Roll
  25. virtual float UpdateRoll( SimpleParticle *pParticle, float timeDelta )
  26. {
  27. pParticle->m_flRoll += pParticle->m_flRollDelta * timeDelta;
  28. pParticle->m_flRollDelta += pParticle->m_flRollDelta * ( timeDelta * -8.0f );
  29. #ifdef _XBOX
  30. //Cap the minimum roll
  31. if ( fabs( pParticle->m_flRollDelta ) < 0.1f )
  32. {
  33. pParticle->m_flRollDelta = ( pParticle->m_flRollDelta > 0.0f ) ? 0.1f : -0.1f;
  34. }
  35. #else
  36. if ( fabs( pParticle->m_flRollDelta ) < 0.5f )
  37. {
  38. pParticle->m_flRollDelta = ( pParticle->m_flRollDelta > 0.0f ) ? 0.5f : -0.5f;
  39. }
  40. #endif // _XBOX
  41. return pParticle->m_flRoll;
  42. }
  43. //Velocity
  44. virtual void UpdateVelocity( SimpleParticle *pParticle, float timeDelta )
  45. {
  46. Vector saveVelocity = pParticle->m_vecVelocity;
  47. //Decellerate
  48. static float dtime;
  49. static float decay;
  50. if ( dtime != timeDelta )
  51. {
  52. dtime = timeDelta;
  53. float expected = 0.5;
  54. decay = exp( log( 0.0001f ) * dtime / expected );
  55. }
  56. pParticle->m_vecVelocity = pParticle->m_vecVelocity * decay;
  57. #ifdef _XBOX
  58. //Cap the minimum speed
  59. if ( pParticle->m_vecVelocity.LengthSqr() < (8.0f*8.0f) )
  60. {
  61. VectorNormalize( saveVelocity );
  62. pParticle->m_vecVelocity = saveVelocity * 8.0f;
  63. }
  64. #else
  65. if ( pParticle->m_vecVelocity.LengthSqr() < (32.0f*32.0f) )
  66. {
  67. VectorNormalize( saveVelocity );
  68. pParticle->m_vecVelocity = saveVelocity * 32.0f;
  69. }
  70. #endif // _XBOX
  71. }
  72. //Alpha
  73. virtual float UpdateAlpha( const SimpleParticle *pParticle )
  74. {
  75. float tLifetime = pParticle->m_flLifetime / pParticle->m_flDieTime;
  76. float ramp = 1.0f - tLifetime;
  77. //Non-linear fade
  78. if ( ramp < 0.75f )
  79. ramp *= ramp;
  80. return ramp;
  81. }
  82. private:
  83. CDustParticle( const CDustParticle & ); // not defined, not accessible
  84. };
  85. void GetColorForSurface( trace_t *trace, Vector *color );
  86. #include "tier0/memdbgoff.h"
  87. #endif // C_IMPACT_EFFECTS_H