00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
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;
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 }
00202
00203
00204 #endif // NL_PS_FLOAT_H
00205
00206