2010-10-07 12:41:56 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
|
|
|
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
* option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
|
* more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-10-02 16:23:55 -05:00
|
|
|
*/
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-14 11:57:03 -05:00
|
|
|
#ifndef TRINITYCORE_PATH_H
|
|
|
|
|
#define TRINITYCORE_PATH_H
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "Common.h"
|
|
|
|
|
#include <vector>
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-06-23 00:57:16 +02:00
|
|
|
struct SimplePathNode
|
|
|
|
|
{
|
|
|
|
|
float x, y, z;
|
|
|
|
|
};
|
|
|
|
|
template<typename PathElem, typename PathNode = PathElem>
|
|
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
class Path
|
|
|
|
|
{
|
|
|
|
|
public:
|
2010-06-23 00:57:16 +02:00
|
|
|
size_t size() const { return i_nodes.size(); }
|
|
|
|
|
bool empty() const { return i_nodes.empty(); }
|
|
|
|
|
void resize(unsigned int sz) { i_nodes.resize(sz); }
|
|
|
|
|
void clear() { i_nodes.clear(); }
|
|
|
|
|
void erase(uint32 idx) { i_nodes.erase(i_nodes.begin()+idx); }
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
float GetTotalLength(uint32 start, uint32 end) const
|
|
|
|
|
{
|
2010-06-23 00:57:16 +02:00
|
|
|
float len = 0.0f;
|
|
|
|
|
for (uint32 idx=start+1; idx < end; ++idx)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2010-06-23 00:57:16 +02:00
|
|
|
PathNode const& node = i_nodes[idx];
|
|
|
|
|
PathNode const& prev = i_nodes[idx-1];
|
|
|
|
|
float xd = node.x - prev.x;
|
|
|
|
|
float yd = node.y - prev.y;
|
|
|
|
|
float zd = node.z - prev.z;
|
2010-04-07 22:59:46 +02:00
|
|
|
len += sqrtf(xd*xd + yd*yd + zd*zd);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
|
|
|
|
return len;
|
|
|
|
|
}
|
2010-08-08 19:45:53 +02:00
|
|
|
|
2010-06-23 00:57:16 +02:00
|
|
|
float GetTotalLength() const { return GetTotalLength(0,size()); }
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
float GetPassedLength(uint32 curnode, float x, float y, float z)
|
|
|
|
|
{
|
2010-06-23 00:57:16 +02:00
|
|
|
float len = GetTotalLength(0,curnode);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-04-07 19:14:10 +02:00
|
|
|
if (curnode > 0)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2010-06-23 00:57:16 +02:00
|
|
|
PathNode const& node = i_nodes[curnode-1];
|
|
|
|
|
float xd = x - node.x;
|
|
|
|
|
float yd = y - node.y;
|
|
|
|
|
float zd = z - node.z;
|
2010-04-07 22:59:46 +02:00
|
|
|
len += sqrtf(xd*xd + yd*yd + zd*zd);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
return len;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-06-23 00:57:16 +02:00
|
|
|
PathNode& operator[](size_t idx) { return i_nodes[idx]; }
|
|
|
|
|
PathNode const& operator[](size_t idx) const { return i_nodes[idx]; }
|
2010-08-08 19:45:53 +02:00
|
|
|
|
2010-06-23 00:57:16 +02:00
|
|
|
void set(size_t idx, PathElem elem) { i_nodes[idx] = elem; }
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
protected:
|
2010-06-23 00:57:16 +02:00
|
|
|
std::vector<PathElem> i_nodes;
|
2008-10-02 16:23:55 -05:00
|
|
|
};
|
2010-06-23 00:57:16 +02:00
|
|
|
|
|
|
|
|
typedef Path<SimplePathNode> SimplePath;
|
|
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
#endif
|
2009-02-17 20:07:49 -06:00
|
|
|
|