Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MPath.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2012 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library 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 GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef MPATH_H
22 #define MPATH_H
23 
24 #include "MPoint.h"
25 
26 #include <vector>
27 
28 namespace OpenSkyNet {
29  namespace Math {
31  class Path {
32  bool _pathChanged;
33  Utils::uint _numPoints;
34  float _totalDist;
35  std::vector<Math::Point<> > _points;
37  std::vector<float> _dist;
38  public:
39  Path();
40 
41  inline Utils::uint getNumPoints() const { return _numPoints; }
42  inline std::vector<Math::Point<> >& getPoints() { return _points; }
43  inline const std::vector<Math::Point<> >& getPoints() const { return _points; }
44 
45  inline Utils::uint addAPoint(const Math::Point<>& aPoint_) {
46  _points.push_back(aPoint_);
47  if (_numPoints > 0) {
48  _dist.push_back((aPoint_ - _points[_numPoints-1]).getLength());
49  _totalDist += _dist[_numPoints-1];
50  }
51  ++_numPoints;
52  _pathChanged = true;
53  return (_numPoints - 1);
54  }
55 
56  inline Utils::uint addAPoint(float x_, float y_, float z_) { return addAPoint(Math::Point<>(x_,y_,z_)); }
57 
58  inline Utils::uint appendPath(const Path& path_) {
59  for (Utils::uint i = 0; i < path_.getNumPoints(); i++)
60  addAPoint(path_.getPoints()[i]);
61  return (_numPoints - 1);
62  }
63 
64  inline void clear() {
65  _points.clear();
66  _dist.clear();
67  _numPoints = 0;
68  _totalDist = 0;
69  _pathChanged = true;
70  }
71 
73  inline bool isPathChanged() {
74  if (_pathChanged) {
75  _pathChanged = false;
76  return true;
77  }
78  return false;
79  }
80 
81  inline void translate(const Math::Point<>& p_) {
82  for (Utils::uint i = 0; i < _numPoints; i++)
83  _points[i] = _points[i] + p_;
84  _pathChanged = true;
85  }
86 
94  void calcNaturalCubicSpline(float minDistanceBetweenPoints_=1.0, Utils::uint maxTotalPoints_=0, float tension_=0.0f);
95 
97  void calcDistances();
98 
99  inline float getTotalDist() const { return _totalDist; }
100 
107  Math::Point<> travelPercentOfPoints(const float& percent_) const;
108  Math::Point<> travelPercentOfDist(const float& percent_) const;
110 
114  float getAdditiveFromSpeed(float speed_) const { return speed_ / _totalDist; }
115  };
116  }
117 }
118 
119 #endif //MPATH_H
void clear()
Definition: MPath.h:64
Math::Point travelPercentOfPoints(const float &percent_) const
Definition: MPath.cpp:66
Utils::uint getNumPoints() const
Definition: MPath.h:41
void translate(const Math::Point<> &p_)
Definition: MPath.h:81
Utils::uint addAPoint(const Math::Point<> &aPoint_)
Definition: MPath.h:45
void calcNaturalCubicSpline(float minDistanceBetweenPoints_=1.0, Utils::uint maxTotalPoints_=0, float tension_=0.0f)
Definition: MPath.cpp:12
float getAdditiveFromSpeed(float speed_) const
Definition: MPath.h:114
void calcDistances()
Definition: MPath.cpp:54
const std::vector< Math::Point<> > & getPoints() const
Definition: MPath.h:43
bool isPathChanged()
Definition: MPath.h:73
unsigned int uint
Definition: UTypes.h:39
Definition: MPoint.h:33
T getLength(const Point< T > &lhs_, const Point< U > &rhs_)
Definition: MPoint.h:290
Path()
Definition: MPath.cpp:10
Math::Point travelPercentOfDist(const float &percent_) const
Definition: MPath.cpp:85
std::vector< Math::Point<> > & getPoints()
Definition: MPath.h:42
Utils::uint addAPoint(float x_, float y_, float z_)
Definition: MPath.h:56
float getTotalDist() const
Definition: MPath.h:99
Utils::uint appendPath(const Path &path_)
Definition: MPath.h:58
Definition: MPath.h:31