# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

track.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_TRACK_H
00027 #define NL_TRACK_H
00028 
00029 #include "nel/misc/stream.h"
00030 #include "nel/misc/types_nl.h"
00031 #include "nel/misc/common.h"
00032 
00033 #include "nel/3d/animation_time.h"
00034 #include "nel/3d/u_track.h"
00035 
00036 #include "3d/animated_value.h"
00037 
00038 
00039 namespace NL3D 
00040 {
00041 
00042 
00043 using NLMISC::CQuat;
00044 using NLMISC::CVector;
00045 
00046 
00047 // ***************************************************************************
00058 class ITrack : public NLMISC::IStreamable, public UTrack
00059 {
00060 public:
00064         virtual ~ITrack() {};
00065 
00072         virtual void eval (const TAnimationTime& date)=0;
00073 
00079         virtual const IAnimatedValue& getValue () const=0;
00080 
00085         virtual bool getLoopMode() const=0;
00086 
00088         // @{
00089 
00090         virtual bool interpolate (TAnimationTime time, float& res);
00091         virtual bool interpolate (TAnimationTime time, sint32& res);
00092         virtual bool interpolate (TAnimationTime time, NLMISC::CRGBA& res);
00093         virtual bool interpolate (TAnimationTime time, NLMISC::CVector& res);
00094         virtual bool interpolate (TAnimationTime time, NLMISC::CQuat& res);
00095         virtual bool interpolate (TAnimationTime time, std::string& res);
00096         virtual bool interpolate (TAnimationTime time, bool& res);
00097 
00098         // @}
00099 };
00100 
00101 
00102 // ***************************************************************************
00112 class ITrackDefault : public ITrack
00113 {
00114 public:
00116         virtual void eval (const TAnimationTime& date) 
00117         {}
00118         TAnimationTime getBeginTime () const
00119         {
00120                 return 0.f;
00121         }
00122         TAnimationTime getEndTime () const
00123         {
00124                 return 0.f;
00125         }
00126         virtual bool getLoopMode() const {return true;}
00127 };
00128 
00129 
00130 
00131 // ***************************************************************************
00132 // ***************************************************************************
00133 // TrackDefault implemenations.
00134 // ***************************************************************************
00135 // ***************************************************************************
00136 
00137 
00138 
00148 template<class T>
00149 class CTrackDefaultBlendable : public ITrackDefault
00150 {
00151 public:
00152 
00153         CTrackDefaultBlendable()
00154         {
00155         }
00156         CTrackDefaultBlendable(const T &val)
00157         {
00158                 _Value.Value= val;
00159         }
00160 
00162         void    setValue(const T &val)
00163         {
00164                 _Value.Value= val;
00165         }
00166 
00167 
00169         virtual const IAnimatedValue& getValue () const
00170         {
00171                 return _Value;
00172         }
00173 
00175         virtual void serial (NLMISC::IStream& f) throw (NLMISC::EStream)
00176         {
00177                 // Serial version
00178                 (void)f.serialVersion (0);
00179 
00180                 // Serial the value
00181                 f.serial (_Value.Value);
00182         }
00183 private:
00184 
00185         // The default value
00186         CAnimatedValueBlendable<T>      _Value;
00187 };
00188 
00189 
00199 template<class T>
00200 class CTrackDefaultNotBlendable : public ITrackDefault
00201 {
00202 public:
00203 
00204         CTrackDefaultNotBlendable()
00205         {
00206         }
00207         CTrackDefaultNotBlendable(const T &val)
00208         {
00209                 _Value.Value= val;
00210         }
00211 
00213         void    setValue(const T &val)
00214         {
00215                 _Value.Value= val;
00216         }
00217 
00218 
00220         virtual const IAnimatedValue& getValue () const
00221         {
00222                 return _Value;
00223         }
00224 
00226         virtual void serial (NLMISC::IStream& f) throw (NLMISC::EStream)
00227         {
00228                 // Serial version
00229                 (void)f.serialVersion (0);
00230 
00231                 // Serial the value
00232                 f.serial (_Value.Value);
00233         }
00234 private:
00235 
00236         // The default value
00237         CAnimatedValueNotBlendable<T>   _Value;
00238 };
00239 
00240 
00241 #define NL3D_TRACKDEF_CTOR(_Son, _Father, _T)   \
00242         _Son() {}                                                                       \
00243         _Son(const _T &v) : _Father<_T>(v) {}
00244 
00245 
00246 // Predefined types
00247 class CTrackDefaultFloat : public CTrackDefaultBlendable<float>
00248 {
00249 public:
00250         NL3D_TRACKDEF_CTOR(CTrackDefaultFloat, CTrackDefaultBlendable, float);
00251         NLMISC_DECLARE_CLASS (CTrackDefaultFloat);
00252 };
00253 class CTrackDefaultVector : public CTrackDefaultBlendable<CVector>
00254 {
00255 public:
00256         NL3D_TRACKDEF_CTOR(CTrackDefaultVector, CTrackDefaultBlendable, CVector);
00257         NLMISC_DECLARE_CLASS (CTrackDefaultVector);
00258 };
00259 class CTrackDefaultQuat : public CTrackDefaultBlendable<CQuat>
00260 {
00261 public:
00262         NL3D_TRACKDEF_CTOR(CTrackDefaultQuat, CTrackDefaultBlendable, CQuat);
00263         NLMISC_DECLARE_CLASS (CTrackDefaultQuat);
00264 };
00265 class CTrackDefaultInt : public CTrackDefaultBlendable<sint32>
00266 {
00267 public:
00268         NL3D_TRACKDEF_CTOR(CTrackDefaultInt, CTrackDefaultBlendable, sint32);
00269         NLMISC_DECLARE_CLASS (CTrackDefaultInt);
00270 };
00271 
00272 class CTrackDefaultRGBA : public CTrackDefaultBlendable<NLMISC::CRGBA>
00273 {
00274 public:
00275         NL3D_TRACKDEF_CTOR(CTrackDefaultRGBA, CTrackDefaultBlendable, NLMISC::CRGBA);
00276         NLMISC_DECLARE_CLASS (CTrackDefaultRGBA);
00277 };
00278 
00279 
00280 class CTrackDefaultString : public CTrackDefaultNotBlendable<std::string>
00281 {
00282 public:
00283         NL3D_TRACKDEF_CTOR(CTrackDefaultString, CTrackDefaultNotBlendable, std::string);
00284         NLMISC_DECLARE_CLASS (CTrackDefaultString);
00285 };
00286 class CTrackDefaultBool : public CTrackDefaultNotBlendable<bool>
00287 {
00288 public:
00289         NL3D_TRACKDEF_CTOR(CTrackDefaultBool, CTrackDefaultNotBlendable, bool);
00290         NLMISC_DECLARE_CLASS (CTrackDefaultBool);
00291 };
00292 
00293 } // NL3D
00294 
00295 
00296 #endif // NL_TRACK_H
00297 
00298 /* End of track.h */