PageRenderTime 38ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/Core/Dependencies/OgreCollada/FCollada/FCollada/FCDocument/FCDAnimationCurve.h

https://bitbucket.org/barakianc/nvidia-physx-and-apex-in-gge
C Header | 323 lines | 112 code | 56 blank | 155 comment | 0 complexity | dfc0aa5caadd96a85beb586dca913059 MD5 | raw file
  1. /*
  2. Copyright (C) 2005-2007 Feeling Software Inc.
  3. Portions of the code are:
  4. Copyright (C) 2005-2007 Sony Computer Entertainment America
  5. MIT License: http://www.opensource.org/licenses/mit-license.php
  6. */
  7. /**
  8. @file FCDAnimationCurve.h
  9. This file contains the FCDAnimationCurve class and the conversion functions/functors.
  10. */
  11. #ifndef _FCD_ANIMATION_CURVE_H_
  12. #define _FCD_ANIMATION_CURVE_H_
  13. #ifndef _FU_DAE_ENUM_H_
  14. #include "FUtils/FUDaeEnum.h"
  15. #endif // _FU_DAE_ENUM_H_
  16. #ifndef __FCD_OBJECT_H_
  17. #include "FCDocument/FCDObject.h"
  18. #endif // __FCD_OBJECT_H_
  19. class FCDAnimated;
  20. class FCDAnimationClip;
  21. class FCDAnimationChannel;
  22. class FCDAnimationKey;
  23. class FCDConversionFunctor;
  24. typedef float (*FCDConversionFunction)(float v); /**< A simple conversion function. */
  25. typedef fm::pvector<FCDAnimationClip> FCDAnimationClipList;
  26. typedef fm::pvector<FCDAnimationKey> FCDAnimationKeyList;
  27. /**
  28. A COLLADA single-dimensional animation curve.
  29. An animation curve holds the keyframes necessary
  30. to animate an animatable floating-point value.
  31. There are multiple interpolation mechanisms supported by COLLADA.
  32. FCollada supports the CONSTANT, LINEAR and BEZIER interpolations.
  33. @see FUDaeInterpolation FUDaeInfinity
  34. @ingroup FCDocument
  35. */
  36. class FCOLLADA_EXPORT FCDAnimationCurve : public FCDObject
  37. {
  38. private:
  39. DeclareObjectType(FCDObject);
  40. // The channel owning this curve.
  41. FCDAnimationChannel* parent;
  42. // Targeting information
  43. int32 targetElement;
  44. fm::string targetQualifier;
  45. // Curve information
  46. FCDAnimationKeyList keys;
  47. FUDaeInfinity::Infinity preInfinity, postInfinity;
  48. // Driver information
  49. FUTrackedPtr<FCDAnimated> inputDriver;
  50. int32 inputDriverIndex;
  51. // Animation clips that depend on this curve
  52. FCDAnimationClipList clips;
  53. FloatList clipOffsets;
  54. FCDAnimationClip* currentClip;
  55. float currentOffset;
  56. static bool is2DEvaluation;
  57. public:
  58. DeclareFlag(AnimChanged, 0); // On Member Value Changed
  59. DeclareFlagCount(1);
  60. public:
  61. /** Constructor: do not use directly.
  62. Instead, use the FCDAnimationChannel::AddCurve function.
  63. You should also attach the new curve to an animated
  64. element using the FCDAnimated::SetCurve function.
  65. @param document The COLLADA document that owns the animation curve.
  66. @param parent The animation channel that contains the curve. */
  67. FCDAnimationCurve(FCDocument* document, FCDAnimationChannel* parent);
  68. /** Destructor. */
  69. virtual ~FCDAnimationCurve();
  70. /** Retrieves the animation channel that contains this animation curve.
  71. @return The parent animation channel. */
  72. inline FCDAnimationChannel* GetParent() { return parent; }
  73. inline const FCDAnimationChannel* GetParent() const { return parent; } /**< See above. */
  74. /** Retrieves the list of keys for the animation curve.
  75. @return The list of keys. */
  76. inline FCDAnimationKey** GetKeys() { return keys.begin(); }
  77. inline const FCDAnimationKey** GetKeys() const { return keys.begin(); } /**< See above. */
  78. /** Retrieves the number of keys within the animation curve.
  79. @return The number of keys. */
  80. inline size_t GetKeyCount() const { return keys.size(); }
  81. /** Sets the number of keys within the animation curve.
  82. @param count The new number of keys in the curve.
  83. @param interpolation If creating new keys, the interpolation type
  84. for the new keys. */
  85. void SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation);
  86. /** Retrieves one key in the animation curve.
  87. @param index The index of the key to retrieve.
  88. @return The key. */
  89. inline FCDAnimationKey* GetKey(size_t index) { FUAssert(index < keys.size(), return NULL); return keys.at(index); }
  90. inline const FCDAnimationKey* GetKey(size_t index) const { FUAssert(index < keys.size(), return NULL); return keys.at(index); } /**< See above. */
  91. /** Appends a key to the animation curve.
  92. @param interpolation The interpolation type for the new key.
  93. @return The new key. */
  94. FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation);
  95. /** Adds a new key to the animation curve at the given time.
  96. @param interpolation The interpolation type for the new key.
  97. @param input The input (x) value of the new key.
  98. @return The new key. */
  99. FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation, float input) { size_t blah; return AddKey(interpolation, input, blah); }
  100. /** Adds a new key to the animation curve at the given time.
  101. @param interpolation The interpolation type for the new key.
  102. @param input The input (x) value of the new key.
  103. @param index [OUT] The index in the array of the new key
  104. @return The new key. */
  105. FCDAnimationKey* AddKey(FUDaeInterpolation::Interpolation interpolation, float input, size_t& index);
  106. /** Removes the given key from this curves list and deletes it
  107. @param key The key to find and delete
  108. @return True on success, false if the key is not found */
  109. bool DeleteKey(FCDAnimationKey* key);
  110. /** Retrieves the type of behavior for the curve if the input value is
  111. outside the input interval defined by the curve keys and less than any key input value.
  112. @see FUDaeInfinity
  113. @return The pre-infinity behavior of the curve. */
  114. inline FUDaeInfinity::Infinity GetPreInfinity() const { return preInfinity; }
  115. /** Sets the behavior of the curve if the input value is
  116. outside the input interval defined by the curve keys and less than any key input value.
  117. @see FUDaeInfinity
  118. @param infinity The pre-infinity behavior of the curve. */
  119. inline void SetPreInfinity(FUDaeInfinity::Infinity infinity) { preInfinity = infinity; SetDirtyFlag(); }
  120. /** Retrieves the type of behavior for the curve if the input value is
  121. outside the input interval defined by the curve keys and greater than any key input value.
  122. @see FUDaeInfinity
  123. @return The post-infinity behavior of the curve. */
  124. inline FUDaeInfinity::Infinity GetPostInfinity() const { return postInfinity; }
  125. /** Sets the behavior of the curve if the input value is
  126. outside the input interval defined by the curve keys and greater than any key input value.
  127. @see FUDaeInfinity
  128. @param infinity The post-infinity behavior of the curve. */
  129. inline void SetPostInfinity(FUDaeInfinity::Infinity infinity) { postInfinity = infinity; SetDirtyFlag(); }
  130. /** Retrieves whether this animation curve has a driver.
  131. @return Whether there is a driver for this curve. */
  132. bool HasDriver() const;
  133. /** Retrieves the value pointer that drives this animation curve.
  134. @param driver A reference to receive the animated input driver. This pointer will
  135. be set to NULL when there is no input driver.
  136. @param index A reference to receive the animated input driver element index. */
  137. void GetDriver(FCDAnimated*& driver, int32& index);
  138. void GetDriver(const FCDAnimated*& driver, int32& index) const; /**< See above. */
  139. FCDAnimated* GetDriverPtr(){ return inputDriver; }
  140. /** [INTERNAL] Retrieve the driver index.
  141. @return The driver index.
  142. */
  143. int32 GetDriverIndex(){ return inputDriverIndex; }
  144. /** Sets the value pointer that drives the animation curve.
  145. @param driver The driver animated value. Set this pointer to NULL
  146. to indicate that time drives the animation curve.
  147. @param index The driver animated value index. */
  148. void SetDriver(FCDAnimated* driver, int32 index);
  149. /** Retrieves the number of animation clips that use this animation curve.
  150. @return The number of animation clips. */
  151. inline size_t GetClipCount() const { return clips.size(); }
  152. /** Retrieves the list of animation clips that use this animation curve.
  153. @return The list of animation clips. */
  154. inline FCDAnimationClip** GetClips() { return clips.begin(); }
  155. inline const FCDAnimationClip** GetClips() const { return clips.begin(); } /**< See above. */
  156. /** Retrieves an animation clips that use this animation curve.
  157. @param index The index of the animation clip.
  158. @return The animation clip at the given index in the list of clips that use this curve. */
  159. inline FCDAnimationClip* GetClip(size_t index) { FUAssert(index < clips.size(), return NULL); return clips[index]; }
  160. inline const FCDAnimationClip* GetClip(size_t index) const { FUAssert(index < clips.size(), return NULL); return clips[index]; } /**< See above. */
  161. /** Adds an animation clip to the list of animation clips that use this curve.
  162. @param clip An animation clip that uses this curve. */
  163. void AddClip(FCDAnimationClip* clip);
  164. /** Updates the keys to match the timing of an animation clip that has been
  165. registered using RegisterAnimationClip, or returned from GetClips.
  166. @param clip The clip to update the keys to. */
  167. void SetCurrentAnimationClip(FCDAnimationClip* clip);
  168. /** Gets the offset for an animation clip. When the offset is added to the
  169. keys, it causes the animation curve to be repositioned so that the
  170. animation clip starts at the beginning.
  171. @param index The index of the animation clip to get offset for.
  172. @return The offset value. */
  173. inline const float GetClipOffset(size_t index) const { return clipOffsets.at(index); }
  174. /** Clones the animation curve. The animation clips can be cloned as well,
  175. but this may lead to an infinite recursion because cloning the clips
  176. will also clone its curves.
  177. @param clone The cloned animation curve. If this pointer is NULL, a new
  178. animation curve will be created for you. You will then need to release
  179. the pointer.
  180. @param includeClips True if want to also clone the animation clips.
  181. @return The cloned animation curve. */
  182. FCDAnimationCurve* Clone(FCDAnimationCurve* clone = NULL, bool includeClips = true) const;
  183. /** Applies a conversion function to the key output values of the animation curve.
  184. @param valueConversion The conversion function to use on the key outputs.
  185. @param tangentConversion The conversion function to use on the key tangents. */
  186. void ConvertValues(FCDConversionFunction valueConversion, FCDConversionFunction tangentConversion);
  187. void ConvertValues(FCDConversionFunctor* valueConversion, FCDConversionFunctor* tangentConversion); /**< See above. */
  188. /** Applies a conversion function to the key input values of the animation curve.
  189. @param timeConversion The conversion function to use on the key inputs.
  190. @param tangentWeightConversion The conversion function to use on the key tangent weights. */
  191. void ConvertInputs(FCDConversionFunction timeConversion, FCDConversionFunction tangentWeightConversion);
  192. void ConvertInputs(FCDConversionFunctor* timeConversion, FCDConversionFunctor* tangentWeightConversion); /**< See above. */
  193. /** Evaluates the animation curve.
  194. @param input An input value.
  195. @return The sampled value of the curve at the given input value. */
  196. float Evaluate(float input) const;
  197. /** [INTERNAL] Adds an animation clip to the list of animation clips that use this curve.
  198. @param clip An animation clip. */
  199. void RegisterAnimationClip(FCDAnimationClip* clip);
  200. /** [INTERNAL] Retrieves the target element suffix for the curve.
  201. This will be -1 if the animated element does not belong to an
  202. animated element list.
  203. @return The target element suffix. */
  204. inline int32 GetTargetElement() const { return targetElement; }
  205. /** [INTERNAL] Retrieves the target qualifier for the curve.
  206. This will be the empty string if that the curve affects
  207. a one-dimensional animated element.
  208. @return The target qualifier. */
  209. inline const fm::string& GetTargetQualifier() const { return targetQualifier; }
  210. /** [INTERNAL] Sets the target element suffix for the curve.
  211. @param e The target element suffix. Set to value to -1
  212. if the animated element does not belong to an animated element list. */
  213. inline void SetTargetElement(int32 e) { targetElement = e; SetDirtyFlag(); }
  214. /** [INTERNAL] Sets the target qualifier for the curve.
  215. @param q The target qualifier. You may sets this string to the empty string
  216. only if that the curve affects a one-dimensional animated element. */
  217. inline void SetTargetQualifier(const fm::string& q) { targetQualifier = q; SetDirtyFlag(); }
  218. /** [INTERNAL] Updates the offset for a given animation clip.
  219. @param offset The new offset.
  220. @param clip The animation clip to associate with the offset. */
  221. void SetClipOffset(float offset, const FCDAnimationClip* clip);
  222. /** Sets the 2D Curve Evaluation flag.
  223. This flag can be set by the user to enable the
  224. slower, but higher quality 2D evaluation. If the
  225. flag is negative, the faster 1D slope-based evaluation is
  226. performed. Defaults to true.
  227. @param flag Whether to enable 2D curve evaluation. */
  228. static void Set2DCurveEvaluation(bool flag) { is2DEvaluation = flag; }
  229. /** Returns whether 2D Curve Evaluation is on or off.
  230. @return A boolean that indicates if the 2D Curve Evaluation is on or off. */
  231. static bool Is2DCurveEvaluation() {return is2DEvaluation; }
  232. };
  233. /** A simple conversion functor. */
  234. class FCDConversionFunctor
  235. {
  236. public:
  237. FCDConversionFunctor() {} /**< Constructor. */
  238. virtual ~FCDConversionFunctor() {} /**< Destructor. */
  239. virtual float operator() (float v) = 0; /**< Main functor to override. @param v The value to convert. @return The converted value. */
  240. };
  241. /** A sample conversion functor: it scales the value by a given amount. */
  242. class FCDConversionScaleFunctor : public FCDConversionFunctor
  243. {
  244. private:
  245. float scaleFactor;
  246. public:
  247. FCDConversionScaleFunctor(float factor) { scaleFactor = factor; } /**< Constructor. @param factor The scale factor. */
  248. void SetScaleFactor(float factor) { scaleFactor = factor; } /**< Mutator. @param factor The new scale factor. */
  249. virtual ~FCDConversionScaleFunctor() {} /**< Destructor. */
  250. virtual float operator() (float v) { return v * scaleFactor; } /**< Scales the given value. @param v The value to scale. @return The scaled value. */
  251. virtual FMVector3 operator() (const FMVector3& v) { return v * scaleFactor; } /**< Scales the given FMVector3. @param v The value to scale. @return The scaled value. */
  252. virtual FMVector4 operator() (const FMVector4& v) { return v * scaleFactor; } /**< Scales the given FMVector4. @param v The value to scale. @return The scaled value. */
  253. };
  254. /** A sample conversion functor: it offsets the value by a given amount. */
  255. class FCDConversionOffsetFunctor : public FCDConversionFunctor
  256. {
  257. private:
  258. float offset;
  259. public:
  260. FCDConversionOffsetFunctor(float _offset) { offset = _offset; } /**< Constructor. @param _offset The value offset. */
  261. virtual ~FCDConversionOffsetFunctor() {} /**< Destructor. */
  262. virtual float operator() (float v) { return v + offset; } /**< Offsets the given value. @param v The value to offset. @return The offseted value. */
  263. };
  264. #endif // _FCD_ANIMATION_CURVE_H_