root/trunk/src/game/Path.h @ 9

Revision 2, 2.8 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef MANGOSSERVER_PATH_H
20#define MANGOSSERVER_PATH_H
21
22#include "Common.h"
23#include <vector>
24
25class Path
26{
27    public:
28        struct PathNode
29        {
30            float x,y,z;
31        };
32
33        void SetLength(const unsigned int sz)
34        {
35            i_nodes.resize( sz );
36        }
37
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
45        {
46            float len = 0, xd, yd, zd;
47            for(unsigned int idx=start+1; idx < end; ++idx)
48            {
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 );
53            }
54            return len;
55        }
56
57        float GetPassedLength(uint32 curnode, float x, float y, float z)
58        {
59            float len = 0, xd, yd, zd;
60            for(unsigned int idx=1; idx < curnode; ++idx)
61            {
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 );
66            }
67
68            if(curnode > 0)
69            {
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 );
74            }
75
76            return len;
77        }
78
79        PathNode& operator[](const unsigned int idx) { return i_nodes[idx]; }
80        const PathNode& operator()(const unsigned int idx) const { return i_nodes[idx]; }
81
82    protected:
83        std::vector<PathNode> i_nodes;
84};
85#endif
Note: See TracBrowser for help on using the browser.