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 
6 	MIT License: http://www.opensource.org/licenses/mit-license.php
7 */
8 /*
9 	Based on the FS Import classes:
10 	Copyright (C) 2005-2006 Feeling Software Inc
11 	Copyright (C) 2005-2006 Autodesk Media Entertainment
12 	MIT License: http://www.opensource.org/licenses/mit-license.php
13 */
14 
15 /**
16 	@file FCDAnimationMultiCurve.h
17 	This file contains the FCDAnimationMultiCurve class.
18 */
19 
20 #ifndef _FCD_ANIMATION_MULTI_CURVE_H_
21 #define _FCD_ANIMATION_MULTI_CURVE_H_
22 
23 #ifndef __FCD_OBJECT_H_
24 #include "FCDocument/FCDObject.h"
25 #endif // __FCD_OBJECT_H_
26 #ifndef _FU_DAE_ENUM_H_
27 #include "FUtils/FUDaeEnum.h"
28 #endif // _FU_DAE_ENUM_H_
29 
30 class FCDocument;
31 class FCDAnimationMKey;
32 
33 typedef fm::pvector<FCDAnimationMKey> FCDAnimationMKeyList; /**< A dynamically-sized array of multi-dimensional animation keys. */
34 
35 /**
36 	A COLLADA multi-dimensional animation curve.
37 
38 	This is a utility class that is used to convert multiple
39 	animation curves into one animation curve that has multiple
40 	dimensions, but only one list of key inputs.
41 
42 	FCollada will never create a multi-dimensional animation curve
43 	during the import of a COLLADA document.
44 
45 	@ingroup FCDocument
46 */
47 class FCOLLADA_EXPORT FCDAnimationMultiCurve : public FCDObject
48 {
49 private:
50 	DeclareObjectType(FCDObject);
51 
52 	// The number of merged curves
53 	uint32 dimension;
54 
55 	// Target information
56 	int32 targetElement;
57 
58 	// Input information
59 	FCDAnimationMKeyList keys;
60 	FUDaeInfinity::Infinity preInfinity, postInfinity;
61 
62 	//What sort of evaluation we do, 1D or 2D
63 	static bool is2DEvaluation;
64 
65 public:
66 	/** Constructor.
67 		The number of dimensions will not change in the lifetime of a
68 		multi-dimensional curve.
69 		@param document The COLLADA document that owns the animation curve.
70 		@param dimension The number of dimensions for the animation curve. */
71 	FCDAnimationMultiCurve(FCDocument* document, uint32 dimension);
72 
73 	/** Destructor. */
74 	virtual ~FCDAnimationMultiCurve();
75 
76 	/** Retrieves the number of dimensions for the curve.
77 		@return The number of dimensions for the curve. */
GetDimension()78 	inline uint32 GetDimension() const { return dimension; }
79 
80 	/** Retrieves the list of key inputs for the animation curve.
81 		@return The list of key inputs. */
GetKeys()82 	inline FCDAnimationMKey** GetKeys() { return keys.begin(); }
GetKeys()83 	inline const FCDAnimationMKey** GetKeys() const { return keys.begin(); } /**< See above. */
84 
85 	/** Retrieves the number of keys within the animation curve.
86 		@return The number of keys. */
GetKeyCount()87 	inline size_t GetKeyCount() const { return keys.size(); }
88 
89 	/** Sets the number of keys within the animation curve.
90 		@param count The new number of keys in the curve.
91 		@param interpolation If creating new keys, the interpolation type
92 			for the new keys. */
93 	void SetKeyCount(size_t count, FUDaeInterpolation::Interpolation interpolation);
94 
95 	/** Retrieve one key of the animation curve.
96 		@param index The index of the key to retrieve.
97 		@return The indexed key. */
GetKey(size_t index)98 	inline FCDAnimationMKey* GetKey(size_t index) { FUAssert(index < keys.size(), return NULL); return keys.at(index); }
GetKey(size_t index)99 	inline const FCDAnimationMKey* GetKey(size_t index) const { FUAssert(index < keys.size(), return NULL); return keys.at(index); } /**< See above. */
100 
101 	/** Appends a key to the animation curve.
102 		@param interpolation The interpolation type for the new key.
103 		@return The new key. */
104 	FCDAnimationMKey* AddKey(FUDaeInterpolation::Interpolation interpolation);
105 
106 	/** Retrieves the type of behavior for the curve if the input value is
107 		outside the input interval defined by the curve keys and less than any key input value.
108 		@see FUDaeInfinity
109 		@return The pre-infinity behavior of the curve. */
GetPreInfinity()110 	inline FUDaeInfinity::Infinity GetPreInfinity() const { return preInfinity; }
111 
112 	/** Sets the behavior of the curve if the input value is
113 		outside the input interval defined by the curve keys and less than any key input value.
114 		@see FUDaeInfinity
115 		@param infinity The pre-infinity behavior of the curve. */
SetPreInfinity(FUDaeInfinity::Infinity infinity)116 	inline void SetPreInfinity(FUDaeInfinity::Infinity infinity) { preInfinity = infinity; SetDirtyFlag(); }
117 
118 	/** Retrieves the type of behavior for the curve if the input value is
119 		outside the input interval defined by the curve keys and greater than any key input value.
120 		@see FUDaeInfinity
121 		@return The post-infinity behavior of the curve. */
GetPostInfinity()122 	inline FUDaeInfinity::Infinity GetPostInfinity() const { return postInfinity; }
123 
124 	/** Sets the behavior of the curve if the input value is
125 		outside the input interval defined by the curve keys and greater than any key input value.
126 		@see FUDaeInfinity
127 		@param infinity The post-infinity behavior of the curve. */
SetPostInfinity(FUDaeInfinity::Infinity infinity)128 	inline void SetPostInfinity(FUDaeInfinity::Infinity infinity) { postInfinity = infinity; SetDirtyFlag(); }
129 
130 	/** Evaluates the animation curve.
131 		@param input An input value.
132 		@param output An array of floating-point values to fill in with the sampled values. */
133 	void Evaluate(float input, float* output) const;
134 
135 	/** [INTERNAL] Retrieves the target element suffix for the curve.
136 		This will be -1 if the animated element does not belong to an
137 		animated element list.
138 		@return The target element suffix. */
GetTargetElement()139 	inline int32 GetTargetElement() const { return targetElement; }
140 
141 	/** [INTERNAL] Sets the target element suffix for the curve.
142 		@param e The target element suffix. Set to value to -1
143 			if the animated element does not belong to an animated element list. */
SetTargetElement(int32 e)144 	inline void SetTargetElement(int32 e) { targetElement = e; SetDirtyFlag(); }
GetTargetElement()145 	inline int32 GetTargetElement() { return targetElement; }
146 
147 	/** [INTERNAL] Sets the target qualifier for the merged curve.
148 		Target qualifiers are transient information useful when exporting animation curves.
149 		@param index The dimension index of the target qualifier to modify.
150 		@param qualifier The new target qualifier. */
151 	//inline void SetTargetQualifier(size_t index, const fm::string& qualifier) { FUAssert(index < dimension, return); targetQualifiers[index] = qualifier; }
152 	//inline fm::string& GetTargetQualifier(size_t index) { FUAssert(index < dimension,); return targetQualifiers[index]; }
153 
154 	/** Turns on or off the 2D Curve Evaluation.
155 		@param flag An on or off boolean flag.*/
Set2DCurveEvaluation(bool flag)156 	inline void Set2DCurveEvaluation(bool flag) { is2DEvaluation = flag; }
157 
158 	/** Returns whether 2D Curve Evaluation is on or off.
159 		@return A boolean that indicates if the 2D Curve Evaluation is on or off. */
Is2DCurveEvaluation()160 	inline bool Is2DCurveEvaluation() {return is2DEvaluation; }
161 };
162 
163 #endif // _FCD_ANIMATION_MULTI_CURVE_H_
164