2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOSSERVER_PATH_H
20 #define MANGOSSERVER_PATH_H
33 void SetLength(const unsigned int sz
)
38 unsigned int Size() const { return i_nodes
.size(); }
39 bool Empty() const { return i_nodes
.empty(); }
40 void Resize(unsigned int sz
) { i_nodes
.resize(sz
); }
41 void Clear(void) { i_nodes
.clear(); }
42 PathNode
const* GetNodes(uint32 start
= 0) const { return &i_nodes
[start
]; }
43 float GetTotalLength() const { return GetTotalLength(0,Size()); }
44 float GetTotalLength(uint32 start
, uint32 end
) const
46 float len
= 0, xd
, yd
, zd
;
47 for(unsigned int idx
=start
+1; idx
< end
; ++idx
)
49 xd
= i_nodes
[ idx
].x
- i_nodes
[ idx
-1 ].x
;
50 yd
= i_nodes
[ idx
].y
- i_nodes
[ idx
-1 ].y
;
51 zd
= i_nodes
[ idx
].z
- i_nodes
[ idx
-1 ].z
;
52 len
+= sqrtf( xd
*xd
+ yd
*yd
+ zd
*zd
);
57 float GetPassedLength(uint32 curnode
, float x
, float y
, float z
)
59 float len
= 0, xd
, yd
, zd
;
60 for(unsigned int idx
=1; idx
< curnode
; ++idx
)
62 xd
= i_nodes
[ idx
].x
- i_nodes
[ idx
-1 ].x
;
63 yd
= i_nodes
[ idx
].y
- i_nodes
[ idx
-1 ].y
;
64 zd
= i_nodes
[ idx
].z
- i_nodes
[ idx
-1 ].z
;
65 len
+= sqrtf( xd
*xd
+ yd
*yd
+ zd
*zd
);
70 xd
= x
- i_nodes
[curnode
-1].x
;
71 yd
= y
- i_nodes
[curnode
-1].y
;
72 zd
= z
- i_nodes
[curnode
-1].z
;
73 len
+= sqrtf( xd
*xd
+ yd
*yd
+ zd
*zd
);
79 PathNode
& operator[](const unsigned int idx
) { return i_nodes
[idx
]; }
80 const PathNode
& operator()(const unsigned int idx
) const { return i_nodes
[idx
]; }
83 std::vector
<PathNode
> i_nodes
;