PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: GraphPath.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 __PLMATH_GRAPH_PATH_H__ 00024 #define __PLMATH_GRAPH_PATH_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Container/Resource.h> 00032 #include "PLMath/Vector3.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLMath { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Forward declarations ] 00043 //[-------------------------------------------------------] 00044 class Graph; 00045 class GraphNode; 00046 00047 00048 //[-------------------------------------------------------] 00049 //[ Classes ] 00050 //[-------------------------------------------------------] 00051 /** 00052 * @brief 00053 * A path can be set of links to graph nodes or owning it's own private nodes 00054 */ 00055 class GraphPath : public PLCore::Resource<GraphPath> { 00056 00057 00058 //[-------------------------------------------------------] 00059 //[ Public functions ] 00060 //[-------------------------------------------------------] 00061 public: 00062 //[-------------------------------------------------------] 00063 //[ Main ] 00064 //[-------------------------------------------------------] 00065 /** 00066 * @brief 00067 * Constructor 00068 * 00069 * @param[in] sName 00070 * Resource name to set 00071 * @param[in] pManager 00072 * Resource manager using this resource, can be a null pointer 00073 */ 00074 PLMATH_API GraphPath(const PLCore::String &sName, PLCore::ResourceManager<GraphPath> *pManager = nullptr); 00075 00076 /** 00077 * @brief 00078 * Constructor 00079 * 00080 * @param[in] pOwnerGraph 00081 * Owner graph, if a null pointer the path has it's own private nodes 00082 * 00083 * @note 00084 * - A path is linking to graph nodes if it's created from for instance 00085 * Graph::FindShortestPath() 00086 */ 00087 PLMATH_API GraphPath(Graph *pOwnerGraph = nullptr); 00088 00089 /** 00090 * @brief 00091 * Destructor 00092 */ 00093 PLMATH_API virtual ~GraphPath(); 00094 00095 /** 00096 * @brief 00097 * Returns the owner graph of the path 00098 * 00099 * @return 00100 * Owner graph of the path, a null pointer if the path is independent 00101 */ 00102 PLMATH_API Graph *GetOwnerGraph() const; 00103 00104 //[-------------------------------------------------------] 00105 //[ Nodes ] 00106 //[-------------------------------------------------------] 00107 /** 00108 * @brief 00109 * Returns the number of nodes 00110 * 00111 * @return 00112 * Number of path nodes 00113 */ 00114 PLMATH_API PLCore::uint32 GetNumOfNodes() const; 00115 00116 /** 00117 * @brief 00118 * Adds a node 00119 * 00120 * @param[in] cNode 00121 * Node which should be added, if the path has no owner 00122 * graph it will delete the node after it is no longer required. 00123 * 00124 * @return 00125 * 'true' if all went fine, else 'false' 00126 */ 00127 PLMATH_API bool AddNode(GraphNode &cNode); 00128 00129 /** 00130 * @brief 00131 * Removes a node 00132 * 00133 * @param[in] nNode 00134 * ID of the node which should be removed 00135 * 00136 * @return 00137 * 'true' if all went fine, else 'false' 00138 */ 00139 PLMATH_API bool RemoveNode(PLCore::uint32 nNode = 0); 00140 00141 /** 00142 * @brief 00143 * Returns a node 00144 * 00145 * @param[in] nID 00146 * ID of the node which should be returned 00147 * 00148 * @return 00149 * The path node, a null pointer if there was an error 00150 */ 00151 PLMATH_API const GraphNode *GetNode(PLCore::uint32 nID = 0) const; 00152 00153 /** 00154 * @brief 00155 * Returns a node 00156 * 00157 * @param[in] nID 00158 * ID of the node which should be returned 00159 * 00160 * @return 00161 * The path node, a null pointer if there was an error 00162 */ 00163 PLMATH_API GraphNode *GetNode(PLCore::uint32 nID = 0); 00164 00165 //[-------------------------------------------------------] 00166 //[ Tools ] 00167 //[-------------------------------------------------------] 00168 /** 00169 * @brief 00170 * Returns the length of the path 00171 * 00172 * @return 00173 * Path length 00174 */ 00175 PLMATH_API float GetLength() const; 00176 00177 /** 00178 * @brief 00179 * Returns whether the path is closed or not 00180 * 00181 * @return 00182 * 'true' if the path is closed, else 'false' 00183 * 00184 * @note 00185 * - If a path is closed the first node is taken after the last one 00186 */ 00187 PLMATH_API bool IsClosed() const; 00188 00189 /** 00190 * @brief 00191 * Sets if the path is closed or not 00192 * 00193 * @param[in] bClosed 00194 * Should the path be closed? 00195 * 00196 * @see 00197 * - IsClosed() 00198 */ 00199 PLMATH_API void SetClosed(bool bClosed = false); 00200 00201 /** 00202 * @brief 00203 * Calculates the position at the given node index 00204 * 00205 * @param[in] fNodeIndex 00206 * Node index (0-<number of nodes>, automatically wrapped into that range) 00207 * @param[in] bLinear 00208 * Linear interpolation? Else a catmull rom curve is used. 00209 * 00210 * @return 00211 * The path position corresponding to the given node index 00212 * 00213 * @remarks 00214 * If the position isn't linear interpolated the first and last node are skipped. 00215 * (only required for the curve progression) 00216 * Therefore at node index 0 the position will be the position node 2. 00217 */ 00218 PLMATH_API Vector3 GetPosByNodeIndex(float fNodeIndex, bool bLinear = true) const; 00219 00220 /** 00221 * @brief 00222 * Calculates the position by using percentage along the path 00223 * 00224 * @param[in] fPercentageAlongPath 00225 * Percentage along the path (0-1, automatically wrapped into that range) 00226 * @param[in] bLinear 00227 * Linear interpolation? Else a catmull rom curve is used. 00228 * 00229 * @return 00230 * The path position corresponding to the given percentage along the path 00231 * 00232 * @remarks 00233 * If the position isn't linear interpolated the first and last node are skipped. 00234 * (only required for the curve progression) 00235 * Therefore at node index 0 the position will be the position node 2. 00236 */ 00237 PLMATH_API Vector3 GetPosByPercentageAlongPath(float fPercentageAlongPath, bool bLinear = true) const; 00238 00239 00240 //[-------------------------------------------------------] 00241 //[ Private data ] 00242 //[-------------------------------------------------------] 00243 private: 00244 Graph *m_pOwnerGraph; /**< Owner graph, can be a null pointer */ 00245 bool m_bClosed; /**< Is the path closed? */ 00246 PLCore::Array<GraphNode*> m_lstNodes; /**< Node list */ 00247 00248 00249 //[-------------------------------------------------------] 00250 //[ Public virtual PLCore::Resource functions ] 00251 //[-------------------------------------------------------] 00252 public: 00253 PLMATH_API virtual GraphPath &operator =(const GraphPath &cSource); 00254 00255 00256 //[-------------------------------------------------------] 00257 //[ Public virtual PLCore::Loadable functions ] 00258 //[-------------------------------------------------------] 00259 public: 00260 PLMATH_API virtual bool Unload() override; 00261 PLMATH_API virtual PLCore::String GetLoadableTypeName() const override; 00262 00263 00264 }; 00265 00266 00267 //[-------------------------------------------------------] 00268 //[ Namespace ] 00269 //[-------------------------------------------------------] 00270 } // PLMath 00271 00272 00273 #endif // __PLMATH_GRAPH_PATH_H__
|