00001 #ifndef __NYTRO_Animation_H
00002 #define __NYTRO_Animation_H
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "system/nyCommon.h"
00012 #include "system/nyBase.h"
00013 #include "graphics/nyColor.h"
00014 #include "math/nyMath.h"
00015
00016 namespace Nytro
00017 {
00018 namespace Audio
00019 {
00020 class SoundSource;
00021 };
00022
00023 namespace Scene
00024 {
00025 class SceneNode;
00026 };
00027
00028 namespace Game
00029 {
00030 class FlowGraph;
00031 };
00032
00033 namespace Graphics
00034 {
00035 using namespace Scene;
00036 using namespace Game;
00037 using namespace Audio;
00038
00039 class Animation;
00040 class AnimationTrack;
00041
00043 enum EAnimationLoop
00044 {
00046 eAnimationLoop_None = 0,
00048 eAnimationLoop_Repeat,
00050 eAnimationLoop_PingPong
00051 };
00052
00054 enum EAnimationInterpolation
00055 {
00056 eAnimationInterpolation_Linear = 0,
00057 eAnimationInterpolation_Bezier,
00058 eAnimationInterpolation_TCB
00059 };
00060
00062 class NYTRO_API AnimationKeyValue
00063 {
00064 public:
00065
00067 union
00068 {
00069 int8 m_int8;
00070 int16 m_int16;
00071 int32 m_int32;
00072 int64 m_int64;
00073 float32 m_float32;
00074 float64 m_float64;
00075 float32 m_vector[3];
00076 float32 m_quat[4];
00077 float32 m_color[4];
00078 };
00079 };
00080
00082 class NYTRO_API AnimationKey
00083 {
00084 public:
00085
00087 enum EAnimationKeyFlag
00088 {
00090 eAnimationKeyFlag_Active = NYTRO_BIT(0),
00092 eAnimationKeyFlag_UseEase = NYTRO_BIT(1)
00093 };
00094
00095 AnimationKey();
00096 virtual ~AnimationKey();
00097
00099 void set( voidptr pData );
00101 void interpolate( EAnimationInterpolation aIpolType, AnimationKey& rKey, float32 aT, voidptr pData );
00102
00103 AnimationKey& operator += ( AnimationKey& rAnimationKey );
00104 AnimationKey& operator -= ( AnimationKey& rAnimationKey );
00105 AnimationKey& operator *= ( AnimationKey& rAnimationKey );
00106 AnimationKey& operator /= ( AnimationKey& rAnimationKey );
00107
00108 AnimationKey operator + ( AnimationKey& rAnimationKey );
00109 AnimationKey operator - ( AnimationKey& rAnimationKey );
00110 AnimationKey operator * ( AnimationKey& rAnimationKey );
00111 AnimationKey operator / ( AnimationKey& rAnimationKey );
00112
00113 AnimationKey& operator += ( float32 rValue );
00114 AnimationKey& operator -= ( float32 rValue );
00115 AnimationKey& operator *= ( float32 rValue );
00116 AnimationKey& operator /= ( float32 rValue );
00117
00118 AnimationKey operator + ( float32 rValue );
00119 AnimationKey operator - ( float32 rValue );
00120 AnimationKey operator * ( float32 rValue );
00121 AnimationKey operator / ( float32 rValue );
00122
00124 uint32 m_flags;
00126 float32 m_time;
00128 uint32 m_type;
00130 float32 m_tension,
00132 m_continuity,
00134 m_bias,
00136 m_easeIn,
00138 m_easeOut;
00140 AnimationKeyValue m_value,
00142 m_leftTangent,
00144 m_rightTangent;
00145 };
00146
00149 class NYTRO_API AnimationTrackController : public Base
00150 {
00151 public:
00152
00154 enum EAnimationTrackCtrlOp
00155 {
00157 eAnimationTrackCtrlOp_Add,
00159 eAnimationTrackCtrlOp_Subtract,
00161 eAnimationTrackCtrlOp_Multiply,
00163 eAnimationTrackCtrlOp_Divide,
00165 eAnimationTrackCtrlOp_Replace
00166 };
00167
00168 AnimationTrackController();
00169 virtual ~AnimationTrackController();
00170
00172 AnimationTrack* getTrack();
00174 AnimationKey getResultKey();
00176 EAnimationTrackCtrlOp getOperand();
00178 virtual void initialize();
00180 virtual void release();
00182 virtual void setTrack( AnimationTrack* pTrack );
00184 virtual void setOperand( EAnimationTrackCtrlOp aValue );
00186 virtual void controlValue( float32 aTime, voidptr pCurrentValue );
00187
00188 protected:
00189
00191 AnimationTrack* m_pTrack;
00193 AnimationKey m_resultKey;
00195 EAnimationTrackCtrlOp m_operand;
00196 };
00197
00199 class NYTRO_API AnimationTrack : public Base
00200 {
00201 public:
00202
00204 enum EAnimationTrackType
00205 {
00206 eAnimationTrackType_Int8,
00207 eAnimationTrackType_Int16,
00208 eAnimationTrackType_Int32,
00209 eAnimationTrackType_Int64,
00210 eAnimationTrackType_Float32,
00211 eAnimationTrackType_Float64,
00212 eAnimationTrackType_Vector2,
00213 eAnimationTrackType_Vector3,
00214 eAnimationTrackType_Quaternion,
00215 eAnimationTrackType_Color
00216 };
00217
00219 enum EAnimationTrackFlag
00220 {
00221 eAnimationTrackFlag_Active = NYTRO_BIT(0)
00222 };
00223
00224 AnimationTrack();
00225 virtual ~AnimationTrack();
00226
00228 vector<AnimationKey>& getKeys();
00230 vector<AnimationTrackController*>& getControllers();
00232 voidptr getVariable();
00234 EAnimationLoop getLoopMode();
00236 float32 getSpeed();
00238 AnimationKey& getDefaultKeyVariable();
00239 uint32 getAnimationTrackFlags();
00240 void setAnimationTrackFlags( uint32 aFlags );
00242 void setVariable( voidptr pValue );
00244 void setLoopMode( EAnimationLoop aValue );
00246 void setSpeed( float32 aValue );
00248 void setInterpolationType( EAnimationInterpolation aType )
00249 {
00250 m_interpolationType = aType;
00251 }
00252
00254 EAnimationInterpolation getInterpolationType() const
00255 {
00256 return m_interpolationType;
00257 }
00258
00260 virtual void process( float32 aTime );
00262 virtual void bindToVariable( EAnimationTrackType aType, voidptr pData );
00264 virtual AnimationKey* addKey( float32 aTime, voidptr pData );
00266 virtual void computeTangents();
00267
00269 AnimationKey* addKey( float32 aTime, float32 aData );
00271 AnimationKey* addKey( float32 aTime, float64 aData );
00273 AnimationKey* addKey( float32 aTime, int64 aData );
00275 AnimationKey* addKey( float32 aTime, int32 aData );
00277 AnimationKey* addKey( float32 aTime, int16 aData );
00279 AnimationKey* addKey( float32 aTime, int8 aData );
00281 AnimationKey* addKey( float32 aTime, Vector3D& aData );
00283 AnimationKey* addKey( float32 aTime, Quaternion& aData );
00285 AnimationKey* addKey( float32 aTime, Color& aData );
00286
00287 protected:
00288
00290 uint32 m_animationTrackFlags;
00292 vector<AnimationKey> m_keys;
00294 EAnimationInterpolation m_interpolationType;
00296 AnimationKey m_defaultKeyVariable;
00298 vector<AnimationTrackController*> m_controllers;
00300 voidptr m_pVariable;
00302 EAnimationLoop m_loopMode;
00304 float32 m_speed,
00306 m_direction;
00307 };
00308
00310 class NYTRO_API AnimationEvent : public Base
00311 {
00312 public:
00313
00314 AnimationEvent();
00315 virtual ~AnimationEvent();
00316
00318 void setTime( float32 aValue );
00320 void setActive( bool bActive );
00322 void setTriggered( bool bTrigger );
00324 void setDescription( const char* pValue );
00325
00327 float32 getTime();
00329 bool isActive();
00331 bool isTriggered();
00333 string getDescription();
00334
00336 virtual void onTrigger();
00337
00338 protected:
00339
00340 float32 m_time;
00341 bool m_bActive, m_bTriggered;
00342 string m_description;
00343 };
00344
00346 class NYTRO_API SoundAnimationEvent : public AnimationEvent
00347 {
00348 public:
00349
00350 SoundAnimationEvent();
00351 virtual ~SoundAnimationEvent();
00352
00353 NYTRO_CLASS_NAME( SoundAnimationEvent );
00354 virtual void onTrigger();
00355
00356 string m_soundFile, m_parentName;
00357 float32 m_volume;
00358 bool m_bFollowParent;
00359 SceneNode* m_pParent;
00360 SoundSource* m_pSound;
00361 };
00362
00364 class NYTRO_API FlowGraphAnimationEvent : public AnimationEvent
00365 {
00366 public:
00367
00368 FlowGraphAnimationEvent();
00369 virtual ~FlowGraphAnimationEvent();
00370
00371 NYTRO_CLASS_NAME( FlowGraphAnimationEvent );
00372 virtual void onTrigger();
00373
00374 FlowGraph* m_pGraph;
00375 };
00376
00378 class NYTRO_API Animation : public Base
00379 {
00380 public:
00381
00383 enum EAnimationFlag
00384 {
00385 eAnimationFlag_AutoDuration = NYTRO_BIT(0)
00386 };
00387
00388 Animation();
00389 virtual ~Animation();
00390
00393 float32 getDuration();
00395 float32 getTime();
00397 float32 getTimeScale();
00399 vector<AnimationTrack*>& getTracks();
00401 EAnimationLoop getLoopMode();
00402
00404 void setDuration( float32 aValue );
00406 void setTime( float32 aValue );
00408 void setTimeScale( float32 aValue );
00410 void setLoopMode( EAnimationLoop aValue );
00411 uint32 getAnimationFlags();
00412 void setAnimationFlags( uint32 aFlags );
00413
00415 virtual void process( float32 aTimeDelta );
00417 virtual AnimationTrack* addTrack( const char* pName, AnimationTrack::EAnimationTrackType aType, voidptr pData );
00419 virtual void play();
00421 virtual AnimationTrack* findTrackByName( const char* pName );
00423 virtual void loadFromXmlElements( XmlElement* pElem );
00425 void freeData();
00426
00427 protected:
00428
00430 uint32 m_animationFlags;
00432 float32 m_duration,
00434 m_time;
00436 float32 m_timeScale,
00438 m_direction;
00440 EAnimationLoop m_loopMode;
00442 vector<AnimationTrack*> m_tracks;
00444 vector<AnimationEvent*> m_events;
00445 };
00446
00448 class NYTRO_API AnimationSetData : public Resource
00449 {
00450 public:
00451
00452 NYTRO_CLASS_NAME( AnimationSetData );
00453
00454 AnimationSetData();
00455 virtual ~AnimationSetData();
00456
00458 EResult load( const char* pFilename = NULL );
00460 EResult unload();
00462 void free();
00464 map<string,Animation*>& getAnimations();
00465
00466 protected:
00467
00469 map<string,Animation*> m_animations;
00470 };
00471 };
00472 };
00473
00474 #endif