1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef TRINITYCORE_PATH_H |
---|
22 | #define TRINITYCORE_PATH_H |
---|
23 | |
---|
24 | #include "Common.h" |
---|
25 | #include <vector> |
---|
26 | |
---|
27 | class Path |
---|
28 | { |
---|
29 | public: |
---|
30 | struct PathNode |
---|
31 | { |
---|
32 | float x,y,z; |
---|
33 | }; |
---|
34 | |
---|
35 | void SetLength(const unsigned int sz) |
---|
36 | { |
---|
37 | i_nodes.resize( sz ); |
---|
38 | } |
---|
39 | |
---|
40 | unsigned int Size() const { return i_nodes.size(); } |
---|
41 | bool Empty() const { return i_nodes.empty(); } |
---|
42 | void Resize(unsigned int sz) { i_nodes.resize(sz); } |
---|
43 | void Clear(void) { i_nodes.clear(); } |
---|
44 | PathNode const* GetNodes(uint32 start = 0) const { return &i_nodes[start]; } |
---|
45 | float GetTotalLength() const { return GetTotalLength(0,Size()); } |
---|
46 | float GetTotalLength(uint32 start, uint32 end) const |
---|
47 | { |
---|
48 | float len = 0, xd, yd, zd; |
---|
49 | for(unsigned int idx=start+1; idx < end; ++idx) |
---|
50 | { |
---|
51 | xd = i_nodes[ idx ].x - i_nodes[ idx-1 ].x; |
---|
52 | yd = i_nodes[ idx ].y - i_nodes[ idx-1 ].y; |
---|
53 | zd = i_nodes[ idx ].z - i_nodes[ idx-1 ].z; |
---|
54 | len += sqrtf( xd*xd + yd*yd + zd*zd ); |
---|
55 | } |
---|
56 | return len; |
---|
57 | } |
---|
58 | |
---|
59 | float GetPassedLength(uint32 curnode, float x, float y, float z) |
---|
60 | { |
---|
61 | float len = 0, xd, yd, zd; |
---|
62 | for(unsigned int idx=1; idx < curnode; ++idx) |
---|
63 | { |
---|
64 | xd = i_nodes[ idx ].x - i_nodes[ idx-1 ].x; |
---|
65 | yd = i_nodes[ idx ].y - i_nodes[ idx-1 ].y; |
---|
66 | zd = i_nodes[ idx ].z - i_nodes[ idx-1 ].z; |
---|
67 | len += sqrtf( xd*xd + yd*yd + zd*zd ); |
---|
68 | } |
---|
69 | |
---|
70 | if(curnode > 0) |
---|
71 | { |
---|
72 | xd = x - i_nodes[curnode-1].x; |
---|
73 | yd = y - i_nodes[curnode-1].y; |
---|
74 | zd = z - i_nodes[curnode-1].z; |
---|
75 | len += sqrtf( xd*xd + yd*yd + zd*zd ); |
---|
76 | } |
---|
77 | |
---|
78 | return len; |
---|
79 | } |
---|
80 | |
---|
81 | PathNode& operator[](const unsigned int idx) { return i_nodes[idx]; } |
---|
82 | const PathNode& operator()(const unsigned int idx) const { return i_nodes[idx]; } |
---|
83 | |
---|
84 | protected: |
---|
85 | std::vector<PathNode> i_nodes; |
---|
86 | }; |
---|
87 | #endif |
---|