Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

LinearInterpolatedAnimation.h

Go to the documentation of this file.
00001 // Copyright NVIDIA Corporation 2002-2004
00002 // TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
00003 // *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
00004 // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
00005 // AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
00006 // BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
00007 // WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
00008 // BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
00009 // ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
00010 // BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 
00011 
00012 #pragma once
00013 
00015 #include "nvsgcommon.h"
00016 
00017 #include  "nvsg/InterpolatedAnimation.h"
00018 
00019 #ifdef _DEBUG
00020 # ifndef new
00021 #  define new new(__FILE__, __LINE__)
00022 #  define _DEFINED_DBGNEW // restrict the 'new' macro to this header file only
00023 # endif
00024 #endif
00025 
00026 namespace nvsg
00027 {
00029 
00030   template<typename T> class LinearInterpolatedAnimation : public InterpolatedAnimation<T>
00031   {
00032     public:
00034 
00035       static const LinearInterpolatedAnimation<T> * create( void );
00036 
00038 
00039       static const LinearInterpolatedAnimation<T> * createFromBase( const InterpolatedAnimation<T> &rhs   
00040                                                                   );
00041 
00043 
00044       virtual const LinearInterpolatedAnimation<T> * clone( void ) const;
00045 
00047 
00049       virtual const T & operator[]( size_t i ) const;
00050 
00051     protected:
00053       NVSG_API LinearInterpolatedAnimation( void );
00054 
00056       NVSG_API LinearInterpolatedAnimation( const InterpolatedAnimation<T> &rhs );
00057 
00059       NVSG_API LinearInterpolatedAnimation( const LinearInterpolatedAnimation &rhs );
00060 
00062       virtual ~LinearInterpolatedAnimation( void );
00063   };
00064 
00065   template<typename T> 
00066   inline LinearInterpolatedAnimation<T>::~LinearInterpolatedAnimation(void)
00067   {
00068     __TRACE();
00069   }
00070 
00071   template<typename T>
00072   inline const LinearInterpolatedAnimation<T> * LinearInterpolatedAnimation<T>::create( void )
00073   {
00074     __TRACE();
00075     return( new LinearInterpolatedAnimation<T> );
00076   }
00077 
00078   template<typename T>
00079   inline const LinearInterpolatedAnimation<T> * LinearInterpolatedAnimation<T>::createFromBase( const InterpolatedAnimation<T> &rhs )
00080   {
00081     __TRACE();
00082     return( new LinearInterpolatedAnimation<T>( rhs ) );
00083   }
00084 
00085   template<typename T> 
00086   inline const LinearInterpolatedAnimation<T> * LinearInterpolatedAnimation<T>::clone( void ) const
00087   {
00088     __TRACE();
00089     return( new LinearInterpolatedAnimation<T>( *this ) );
00090   }
00091 
00092   template<typename T> 
00093   inline const T & LinearInterpolatedAnimation<T>::operator[]( size_t frame ) const
00094   {
00095     __TRACE();
00096     if ( frame != getCurrentFrame() )
00097     {
00098 #if defined( _DEBUG )
00099       __ASSERT( getFrame(0) == 0 );
00100       for ( size_t i=1 ; i<getNumberOfKeys() ; i++ )
00101       {
00102         __ASSERT( getFrame(i-1) < getFrame(i) );
00103       }
00104 #endif
00105       size_t key = getKey( (unsigned int) frame );
00106       if ( getFrame( key ) == frame ) //  frame is on a key => use this key frame
00107       {
00108         setCurrent( key );
00109       }
00110       else    //  frame is between it-1 and it
00111       {
00112         __ASSERT( key != 0 );
00113         setCurrent( (unsigned int) frame, lerp( (float)( frame - getFrame(key-1) ) / ( getFrame(key) - getFrame(key-1) ),
00114                                                 getValue( key-1 ), getValue( key ) ) );
00115       }
00116     }
00117     return( getCurrentValue() );
00118   }
00119 }
00120 
00121 #ifdef _DEFINED_DBGNEW
00122 # undef new
00123 #endif

Generated on Tue Mar 1 13:19:18 2005 for NVSGSDK by NVIDIA