Update contrib.
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: AnimationController implementation
22 * \brief AnimationController implementation
25 #ifndef M3G_CORE_INCLUDE
26 # error included by m3g_core.c; do not compile separately.
29 #include "m3g_animationcontroller.h"
30 #include "m3g_memory.h"
33 /*----------------------------------------------------------------------
35 *--------------------------------------------------------------------*/
39 * \brief Destroys this AnimationController object.
41 * \param obj AnimationController object
43 static void m3gDestroyAnimationController(Object *obj)
45 AnimationController *animController = (AnimationController *) obj;
46 M3G_VALIDATE_OBJECT(animController);
48 m3gDestroyObject(&animController->object);
53 * \brief Check if controller is active.
55 * \param controller AnimationController object
56 * \param worldTime current world time
57 * \retval M3G_TRUE controller active
58 * \retval M3G_FALSE controller not active
60 static M3Gbool m3gIsActive(const AnimationController *controller,
63 if (controller->activationTime == controller->deactivationTime) {
66 return (worldTime >= controller->activationTime &&
67 worldTime < controller->deactivationTime);
72 * \brief Gets time to controller activation.
74 * \param controller AnimationController object
75 * \param worldTime current world time
76 * \return time to controller activation
78 static M3Gint m3gTimeToActivation(const AnimationController *controller,
81 if (worldTime < controller->activationTime) {
82 return (controller->activationTime - worldTime);
84 else if (worldTime < controller->deactivationTime) {
92 * \brief Gets time to controller deactivation.
94 * \param controller AnimationController object
95 * \param worldTime current world time
96 * \return time to controller deactivation
98 static M3Gint m3gTimeToDeactivation(const AnimationController *controller,
101 if (worldTime < controller->deactivationTime) {
102 return (controller->deactivationTime - worldTime);
109 * \brief Overloaded Object3D method.
111 * \param originalObj original AnimationController object
112 * \param cloneObj pointer to cloned AnimationController object
113 * \param pairs array for all object-duplicate pairs
114 * \param numPairs number of pairs
116 static M3Gbool m3gAnimationControllerDuplicate(const Object *originalObj,
121 const AnimationController *original = (AnimationController *)originalObj;
122 AnimationController *clone =
123 m3gCreateAnimationController(originalObj->interface);
124 *cloneObj = (Object *)clone;
125 if (*cloneObj == NULL) {
129 if (m3gObjectDuplicate(originalObj, cloneObj, pairs, numPairs)) {
130 clone->activationTime = original->activationTime;
131 clone->deactivationTime = original->deactivationTime;
132 clone->weight = original->weight;
133 clone->speed = original->speed;
134 clone->refWorldTime = original->refWorldTime;
135 clone->refSequenceTime = original->refSequenceTime;
143 /*----------------------------------------------------------------------
144 * Virtual function table
145 *--------------------------------------------------------------------*/
147 static const ObjectVFTable m3gvf_AnimationController = {
148 m3gObjectApplyAnimation,
149 m3gObjectIsCompatible,
150 m3gObjectUpdateProperty,
151 m3gObjectDoGetReferences,
153 m3gAnimationControllerDuplicate,
154 m3gDestroyAnimationController
158 /*----------------------------------------------------------------------
159 * Public API functions
160 *--------------------------------------------------------------------*/
163 * \brief Creates a new AnimationController with default values
165 * \param hInterface M3G interface
166 * \retval AnimationController new AnimationController object
167 * \retval NULL AnimationController creating failed
169 M3G_API M3GAnimationController m3gCreateAnimationController(
170 M3GInterface hInterface)
172 Interface *m3g = (Interface *) hInterface;
173 M3G_VALIDATE_INTERFACE(m3g);
175 AnimationController *controller = m3gAllocZ(m3g, sizeof(AnimationController));
177 if (controller != NULL) {
178 m3gInitObject(&controller->object, m3g,
179 M3G_CLASS_ANIMATION_CONTROLLER);
180 controller->weight = 1;
181 controller->speed = 1.0f;
184 return (M3GAnimationController) controller;
189 * \brief Set active interval.
191 * \param hController AnimationController object
192 * \param worldTimeMin active interval start
193 * \param worldTimeMax active interval end
195 M3G_API void m3gSetActiveInterval(M3GAnimationController hController,
199 AnimationController *controller = (AnimationController *) hController;
200 M3G_VALIDATE_OBJECT(controller);
202 if (worldTimeMin > worldTimeMax) {
203 m3gRaiseError(M3G_INTERFACE(controller), M3G_INVALID_VALUE);
206 controller->activationTime = worldTimeMin;
207 controller->deactivationTime = worldTimeMax;
211 * \brief Get active interval start.
213 * \param hController AnimationController object
214 * \return active interval start
216 M3G_API M3Gint m3gGetActiveIntervalStart(M3GAnimationController hController)
218 AnimationController *controller = (AnimationController *) hController;
219 M3G_VALIDATE_OBJECT(controller);
221 return controller->activationTime;
225 * \brief Get active interval end.
227 * \param hController AnimationController object
228 * \return active interval end
230 M3G_API M3Gint m3gGetActiveIntervalEnd(M3GAnimationController hController)
232 AnimationController *controller = (AnimationController *) hController;
233 M3G_VALIDATE_OBJECT(controller);
235 return controller->deactivationTime;
241 * \param hController AnimationController object
242 * \param factor speed factor
243 * \param worldTime reference world time
245 M3G_API void m3gSetSpeed(M3GAnimationController hController,
246 M3Gfloat factor, M3Gint worldTime)
248 AnimationController *controller = (AnimationController *) hController;
249 M3G_VALIDATE_OBJECT(controller);
251 controller->refSequenceTime = m3gGetPosition(controller, worldTime);
252 controller->refWorldTime = worldTime;
253 controller->speed = factor;
259 * \param hController AnimationController object
260 * \return speed factor
262 M3G_API M3Gfloat m3gGetSpeed(M3GAnimationController hController)
264 AnimationController *controller = (AnimationController *) hController;
265 M3G_VALIDATE_OBJECT(controller);
267 return controller->speed;
271 * \brief Set position.
273 * \param hController AnimationController object
274 * \param sequenceTime sequence time
275 * \param worldTime world time
277 M3G_API void m3gSetPosition(M3GAnimationController hController,
278 M3Gfloat sequenceTime, M3Gint worldTime)
280 AnimationController *controller = (AnimationController *) hController;
281 M3G_VALIDATE_OBJECT(controller);
283 controller->refWorldTime = worldTime;
284 controller->refSequenceTime = sequenceTime;
288 * \brief Get position.
290 * \param hController AnimationController object
291 * \param worldTime current world time
294 M3G_API M3Gfloat m3gGetPosition(M3GAnimationController hController, M3Gint worldTime)
296 AnimationController *controller = (AnimationController *) hController;
297 M3G_VALIDATE_OBJECT(controller);
299 return m3gAdd(controller->refSequenceTime,
300 m3gMul(controller->speed, (M3Gfloat) worldTime - controller->refWorldTime));
305 * \brief Set controller weight.
307 * \param hController AnimationController object
308 * \param weight controller weight
310 M3G_API void m3gSetWeight(M3GAnimationController hController, M3Gfloat weight)
312 AnimationController *controller = (AnimationController *) hController;
313 M3G_VALIDATE_OBJECT(controller);
316 m3gRaiseError(M3G_INTERFACE(controller), M3G_INVALID_VALUE);
319 controller->weight = weight;
323 * \brief Get controller weight.
325 * \param hController AnimationController object
326 * \return controller weight
328 M3G_API M3Gfloat m3gGetWeight(M3GAnimationController hController)
330 AnimationController *controller = (AnimationController *) hController;
331 M3G_VALIDATE_OBJECT(controller);
333 return controller->weight;
337 * \brief Get reference world time.
339 * \param hController AnimationController object
340 * \return reference world time
342 M3G_API M3Gint m3gGetRefWorldTime(M3GAnimationController hController)
344 AnimationController *controller = (AnimationController *) hController;
345 M3G_VALIDATE_OBJECT(controller);
347 return controller->refWorldTime;