PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Animation.h * 00003 * 00004 * Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLRENDERER_ANIMATION_H__ 00024 #define __PLRENDERER_ANIMATION_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Base/Event/Event.h> 00032 #include <PLCore/Container/Element.h> 00033 #include "PLRenderer/PLRenderer.h" 00034 00035 00036 //[-------------------------------------------------------] 00037 //[ Namespace ] 00038 //[-------------------------------------------------------] 00039 namespace PLRenderer { 00040 00041 00042 //[-------------------------------------------------------] 00043 //[ Forward declarations ] 00044 //[-------------------------------------------------------] 00045 class AnimationInfo; 00046 class AnimationManager; 00047 00048 00049 //[-------------------------------------------------------] 00050 //[ Classes ] 00051 //[-------------------------------------------------------] 00052 /** 00053 * @brief 00054 * Animation control 00055 */ 00056 class Animation : public PLCore::Element<Animation> { 00057 00058 00059 //[-------------------------------------------------------] 00060 //[ Public definitions ] 00061 //[-------------------------------------------------------] 00062 public: 00063 /** 00064 * @brief 00065 * Animation flags 00066 */ 00067 enum EFlags { 00068 Loop = 1<<0, /**< Loop animation */ 00069 PingPong = 1<<1 /**< Ping pong animation */ 00070 }; 00071 00072 00073 //[-------------------------------------------------------] 00074 //[ Events ] 00075 //[-------------------------------------------------------] 00076 public: 00077 PLCore::Event<> EventStart; /**< Animation has been started */ 00078 PLCore::Event<> EventStop; /**< Animation has been stopped */ 00079 PLCore::Event<> EventFrameChange; /**< Current frame change event */ 00080 PLCore::Event<int> EventSpecialFrame; /**< Special marked frame reached event, event ID as parameter (see 'AnimationEvent') */ 00081 00082 00083 //[-------------------------------------------------------] 00084 //[ Public functions ] 00085 //[-------------------------------------------------------] 00086 public: 00087 /** 00088 * @brief 00089 * Constructor 00090 * 00091 * @param[in] sName 00092 * Element name to set 00093 * @param[in] pManager 00094 * Animation manager using this element, can be a null pointer 00095 */ 00096 PLRENDERER_API Animation(const PLCore::String &sName = "", AnimationManager *pManager = nullptr); 00097 00098 /** 00099 * @brief 00100 * Destructor 00101 */ 00102 PLRENDERER_API virtual ~Animation(); 00103 00104 /** 00105 * @brief 00106 * Resets the animation 00107 */ 00108 PLRENDERER_API void Reset(); 00109 00110 /** 00111 * @brief 00112 * Get the animation active status 00113 * 00114 * @return 00115 * 'true' if the animation is active, else 'false' 00116 */ 00117 inline bool IsActive() const; 00118 00119 /** 00120 * @brief 00121 * Set the animation active status 00122 * 00123 * @param[in] bActive 00124 * Should the animation be active? 00125 * 00126 * @note 00127 * - If an animation is inactive it is ignored 00128 */ 00129 inline void SetActive(bool bActive = true); 00130 00131 /** 00132 * @brief 00133 * Type of animation 00134 * 00135 * @return 00136 * Animation type (for instance 0=skeleton 1=vertex) 00137 */ 00138 inline PLCore::uint32 GetType() const; 00139 00140 /** 00141 * @brief 00142 * Sets the animation type 00143 * 00144 * @param[in] nType 00145 * Animation type (for instance 0=skeleton 1=vertex) 00146 */ 00147 inline void SetType(PLCore::uint32 nType = 0); 00148 00149 /** 00150 * @brief 00151 * Starts an animation 00152 * 00153 * @param[in] nStart 00154 * Start frame (inclusive) 00155 * @param[in] nEnd 00156 * End frame (inclusive) 00157 * @param[in] fSpeed 00158 * Animation speed, if negative, the animation is played reversed 00159 * @param[in] nFlags 00160 * Animation flags (see EFlags) 00161 * 00162 * @note 00163 * - Use the start function below which accepts a AnimationInfo 00164 * as parameter for more complex animations 00165 */ 00166 PLRENDERER_API void Start(PLCore::uint32 nStart, PLCore::uint32 nEnd, float fSpeed = 24.0f, PLCore::uint32 nFlags = 0); 00167 00168 /** 00169 * @brief 00170 * Starts an animation 00171 * 00172 * @param[in] cAnimationInfo 00173 * The animation information 00174 * @param[in] bRestart 00175 * Restart animation if it is already currently played? 00176 * 00177 * @note 00178 * - cAnimationInfo must stay a valid reference as long as the animation is played! 00179 * - Because events are stored in the animation information it's possible that events 00180 * are caused during the animation playback if an scene node is set 00181 */ 00182 PLRENDERER_API void Start(AnimationInfo &cAnimationInfo, bool bRestart = false); 00183 00184 /** 00185 * @brief 00186 * Stops the animation 00187 */ 00188 PLRENDERER_API void Stop(); 00189 00190 /** 00191 * @brief 00192 * Pause the animation 00193 */ 00194 inline void Pause(); 00195 00196 /** 00197 * @brief 00198 * Continues the animation 00199 */ 00200 inline void Continue(); 00201 00202 /** 00203 * @brief 00204 * Returns the animation information 00205 * 00206 * @return 00207 * Animation information, a null pointer if there's no one 00208 */ 00209 inline AnimationInfo *GetAnimation() const; 00210 00211 /** 00212 * @brief 00213 * Gets the animation weight 00214 * 00215 * @return 00216 * Animation weight (normally 0.0-1.0) 00217 */ 00218 inline float GetWeight() const; 00219 00220 /** 00221 * @brief 00222 * Sets the animation weight 00223 * 00224 * @param[in] fWeight 00225 * Animation weight (normally 0.0-1.0) 00226 */ 00227 inline void SetWeight(float fWeight = 1.0f); 00228 00229 /** 00230 * @brief 00231 * Get the animation speed 00232 * 00233 * @return 00234 * Current speed of the animation, if negative, the animation is played reversed 00235 */ 00236 inline float GetSpeed() const; 00237 00238 /** 00239 * @brief 00240 * Set the animation speed 00241 * 00242 * @param[in] fSpeed 00243 * New speed for the animation, if negative, the animation is played reversed 00244 */ 00245 inline void SetSpeed(float fSpeed = 24.0f); 00246 00247 /** 00248 * @brief 00249 * Get the animation information flags 00250 * 00251 * @return 00252 * Animation information flags (see EFlags) 00253 */ 00254 inline PLCore::uint32 GetFlags() const; 00255 00256 /** 00257 * @brief 00258 * Sets the animation information flags 00259 * 00260 * @param[in] nFlags 00261 * Animation information flags (see EFlags) 00262 */ 00263 inline void SetFlags(PLCore::uint32 nFlags = 0); 00264 00265 /** 00266 * @brief 00267 * Get the animation running status 00268 * 00269 * @return 00270 * 'true' if the animation is currently running, else 'false' 00271 */ 00272 inline bool IsRunning() const; 00273 00274 /** 00275 * @brief 00276 * Returns the start frame 00277 * 00278 * @return 00279 * The start frame (inclusive) 00280 */ 00281 inline PLCore::uint32 GetStartFrame() const; 00282 00283 /** 00284 * @brief 00285 * Returns the end frame 00286 * 00287 * @return 00288 * The end frame (inclusive) 00289 */ 00290 inline PLCore::uint32 GetEndFrame() const; 00291 00292 /** 00293 * @brief 00294 * Returns the number of frames 00295 * 00296 * @return 00297 * The number of frames 00298 */ 00299 inline PLCore::uint32 GetNumOfFrames() const; 00300 00301 /** 00302 * @brief 00303 * Get the current animation frame 00304 * 00305 * @return 00306 * Current animation frame (for instance 2.6) 00307 */ 00308 PLRENDERER_API float GetFrame() const; 00309 00310 /** 00311 * @brief 00312 * Gets the progress from the current state to the next state (0.0-1.0) 00313 * 00314 * @return 00315 * Current animation frame (for instance 0.6) 00316 */ 00317 PLRENDERER_API float GetProgress() const; 00318 00319 /** 00320 * @brief 00321 * Get the current animation frame as an integer 00322 * 00323 * @return 00324 * Current animation frame as an integer 00325 * 00326 * @note 00327 * - This function returns an integer for the current animation frame, e.g. if the 00328 * animation frame is at 2.6f, it will return 2 00329 */ 00330 PLRENDERER_API PLCore::uint32 GetCurrentFrame() const; 00331 00332 /** 00333 * @brief 00334 * Set the current animation frame 00335 * 00336 * @param[in] fFrame 00337 * Current animation frame 00338 * 00339 * @note 00340 * - If the given frame is out of bounds, it's clamped automatically 00341 */ 00342 PLRENDERER_API void SetCurrentFrame(float fFrame); 00343 00344 /** 00345 * @brief 00346 * Get the next animation frame as an integer 00347 * 00348 * @return 00349 * Next animation frame as an integer 00350 * 00351 * @see 00352 * - GetCurrentFrame() 00353 */ 00354 PLRENDERER_API PLCore::uint32 GetNextFrame() const; 00355 00356 /** 00357 * @brief 00358 * Updates the animation 00359 * 00360 * @param[in] fTimeDifference 00361 * Past time since last frame (use e.g. PLCore::Timing::GetInstance()->GetTimeDifference()) 00362 */ 00363 PLRENDERER_API void Update(float fTimeDifference); 00364 00365 /** 00366 * @brief 00367 * Returns whether animation events are enabled or not 00368 * 00369 * @return 00370 * 'true' if animation events are enabled, else 'false' 00371 * 00372 * @note 00373 * - If animation events are enabled special frames are able to send 00374 * an event message to the scene node connected with the animation 00375 */ 00376 inline bool GetEvents() const; 00377 00378 /** 00379 * @brief 00380 * Sets whether animation events are enabled or not 00381 * 00382 * @param[in] bEvents 00383 * Are animation events enabled? 00384 * 00385 * @see 00386 * - GetEvents() 00387 */ 00388 inline void SetEvents(bool bEvents = true); 00389 00390 //[-------------------------------------------------------] 00391 //[ Operators ] 00392 //[-------------------------------------------------------] 00393 PLRENDERER_API Animation &operator =(const Animation &cSource); 00394 00395 00396 //[-------------------------------------------------------] 00397 //[ Private functions ] 00398 //[-------------------------------------------------------] 00399 private: 00400 /** 00401 * @brief 00402 * Check if events should be caused 00403 * 00404 * @param[in] nPreviousFrame 00405 * Previous frame 00406 * 00407 * @note 00408 * - An event is caused if the current frame isn't equal to 00409 * the previous and if there is an scene node receiving the caused event 00410 */ 00411 void CheckEvent(int nPreviousFrame = -1) const; 00412 00413 00414 //[-------------------------------------------------------] 00415 //[ Private data ] 00416 //[-------------------------------------------------------] 00417 private: 00418 float m_fFrame; /**< Current animation frame */ 00419 bool m_bActive; /**< Active status (if the channel is used in calculations) */ 00420 bool m_bRunning; /**< Running status */ 00421 PLCore::uint32 m_nType; /**< Animation type (for instance 0=skeleton, 1=vertex) */ 00422 PLCore::uint32 m_nFlags; /**< Animation flags */ 00423 PLCore::uint32 m_nStart; /**< Start frame of the animation */ 00424 PLCore::uint32 m_nEnd; /**< End frame of the animation */ 00425 float m_fSpeed; /**< Playback speed */ 00426 bool m_bEvents; /**< Are animation events enabled? */ 00427 AnimationInfo *m_pAnimationInfo; /**< Pointer to the animation information, can be a null pointer */ 00428 float m_fWeight; /**< Animation weight */ 00429 bool m_bBounced; /**< If ping pong playback, was there already a 'bounce'? */ 00430 00431 00432 }; 00433 00434 00435 //[-------------------------------------------------------] 00436 //[ Namespace ] 00437 //[-------------------------------------------------------] 00438 } // PLRenderer 00439 00440 00441 //[-------------------------------------------------------] 00442 //[ Implementation ] 00443 //[-------------------------------------------------------] 00444 #include "PLRenderer/Animation/Animation.inl" 00445 00446 00447 #endif // __PLRENDERER_ANIMATION_H__
|