00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_ANIMATED_VALUE_H
00027 #define NL_ANIMATED_VALUE_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/vector.h"
00031 #include "nel/misc/quat.h"
00032 #include "nel/misc/rgba.h"
00033
00034
00035 namespace NL3D
00036 {
00037
00038
00047 class IAnimatedValue
00048 {
00049 public:
00058 virtual void blend (const IAnimatedValue& value, float blendFactor) =0;
00059
00065 virtual void affect (const IAnimatedValue& value) =0;
00066 };
00067
00068
00076 template<class T>
00077 class CAnimatedValueBlendable : public IAnimatedValue
00078 {
00079 public:
00080
00082
00083 {
00084
00085 nlassert (typeid (value)==typeid(*this));
00086
00087
00088 CAnimatedValueBlendable<T> *pValue=(CAnimatedValueBlendable<T>*)&value;
00089
00090
00091 Value=(T) (Value*blendFactor+pValue->Value*(1.f-blendFactor));
00092 }
00093
00099 virtual void affect (const IAnimatedValue& value)
00100 {
00101
00102 nlassert (typeid (value)==typeid(*this));
00103
00104
00105 CAnimatedValueBlendable<T> *pValue=(CAnimatedValueBlendable<T>*)&value;
00106
00107
00108 Value=pValue->Value;
00109 }
00110
00111
00112 T Value;
00113 };
00114
00115
00116
00124 class CAnimatedValueBlendable<NLMISC::CQuat> : public IAnimatedValue
00125 {
00126 public:
00128 virtual void blend (const IAnimatedValue& value, float blendFactor)
00129 {
00130
00131 nlassert (typeid (value)==typeid(*this));
00132
00133
00134 CAnimatedValueBlendable<NLMISC::CQuat> *pValue=(CAnimatedValueBlendable<NLMISC::CQuat>*)&value;
00135
00136
00137
00138
00139 Value= NLMISC::CQuat::slerp(Value, pValue->Value, 1-blendFactor);
00140
00141 }
00142
00148 virtual void affect (const IAnimatedValue& value)
00149 {
00150
00151 nlassert (typeid (value)==typeid(*this));
00152
00153
00154 CAnimatedValueBlendable<NLMISC::CQuat> *pValue=(CAnimatedValueBlendable<NLMISC::CQuat>*)&value;
00155
00156
00157 Value=pValue->Value;
00158 }
00159
00160
00161 NLMISC::CQuat Value;
00162 };
00163
00164
00172 class CAnimatedValueBlendable<NLMISC::CRGBA> : public IAnimatedValue
00173 {
00174 public:
00176 virtual void blend (const IAnimatedValue& value, float blendFactor)
00177 {
00178
00179 nlassert (typeid (value)==typeid(*this));
00180
00181
00182 CAnimatedValueBlendable<NLMISC::CRGBA> *pValue=(CAnimatedValueBlendable<NLMISC::CRGBA>*)&value;
00183
00184
00185 Value.blendFromui (pValue->Value, this->Value, (uint)(256.f*blendFactor));
00186 }
00187
00193 virtual void affect (const IAnimatedValue& value)
00194 {
00195
00196 nlassert (typeid (value)==typeid(*this));
00197
00198
00199 CAnimatedValueBlendable<NLMISC::CRGBA> *pValue=(CAnimatedValueBlendable<NLMISC::CRGBA>*)&value;
00200
00201
00202 Value=pValue->Value;
00203 }
00204
00205
00206 NLMISC::CRGBA Value;
00207 };
00208
00209
00217 template<class T>
00218 class CAnimatedValueNotBlendable : public IAnimatedValue
00219 {
00220 public:
00221 virtual ~CAnimatedValueNotBlendable<T>() {}
00223 virtual void blend (const IAnimatedValue& value, float blendFactor)
00224 {
00225
00226 nlassert (typeid (value)==typeid(*this));
00227
00228
00229 CAnimatedValueNotBlendable<T> *pValue=(CAnimatedValueNotBlendable<T>*)&value;
00230
00231
00232 if (blendFactor<0.5f)
00233 Value=pValue->Value;
00234 }
00235
00241 virtual void affect (const IAnimatedValue& value)
00242 {
00243
00244 nlassert (typeid (value)==typeid(*this));
00245
00246
00247 CAnimatedValueNotBlendable<T> *pValue=(CAnimatedValueNotBlendable<T>*)&value;
00248
00249
00250 Value=pValue->Value;
00251 }
00252
00253
00254 T Value;
00255 };
00256
00257
00258 typedef CAnimatedValueNotBlendable<bool> CAnimatedValueBool;
00259 typedef CAnimatedValueBlendable<sint32> CAnimatedValueInt;
00260 typedef CAnimatedValueBlendable<float> CAnimatedValueFloat;
00261 typedef CAnimatedValueBlendable<NLMISC::CVector> CAnimatedValueVector;
00262 typedef CAnimatedValueNotBlendable<std::string> CAnimatedValueString;
00263 typedef CAnimatedValueBlendable<NLMISC::CQuat> CAnimatedValueQuat;
00264 typedef CAnimatedValueBlendable<NLMISC::CRGBA> CAnimatedValueRGBA;
00265
00266
00267 }
00268
00269
00270 #endif // NL_ANIMATED_VALUE_H
00271
00272