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.

96 lines
2.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "simple_keys.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. //-----------------------------------------------------------------------------
  11. // Simple key interpolations
  12. //-----------------------------------------------------------------------------
  13. //-----------------------------------------------------------------------------
  14. // Purpose:
  15. // Input : &out -
  16. // t -
  17. // &start -
  18. // &end -
  19. //-----------------------------------------------------------------------------
  20. void CSimpleKeyInterp::Interp( Vector &out, float t, const CSimpleKeyInterp &start, const CSimpleKeyInterp &end )
  21. {
  22. float delta = end.GetTime() - start.GetTime();
  23. t = clamp( t-start.GetTime(), 0, delta );
  24. float unitT = (delta > 0) ? (t / delta) : 1;
  25. switch( end.m_interp )
  26. {
  27. case KEY_SPLINE:
  28. unitT = SimpleSpline( unitT );
  29. break;
  30. case KEY_ACCELERATE:
  31. unitT *= unitT;
  32. break;
  33. case KEY_DECELERATE:
  34. unitT = sqrt(unitT);
  35. break;
  36. default:
  37. case KEY_LINEAR:
  38. //unitT = unitT;
  39. break;
  40. }
  41. out = (1-unitT) * ((Vector)start) + unitT * ((Vector)end);
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Simple key list
  45. //-----------------------------------------------------------------------------
  46. //-----------------------------------------------------------------------------
  47. // Purpose:
  48. // Input : &key -
  49. // Output : int
  50. //-----------------------------------------------------------------------------
  51. int CSimpleKeyList::Insert( const CSimpleKeyInterp &key )
  52. {
  53. for ( int i = 0; i < m_list.Count(); i++ )
  54. {
  55. if ( key.GetTime() < m_list[i].GetTime() )
  56. return m_list.InsertBefore( i, key );
  57. }
  58. return m_list.AddToTail( key );
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. // Input : &out -
  63. // t -
  64. // Output : Returns true on success, false on failure.
  65. //-----------------------------------------------------------------------------
  66. bool CSimpleKeyList::Interp( Vector &out, float t )
  67. {
  68. int startIndex = -1;
  69. out.Init();
  70. for ( int i = 0; i < m_list.Count(); i++ )
  71. {
  72. if ( t < m_list[i].GetTime() )
  73. {
  74. // before start
  75. if ( startIndex < 0 )
  76. return false;
  77. CSimpleKeyInterp::Interp( out, t, m_list[startIndex], m_list[i] );
  78. return true;
  79. }
  80. startIndex = i;
  81. }
  82. // past end
  83. return false;
  84. }