diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /sp/src/game/shared/apparent_velocity_helper.h | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'sp/src/game/shared/apparent_velocity_helper.h')
| -rw-r--r-- | sp/src/game/shared/apparent_velocity_helper.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/sp/src/game/shared/apparent_velocity_helper.h b/sp/src/game/shared/apparent_velocity_helper.h new file mode 100644 index 00000000..ac785c13 --- /dev/null +++ b/sp/src/game/shared/apparent_velocity_helper.h @@ -0,0 +1,74 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//=============================================================================//
+
+#ifndef APPARENT_VELOCITY_HELPER_H
+#define APPARENT_VELOCITY_HELPER_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+
+inline float CalcDistance( float x, float y )
+{
+ return x - y;
+}
+
+inline float CalcDistance( const Vector &a, const Vector &b )
+{
+ return a.DistTo( b );
+}
+
+
+template<class T>
+class CDefaultCalcDistance
+{
+public:
+ static inline float CalcDistance( const T &a, const T &b )
+ {
+ return ::CalcDistance( a, b );
+ }
+};
+
+class CCalcDistance2D
+{
+public:
+ static inline float CalcDistance( const Vector &a, const Vector &b )
+ {
+ return (a-b).Length2D();
+ }
+};
+
+
+template< class T, class Functor=CDefaultCalcDistance<T> >
+class CApparentVelocity
+{
+public:
+ CApparentVelocity()
+ {
+ m_LastTime = -1;
+ }
+
+ float AddSample( float time, T value )
+ {
+ float flRet = 0;
+ if ( m_LastTime != -1 )
+ {
+ flRet = Functor::CalcDistance(value, m_LastValue) / (time - m_LastTime);
+ }
+
+ m_LastTime = time;
+ m_LastValue = value;
+
+ return flRet;
+ }
+
+private:
+ T m_LastValue;
+ float m_LastTime;
+};
+
+
+#endif // APPARENT_VELOCITY_HELPER_H
|