Files
TCPlayerbotCore/src/game/Path.h
T

89 lines
2.9 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* 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
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* 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, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
2008-10-02 16:23:55 -05:00
class Path
{
public:
struct PathNode
{
float x,y,z;
};
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void SetLength(const unsigned int sz)
{
2010-04-07 22:59:46 +02:00
i_nodes.resize(sz);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
unsigned int Size() const { return i_nodes.size(); }
bool Empty() const { return i_nodes.empty(); }
void Resize(unsigned int sz) { i_nodes.resize(sz); }
void Clear(void) { i_nodes.clear(); }
PathNode const* GetNodes(uint32 start = 0) const { return &i_nodes[start]; }
float GetTotalLength() const { return GetTotalLength(0,Size()); }
float GetTotalLength(uint32 start, uint32 end) const
{
float len = 0, xd, yd, zd;
2009-10-17 16:20:24 -07:00
for (unsigned int idx=start+1; idx < end; ++idx)
2008-10-02 16:23:55 -05:00
{
xd = i_nodes[ idx ].x - i_nodes[ idx-1 ].x;
yd = i_nodes[ idx ].y - i_nodes[ idx-1 ].y;
zd = i_nodes[ idx ].z - i_nodes[ idx-1 ].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;
}
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)
{
float len = 0, xd, yd, zd;
2009-10-17 16:20:24 -07:00
for (unsigned int idx=1; idx < curnode; ++idx)
2008-10-02 16:23:55 -05:00
{
xd = i_nodes[ idx ].x - i_nodes[ idx-1 ].x;
yd = i_nodes[ idx ].y - i_nodes[ idx-1 ].y;
zd = i_nodes[ idx ].z - i_nodes[ idx-1 ].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
2010-04-07 19:14:10 +02:00
if (curnode > 0)
2008-10-02 16:23:55 -05:00
{
xd = x - i_nodes[curnode-1].x;
yd = y - i_nodes[curnode-1].y;
zd = z - i_nodes[curnode-1].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
2008-10-02 16:23:55 -05:00
PathNode& operator[](const unsigned int idx) { return i_nodes[idx]; }
const PathNode& operator()(const unsigned int idx) const { return i_nodes[idx]; }
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
protected:
std::vector<PathNode> i_nodes;
};
#endif
2009-02-17 20:07:49 -06:00