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.

97 lines
2.5 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "fx_interpvalue.h"
  8. // NOTE: This has to be the last file included!
  9. #include "tier0/memdbgon.h"
  10. CInterpolatedValue::CInterpolatedValue( void ) : m_flStartTime( 0.0f ), m_flEndTime( 0.0f ), m_flStartValue( 0.0f ), m_flEndValue( 0.0f ), m_nInterpType( INTERP_LINEAR )
  11. {
  12. }
  13. CInterpolatedValue::CInterpolatedValue( float startTime, float endTime, float startValue, float endValue, InterpType_t type ) :
  14. m_flStartTime( startTime ), m_flEndTime( endTime ), m_flStartValue( startValue ), m_flEndValue( endValue ), m_nInterpType( type )
  15. {
  16. }
  17. void CInterpolatedValue::SetTime( float start, float end )
  18. {
  19. m_flStartTime = start; m_flEndTime = end;
  20. }
  21. void CInterpolatedValue::SetRange( float start, float end )
  22. {
  23. m_flStartValue = start; m_flEndValue = end;
  24. }
  25. void CInterpolatedValue::SetType( InterpType_t type )
  26. {
  27. m_nInterpType = type;
  28. }
  29. // Set the value with no range
  30. void CInterpolatedValue::SetAbsolute( float value )
  31. {
  32. m_flStartValue = m_flEndValue = value;
  33. m_flStartTime = m_flEndTime = gpGlobals->curtime;
  34. m_nInterpType = INTERP_LINEAR;
  35. }
  36. // Set the value with range and time supplied
  37. void CInterpolatedValue::Init( float startValue, float endValue, float dt, InterpType_t type /*= INTERP_LINEAR*/ )
  38. {
  39. if ( dt <= 0.0f )
  40. {
  41. SetAbsolute( endValue );
  42. return;
  43. }
  44. SetTime( gpGlobals->curtime, gpGlobals->curtime + dt );
  45. SetRange( startValue, endValue );
  46. SetType( type );
  47. }
  48. // Start from the current value and move towards the end value
  49. void CInterpolatedValue::InitFromCurrent( float endValue, float dt, InterpType_t type /*= INTERP_LINEAR*/ )
  50. {
  51. Init( Interp( gpGlobals->curtime ), endValue, dt, type );
  52. }
  53. // Find our interpolated value at the given point in time
  54. float CInterpolatedValue::Interp( float curTime )
  55. {
  56. switch( m_nInterpType )
  57. {
  58. case INTERP_LINEAR:
  59. {
  60. if ( curTime >= m_flEndTime )
  61. return m_flEndValue;
  62. if ( curTime <= m_flStartTime )
  63. return m_flStartValue;
  64. return RemapVal( curTime, m_flStartTime, m_flEndTime, m_flStartValue, m_flEndValue );
  65. }
  66. case INTERP_SPLINE:
  67. {
  68. if ( curTime >= m_flEndTime )
  69. return m_flEndValue;
  70. if ( curTime <= m_flStartTime )
  71. return m_flStartValue;
  72. return SimpleSplineRemapVal( curTime, m_flStartTime, m_flEndTime, m_flStartValue, m_flEndValue );
  73. }
  74. }
  75. // NOTENOTE: You managed to pass in a bogus interpolation type!
  76. Assert(0);
  77. return -1.0f;
  78. }