- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# FCDocument/FCDAnimationCurve.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2005-2007 Feeling Software Inc.
    00003     Portions of the code are:
    00004     Copyright (C) 2005-2007 Sony Computer Entertainment America
    00005
    00006     MIT License: http://www.opensource.org/licenses/mit-license.php
    00007 */
    00008
    00014 #ifndef _FCD_ANIMATION_CURVE_H_
    00015 #define _FCD_ANIMATION_CURVE_H_
    00016
    00017 #ifndef _FU_DAE_ENUM_H_
    00018 #include "FUtils/FUDaeEnum.h"
    00019 #endif // _FU_DAE_ENUM_H_
    00020 #ifndef __FCD_OBJECT_H_
    00021 #include "FCDocument/FCDObject.h"
    00022 #endif // __FCD_OBJECT_H_
    00023
    00024 class FCDAnimated;
    00025 class FCDAnimationClip;
    00026 class FCDAnimationChannel;
    00027 class FCDAnimationKey;
    00028 class FCDConversionFunctor;
    00029
    00030 typedef float (*FCDConversionFunction)(float v);
    00032 typedef fm::pvector<FCDAnimationClip> FCDAnimationClipList;
    00033 typedef fm::pvector<FCDAnimationKey> FCDAnimationKeyList;
    00046 class FCOLLADA_EXPORT FCDAnimationCurve : public FCDObject
    00047 {
    00048 private:
    00049     DeclareObjectType(FCDObject);
    00050
    00051     // The channel owning this curve.
    00052     FCDAnimationChannel* parent;
    00053
    00054     // Targeting information
    00055     int32 targetElement;
    00056     fm::string targetQualifier;
    00057
    00058     // Curve information
    00059     FCDAnimationKeyList keys;
    00060     FUDaeInfinity::Infinity preInfinity, postInfinity;
    00061
    00062     // Driver information
    00063     FUTrackedPtr<FCDAnimated> inputDriver;
    00064     int32 inputDriverIndex;
    00065
    00066     // Animation clips that depend on this curve
    00067     FCDAnimationClipList clips;
    00068     FloatList clipOffsets;
    00069     FCDAnimationClip* currentClip;
    00070     float currentOffset;
    00071     static bool is2DEvaluation;
    00072
    00073 public:
    00074     DeclareFlag(AnimChanged, 0);    // On Member Value Changed
    00075     DeclareFlagCount(1);
    00076
    00077 public:
    00084     FCDAnimationCurve(FCDocument* document, FCDAnimationChannel* parent);
    00085
    00087     virtual ~FCDAnimationCurve();
    00088
    00091     inline FCDAnimationChannel* GetParent() { return parent; }
    00092     inline const FCDAnimationChannel* GetParent() const { return parent; }
    00096     inline FCDAnimationKey** GetKeys() { return keys.begin(); }
    00097     inline const FCDAnimationKey** GetKeys() const { return keys.begin(); }
    00101     inline size_t GetKeyCount() const { return keys.size(); }
    00102
    00107     void SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation);
    00108
    00112     inline FCDAnimationKey* GetKey(size_t index) { FUAssert(index < keys.size(), return NULL); return keys.at(index); }
    00113     inline const FCDAnimationKey* GetKey(size_t index) const { FUAssert(index < keys.size(), return NULL); return keys.at(index); }
    00118     FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation);
    00119
    00124     FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation, float input) { size_t blah; return AddKey(interpolation, input, blah); }
    00125
    00131     FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation, float input, size_t& index);
    00132
    00136     bool DeleteKey(FCDAnimationKey* key);
    00137
    00142     inline FUDaeInfinity::Infinity GetPreInfinity() const { return preInfinity; }
    00143
    00148     inline void SetPreInfinity(FUDaeInfinity::Infinity infinity) { preInfinity = infinity; SetDirtyFlag(); }
    00149
    00154     inline FUDaeInfinity::Infinity GetPostInfinity() const { return postInfinity; }
    00155
    00160     inline void SetPostInfinity(FUDaeInfinity::Infinity infinity) { postInfinity = infinity; SetDirtyFlag(); }
    00161
    00164     bool HasDriver() const;
    00165
    00170     void GetDriver(FCDAnimated*& driver, int32& index);
    00171     void GetDriver(const FCDAnimated*& driver, int32& index) const;
    00172     FCDAnimated* GetDriverPtr(){ return inputDriver; }
    00173
    00177     int32 GetDriverIndex(){ return inputDriverIndex; }
    00178
    00183     void SetDriver(FCDAnimated* driver, int32 index);
    00184
    00187     inline size_t GetClipCount() const { return clips.size(); }
    00188
    00191     inline FCDAnimationClip** GetClips() { return clips.begin(); }
    00192     inline const FCDAnimationClip** GetClips() const { return clips.begin(); }
    00197     inline FCDAnimationClip* GetClip(size_t index) { FUAssert(index < clips.size(), return NULL); return clips[index]; }
    00198     inline const FCDAnimationClip* GetClip(size_t index) const { FUAssert(index < clips.size(), return NULL); return clips[index]; }
    00202     void AddClip(FCDAnimationClip* clip);
    00203
    00207     void SetCurrentAnimationClip(FCDAnimationClip* clip);
    00208
    00214     inline const float GetClipOffset(size_t index) const { return clipOffsets.at(index); }
    00215
    00224     FCDAnimationCurve* Clone(FCDAnimationCurve* clone = NULL, bool includeClips = true) const;
    00225
    00229     void ConvertValues(FCDConversionFunction valueConversion, FCDConversionFunction tangentConversion);
    00230     void ConvertValues(FCDConversionFunctor* valueConversion, FCDConversionFunctor* tangentConversion);
    00235     void ConvertInputs(FCDConversionFunction timeConversion, FCDConversionFunction tangentWeightConversion);
    00236     void ConvertInputs(FCDConversionFunctor* timeConversion, FCDConversionFunctor* tangentWeightConversion);
    00241     float Evaluate(float input) const;
    00242
    00245     void RegisterAnimationClip(FCDAnimationClip* clip);
    00246
    00251     inline int32 GetTargetElement() const { return targetElement; }
    00252
    00257     inline const fm::string& GetTargetQualifier() const { return targetQualifier; }
    00258
    00262     inline void SetTargetElement(int32 e) { targetElement = e; SetDirtyFlag(); }
    00263
    00267     inline void SetTargetQualifier(const fm::string& q) { targetQualifier = q; SetDirtyFlag(); }
    00268
    00272     void SetClipOffset(float offset, const FCDAnimationClip* clip);
    00273
    00280     static void Set2DCurveEvaluation(bool flag) { is2DEvaluation = flag; }
    00281
    00284     static bool Is2DCurveEvaluation() {return is2DEvaluation; }
    00285 };
    00286
    00288 class FCDConversionFunctor
    00289 {
    00290 public:
    00291     FCDConversionFunctor() {}
    00292     virtual ~FCDConversionFunctor() {}
    00293     virtual float operator() (float v) = 0;
    00294 };
    00295
    00297 class FCDConversionScaleFunctor : public FCDConversionFunctor
    00298 {
    00299 private:
    00300     float scaleFactor;
    00301
    00302 public:
    00303     FCDConversionScaleFunctor(float factor) { scaleFactor = factor; }
    00304     void SetScaleFactor(float factor) { scaleFactor = factor; }
    00305     virtual ~FCDConversionScaleFunctor() {}
    00306     virtual float operator() (float v) { return v * scaleFactor; }
    00307     virtual FMVector3 operator() (const FMVector3& v) { return v * scaleFactor; }
    00308     virtual FMVector4 operator() (const FMVector4& v) { return v * scaleFactor; }
    00309 };
    00310
    00312 class FCDConversionOffsetFunctor : public FCDConversionFunctor
    00313 {
    00314 private:
    00315     float offset;
    00316
    00317 public:
    00318     FCDConversionOffsetFunctor(float _offset) { offset = _offset; }
    00319     virtual ~FCDConversionOffsetFunctor() {}
    00320     virtual float operator() (float v) { return v + offset; }
    00321 };
    00322
    00323 #endif // _FCD_ANIMATION_CURVE_H_