PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: SNMPositionPath.h * 00003 * 00004 * Copyright (C) 2002-2012 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 __PLSCENE_SCENENODEMODIFIER_POSITIONPATH_H__ 00024 #define __PLSCENE_SCENENODEMODIFIER_POSITIONPATH_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Base/Event/EventHandler.h> 00032 #include "PLScene/Scene/SceneNodeModifiers/SNMTransform.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Forward declarations ] 00037 //[-------------------------------------------------------] 00038 namespace PLMath { 00039 class GraphPath; 00040 class GraphPathHandler; 00041 } 00042 namespace PLRenderer { 00043 class Renderer; 00044 } 00045 namespace PLScene { 00046 class VisNode; 00047 } 00048 00049 00050 //[-------------------------------------------------------] 00051 //[ Namespace ] 00052 //[-------------------------------------------------------] 00053 namespace PLScene { 00054 00055 00056 //[-------------------------------------------------------] 00057 //[ Classes ] 00058 //[-------------------------------------------------------] 00059 /** 00060 * @brief 00061 * Scene node modifier class moving the position of a scene node along a given path 00062 * 00063 * @remarks 00064 * There are two major strategies how to move along a path: 00065 * - By giving the percentage along the whole path, 0-1. This is the default setting and has the 00066 * advantage that the movement speed is constant and not depend of the length of each path segment. 00067 * - By giving the percentage by node index, 0-<number of nodes>. By using this approach the movement 00068 * speed on the path may vary, this depends on whether or not all path segments have the same length. 00069 * Beside the major strategy, it's possible to set the interpolation type. 00070 */ 00071 class SNMPositionPath : public SNMTransform { 00072 00073 00074 //[-------------------------------------------------------] 00075 //[ Public definition ] 00076 //[-------------------------------------------------------] 00077 public: 00078 /** 00079 * @brief 00080 * Interpolation type 00081 */ 00082 enum EInterpolation { 00083 Linear = 0, /**< Linear interpolation */ 00084 CatmullRomCurve = 1 /**< Catmull rom curve interpolation */ 00085 }; 00086 pl_enum(EInterpolation) 00087 pl_enum_value(Linear, "Linear interpolation") 00088 pl_enum_value(CatmullRomCurve, "Catmull rom curve interpolation") 00089 pl_enum_end 00090 00091 /** 00092 * @brief 00093 * Scene node modifier flags (SceneNodeModifier flags extension) 00094 */ 00095 enum EFlags { 00096 NodeIndexProgress = 1<<2 /**< 'Progress' defined by 'node index' instead or 'percentage along path' */ 00097 }; 00098 pl_enum(EFlags) 00099 pl_enum_base(SNMTransform::EFlags) 00100 pl_enum_value(NodeIndexProgress, "'Progress' defined by 'node index' instead or 'percentage along path'") 00101 pl_enum_end 00102 00103 00104 //[-------------------------------------------------------] 00105 //[ RTTI interface ] 00106 //[-------------------------------------------------------] 00107 pl_class(PLS_RTTI_EXPORT, SNMPositionPath, "PLScene", PLScene::SNMTransform, "Scene node modifier class moving the position of a scene node along a given path") 00108 // Attributes 00109 pl_attribute(Filename, PLCore::String, "", ReadWrite, GetSet, "Filename of the path the node should move on", "Type='GraphPath'") 00110 pl_attribute(Progress, float, 0.0f, ReadWrite, DirectValue, "Path progress (0-1, automatically wrapped into that range -> or node index)", "") 00111 pl_attribute(Speed, float, 1.0f, ReadWrite, DirectValue, "Path movement speed", "") 00112 pl_attribute(Interpolation, pl_enum_type(EInterpolation), Linear, ReadWrite, DirectValue, "Interpolation type", "") 00113 // Overwritten SceneNodeModifier attributes 00114 pl_attribute(Flags, pl_flag_type(EFlags), 0, ReadWrite, GetSet, "Flags", "") 00115 // Constructors 00116 pl_constructor_1(ParameterConstructor, SceneNode&, "Parameter constructor", "") 00117 pl_class_end 00118 00119 00120 //[-------------------------------------------------------] 00121 //[ Public RTTI get/set functions ] 00122 //[-------------------------------------------------------] 00123 public: 00124 PLS_API PLCore::String GetFilename() const; 00125 PLS_API void SetFilename(const PLCore::String &sValue); 00126 00127 00128 //[-------------------------------------------------------] 00129 //[ Public functions ] 00130 //[-------------------------------------------------------] 00131 public: 00132 /** 00133 * @brief 00134 * Constructor 00135 * 00136 * @param[in] cSceneNode 00137 * Owner scene node 00138 */ 00139 PLS_API SNMPositionPath(SceneNode &cSceneNode); 00140 00141 /** 00142 * @brief 00143 * Destructor 00144 */ 00145 PLS_API virtual ~SNMPositionPath(); 00146 00147 /** 00148 * @brief 00149 * Returns the used graph path 00150 * 00151 * @return 00152 * The used graph path, can be a null pointer 00153 */ 00154 PLS_API PLMath::GraphPath *GetGraphPath() const; 00155 00156 00157 //[-------------------------------------------------------] 00158 //[ Protected virtual SceneNodeModifier functions ] 00159 //[-------------------------------------------------------] 00160 protected: 00161 PLS_API virtual void OnActivate(bool bActivate) override; 00162 00163 00164 //[-------------------------------------------------------] 00165 //[ Private functions ] 00166 //[-------------------------------------------------------] 00167 private: 00168 /** 00169 * @brief 00170 * Called when the scene node modifier needs to be updated 00171 */ 00172 void OnUpdate(); 00173 00174 /** 00175 * @brief 00176 * Called on scene node debug draw 00177 * 00178 * @param[in] cRenderer 00179 * The used renderer 00180 * @param[in] pVisNode 00181 * The current visibility node of this scene node, can be a null pointer 00182 */ 00183 void OnDrawDebug(PLRenderer::Renderer &cRenderer, const VisNode *pVisNode); 00184 00185 00186 //[-------------------------------------------------------] 00187 //[ Private event handlers ] 00188 //[-------------------------------------------------------] 00189 private: 00190 PLCore::EventHandler<> EventHandlerUpdate; 00191 PLCore::EventHandler<PLRenderer::Renderer &, const VisNode *> EventHandlerDrawDebug; 00192 00193 00194 //[-------------------------------------------------------] 00195 //[ Private data ] 00196 //[-------------------------------------------------------] 00197 private: 00198 // Exported variables 00199 PLCore::String m_sFilename; 00200 float m_fProgress; 00201 float m_fSpeed; 00202 PLCore::uint32 m_nInterpolation; 00203 00204 // Private data 00205 PLMath::GraphPathHandler *m_pPathHandler; /**< Our path (ALWAYS valid!) */ 00206 00207 00208 }; 00209 00210 00211 //[-------------------------------------------------------] 00212 //[ Namespace ] 00213 //[-------------------------------------------------------] 00214 } // PLScene 00215 00216 00217 #endif // __PLSCENE_SCENENODEMODIFIER_POSITIONPATH_H__
|