# 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  

ps_float.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_PS_FLOAT_H
00027 #define NL_PS_FLOAT_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "3d/ps_attrib_maker_template.h"
00031 #include "3d/ps_attrib_maker_bin_op.h"
00032 #include "nel/3d/animation_time.h"
00033 #include <algorithm>
00034 #include <nel/misc/vector_h.h>
00035 
00036 namespace NL3D {
00037 
00038 
00039 const char *CPSAttribMaker<float>::getType() { return "float"; }
00040 
00043 
00044 class CPSFloatBlender : public CPSValueBlender<float>
00045 {
00046 public:
00047         NLMISC_DECLARE_CLASS(CPSFloatBlender);
00048         CPSFloatBlender(float startFloat = 0.1f , float endFloat = 1.f, float nbCycles = 1.0f) : CPSValueBlender<float>(nbCycles)
00049         {
00050                 _F.setValues(startFloat, endFloat);
00051         }
00052         CPSAttribMakerBase *clone() const { return new CPSFloatBlender(*this); }
00053         // F is serialized by base classes...
00054 
00055 };
00056 
00057 
00059 class CPSFloatGradient : public CPSValueGradient<float>
00060 {
00061 public:
00062         NLMISC_DECLARE_CLASS(CPSFloatGradient);
00063 
00070         CPSFloatGradient(const float *floatTab = CPSFloatGradient::_DefaultGradient
00071                                                 , uint32 nbValues = 2, uint32 nbStages = 16, float nbCycles = 1.0f);
00072 
00073         
00074         static float _DefaultGradient[];
00075         CPSAttribMakerBase *clone() const { return new CPSFloatGradient(*this); }
00076         // F is serialized by base classes...   
00077 };
00078 
00083 class CPSFloatMemory : public CPSAttribMakerMemory<float>
00084 {
00085 public:
00086         CPSFloatMemory() { setDefaultValue(0.f); }
00087         NLMISC_DECLARE_CLASS(CPSFloatMemory);
00088         CPSAttribMakerBase *clone() const { return new CPSFloatMemory(*this); }
00089 
00090 };
00091 
00095 class CPSFloatBinOp : public CPSAttribMakerBinOp<float>
00096 {
00097 public:
00098         NLMISC_DECLARE_CLASS(CPSFloatBinOp);
00099         CPSAttribMakerBase *clone() const { return new CPSFloatBinOp(*this); }
00100 };
00101 
00103 class CPSFloatCurveFunctor
00104 {
00105         public:
00106                 struct CCtrlPoint
00107                 {
00108                         CCtrlPoint() {}
00109                         CCtrlPoint(float date, float value) : Date(date), Value(value) { nlassert(Date >= 0 && Date <= 1); }
00110                         float Date;
00111                         float Value;
00112                         void serial(NLMISC::IStream &f) throw(NLMISC::EStream)
00113                         {
00114                                 f.serial(Date, Value);
00115                         }
00116                 };
00117                 
00119                 CPSFloatCurveFunctor();
00120 
00124                 void                                                    addControlPoint(const CCtrlPoint &ctrlPoint);
00125 
00127                 uint                                                    getNumCtrlPoints(void) const { return _CtrlPoints.size(); }                     
00128 
00132                 const CCtrlPoint                                &getControlPoint(uint index) const;
00133 
00135                 void                                                    setCtrlPoint(uint index, const CCtrlPoint &ctrlPoint);
00136 
00138                 void                                                    removeCtrlPoint(uint index);
00139 
00141                 void                                                    setNumSamples(uint32 numSamples);
00142 
00144                 uint32                                                  getNumSamples(void) const { return _NumSamples; }
00145 
00147                 void                                                    enableSmoothing(bool enable = true);
00148 
00150                 bool                                                    hasSmoothing(void) const                        { return _Smoothing;}
00151 
00157                 #ifdef NL_OS_WINDOWS
00158                         __forceinline
00159                 #endif
00160                 float operator()(TAnimationTime time) const
00161                 {
00162                         return _Tab[OptFastFloor(time * _NumSamples)];
00163                 }
00164 
00166                 float                                                   getValue(float date) const;
00167 
00169                 void serial(NLMISC::IStream &f) throw(NLMISC::EStream);
00170 
00171         protected:              
00173                 float getSlope(uint index) const ;
00175                 void                                            sortPoints(void);       
00177                 void                                            updateTab(void);        
00178                 std::vector<CCtrlPoint>         _CtrlPoints;
00179                 uint32                                          _NumSamples;
00180                 std::vector<float>                      _Tab; // sampled version of the curve           
00181                 bool                                            _Smoothing;
00182 };
00183 
00184 
00185 inline bool operator<(const CPSFloatCurveFunctor::CCtrlPoint &lhs, const CPSFloatCurveFunctor::CCtrlPoint &rhs)
00186 {
00187         return lhs.Date < rhs.Date;
00188 }
00189 
00190 
00191 class CPSFloatCurve : public CPSAttribMakerT<float, CPSFloatCurveFunctor>
00192 {
00193 public:
00194         CPSFloatCurve() : CPSAttribMakerT<float, CPSFloatCurveFunctor>(1) {}
00195         NLMISC_DECLARE_CLASS(CPSFloatCurve);
00196         CPSAttribMakerBase *clone() const { return new CPSFloatCurve(*this); }
00197 };
00198 
00199 
00200 
00201 } // NL3D
00202 
00203 
00204 #endif // NL_PS_FLOAT_H
00205 
00206 /* End of ps_size.h */