PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: SkeletonHandler.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 __PLMESH_SKELETONHANDLER_H__ 00024 #define __PLMESH_SKELETONHANDLER_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Container/Array.h> 00032 #include <PLCore/Container/ResourceHandler.h> 00033 #include "PLMesh/Joint.h" 00034 #include "PLMesh/Skeleton.h" 00035 #include "PLMesh/JointHandler.h" 00036 00037 00038 //[-------------------------------------------------------] 00039 //[ Forward declarations ] 00040 //[-------------------------------------------------------] 00041 namespace PLGraphics { 00042 class Color4; 00043 } 00044 namespace PLRenderer { 00045 class Font; 00046 class Renderer; 00047 } 00048 00049 00050 //[-------------------------------------------------------] 00051 //[ Namespace ] 00052 //[-------------------------------------------------------] 00053 namespace PLMesh { 00054 00055 00056 //[-------------------------------------------------------] 00057 //[ Classes ] 00058 //[-------------------------------------------------------] 00059 /** 00060 * @brief 00061 * Skeleton handler code 00062 * 00063 * @remarks 00064 * @verbatim 00065 * Skeleton handler animation example:\n 00066 * ResetJointStates(); // Reset current joint states\n 00067 * ApplyJointStates(2, 3, 0.5f); // Apply frame 2.5 of the skeleton animation to the current joint states\n 00068 * ApplyJointStates(cRun); // Apply the current joint states of the skeleton animation handler\n 00069 * // cRun to the current joint states. Note that we want to add the delta \n 00070 * // values from cRun, so, within this handler the base joint states are NOT added!\n 00071 * ApplyBaseJointStates(); // Apply base joint states to get the final pose\n 00072 * CalculateStates(); // Complete the current joint states 00073 * @endverbatim 00074 */ 00075 class SkeletonHandler : public PLCore::ResourceHandler<Skeleton> { 00076 00077 00078 //[-------------------------------------------------------] 00079 //[ Public functions ] 00080 //[-------------------------------------------------------] 00081 public: 00082 /** 00083 * @brief 00084 * Constructor 00085 */ 00086 PLMESH_API SkeletonHandler(); 00087 00088 /** 00089 * @brief 00090 * Destructor 00091 */ 00092 PLMESH_API virtual ~SkeletonHandler(); 00093 00094 /** 00095 * @brief 00096 * Draws the joints 00097 * 00098 * @param[in] cRenderer 00099 * Renderer to use 00100 * @param[in] cColor 00101 * Color to use 00102 * @param[in] mWorldViewProjection 00103 * World view projection matrix to use 00104 * @param[in] fPointSize 00105 * Point size 00106 */ 00107 PLMESH_API void DrawJoints(PLRenderer::Renderer &cRenderer, const PLGraphics::Color4 &cColor, const PLMath::Matrix4x4 &mWorldViewProjection, float fPointSize = 1.0f) const; 00108 00109 /** 00110 * @brief 00111 * Draws the joint names 00112 * 00113 * @param[in] cFont 00114 * Font to use 00115 * @param[in] cColor 00116 * Color to use 00117 * @param[in] mWorldViewProjection 00118 * World view projection matrix to use 00119 */ 00120 PLMESH_API void DrawJointNames(PLRenderer::Font &cFont, const PLGraphics::Color4 &cColor, const PLMath::Matrix4x4 &mWorldViewProjection) const; 00121 00122 /** 00123 * @brief 00124 * Draws the skeleton 00125 * 00126 * @param[in] cRenderer 00127 * Renderer to use 00128 * @param[in] cColor 00129 * Color to use 00130 * @param[in] mWorldViewProjection 00131 * World view projection matrix to use 00132 * @param[in] fLineWidth 00133 * Line width 00134 */ 00135 PLMESH_API void DrawSkeleton(PLRenderer::Renderer &cRenderer, const PLGraphics::Color4 &cColor, const PLMath::Matrix4x4 &mWorldViewProjection, float fLineWidth = 1.0f) const; 00136 00137 //[-------------------------------------------------------] 00138 //[ Joint states ] 00139 //[-------------------------------------------------------] 00140 /** 00141 * @brief 00142 * Returns the current joint handlers 00143 * 00144 * @return 00145 * Current joint handlers 00146 */ 00147 PLMESH_API PLCore::Array<JointHandler> &GetJointHandlers(); 00148 PLMESH_API const PLCore::Array<JointHandler> &GetJointHandlers() const; 00149 00150 /** 00151 * @brief 00152 * Returns a joint handler by name 00153 * 00154 * @param[in] sJointName 00155 * Name of the joint to return the handler from 00156 * 00157 * @return 00158 * Joint handler, a null pointer on error 00159 */ 00160 PLMESH_API JointHandler *GetJointHandler(const PLCore::String &sJointName) const; 00161 00162 /** 00163 * @brief 00164 * Returns the base joint handlers 00165 * 00166 * @return 00167 * Base joint handlers 00168 */ 00169 PLMESH_API PLCore::Array<JointHandler> &GetBaseJointHandlers(); 00170 00171 /** 00172 * @brief 00173 * Returns a base joint handler by name 00174 * 00175 * @param[in] sJointName 00176 * Name of the base joint to return the handler from 00177 * 00178 * @return 00179 * Base joint handler, a null pointer on error 00180 */ 00181 PLMESH_API JointHandler *GetBaseJointHandler(const PLCore::String &sJointName) const; 00182 00183 /** 00184 * @brief 00185 * Resets all current joint states 00186 * 00187 * @param[in] bForceAll 00188 * If 'true', user controlled joints are reset, too 00189 * 00190 * @return 00191 * 'true' if all went fine, else 'false' (maybe no skeleton set?) 00192 */ 00193 PLMESH_API bool ResetJointStates(bool bForceAll = false); 00194 00195 /** 00196 * @brief 00197 * Resets all base joint states to the skeleton 'orginal' base joint states 00198 * 00199 * @return 00200 * 'true' if all went fine, else 'false' (maybe no skeleton set?) 00201 */ 00202 PLMESH_API bool ResetBaseJointStates(); 00203 00204 /** 00205 * @brief 00206 * Applies the joint states from the given skeleton animation frame 00207 * to the current joint states 00208 * 00209 * @param[in] nFrame 00210 * Skeleton animation frame 00211 * @param[in] fWeight 00212 * Weight (0.0-1.0) 00213 * 00214 * @return 00215 * 'true' if all went fine, else 'false' (maybe no skeleton set?) 00216 */ 00217 PLMESH_API bool ApplyJointStates(PLCore::uint32 nFrame, float fWeight = 1.0f); 00218 00219 /** 00220 * @brief 00221 * Applies the blended joint states from the given joint animation frames 00222 * to the current joint states 00223 * 00224 * @param[in] nFrame1 00225 * Skeleton animation frame 1 00226 * @param[in] nFrame2 00227 * Skeleton animation frame 2 00228 * @param[in] fTime 00229 * Skeleton animation time (0.0-1.0) 00230 * @param[in] fWeight 00231 * Weight (0.0-1.0) 00232 * 00233 * @return 00234 * 'true' if all went fine, else 'false' (maybe no skeleton set?) 00235 */ 00236 PLMESH_API bool ApplyJointStates(PLCore::uint32 nFrame1, PLCore::uint32 nFrame2, float fTime, float fWeight = 1.0f); 00237 00238 /** 00239 * @brief 00240 * Applies the current joint states from the given joint handler 00241 * to the current joint states 00242 * 00243 * @param[in] cSkeletonHandler 00244 * Skeleton handler to use 00245 * @param[in] fWeight 00246 * Weight (0.0-1.0) 00247 * 00248 * @return 00249 * 'true' if all went fine, else 'false' (maybe no skeleton set?) 00250 * 00251 * @note 00252 * - In order to apply the pSkeletonHandler joint states correctly, it should 00253 * only consist of deltas. (ApplyBaseJointStates() not done...) 00254 */ 00255 PLMESH_API bool ApplyJointStates(SkeletonHandler &cSkeletonHandler, float fWeight = 1.0f); 00256 00257 /** 00258 * @brief 00259 * Applies the base joint states to the current joint states 00260 * 00261 * @return 00262 * 'true' if all went fine, else 'false' (maybe no skeleton set?) 00263 */ 00264 PLMESH_API bool ApplyBaseJointStates(); 00265 00266 /** 00267 * @brief 00268 * Calculates all current absolute joint states 00269 * 00270 * @return 00271 * 'true' if all went fine, else 'false' (maybe no skeleton set?) 00272 * 00273 * @note 00274 * - Before applying this skeleton handler on for instance a mesh you have to call 00275 * this function to calculate all current absolute joint states! 00276 */ 00277 PLMESH_API bool CalculateStates(); 00278 00279 00280 //[-------------------------------------------------------] 00281 //[ Private functions ] 00282 //[-------------------------------------------------------] 00283 private: 00284 /** 00285 * @brief 00286 * Recursive joint state calculations 00287 * 00288 * @param[in] cJointHandler 00289 * Current joint handler to process 00290 * @param[in] pParentJointHandler 00291 * Current parent joint handler to process, can be a null pointer 00292 */ 00293 void RecCalculateStates(JointHandler &cJointHandler, JointHandler *pParentJointHandler = nullptr); 00294 00295 00296 //[-------------------------------------------------------] 00297 //[ Private data ] 00298 //[-------------------------------------------------------] 00299 private: 00300 PLCore::Array<JointHandler> m_lstBaseJointHandlers; /**< Base joint handlers */ 00301 PLCore::Array<JointHandler> m_lstJointHandlers; /**< Current joint handlers */ 00302 00303 00304 //[-------------------------------------------------------] 00305 //[ Public virtual PLCore::ResourceHandler functions ] 00306 //[-------------------------------------------------------] 00307 public: 00308 PLMESH_API virtual bool SetResource(Skeleton *pResource = nullptr) override; 00309 00310 00311 }; 00312 00313 00314 //[-------------------------------------------------------] 00315 //[ Namespace ] 00316 //[-------------------------------------------------------] 00317 } // PLMesh 00318 00319 00320 #endif // __PLMESH_SKELETONHANDLER_H__
|