PF_API 0.52
|
00001 00002 // Copyright (C) 2004-2006 Dylan Blair 00003 // 00004 // email: dblair@alumni.cs.utexas.edu 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License, or (at your option) any later version. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 #ifndef MPATH_H 00022 #define MPATH_H 00023 00024 #include <vector> 00025 #include "MPoint.h" 00026 00027 namespace OpenSkyNet { 00028 namespace Math { 00030 class Path { 00031 bool _pathChanged; 00032 Utils::uint _numPoints; 00033 float _totalDist; 00034 std::vector<Math::Point<> > _points; 00036 std::vector<float> _dist; 00037 public: 00038 Path(); 00039 00040 inline Utils::uint getNumPoints() const { return _numPoints; } 00041 inline std::vector<Math::Point<> >& getPoints() { return _points; } 00042 inline const std::vector<Math::Point<> >& getPoints() const { return _points; } 00043 00044 inline Utils::uint addAPoint(const Math::Point<>& aPoint_) { 00045 _points.push_back(aPoint_); 00046 if (_numPoints > 0) { 00047 _dist.push_back((aPoint_ - _points[_numPoints-1]).getLength()); 00048 _totalDist += _dist[_numPoints-1]; 00049 } 00050 ++_numPoints; 00051 _pathChanged = true; 00052 return (_numPoints - 1); 00053 } 00054 00055 inline Utils::uint addAPoint(float x_, float y_, float z_) { return addAPoint(Math::Point<>(x_,y_,z_)); } 00056 00057 inline Utils::uint appendPath(const Path& path_) { 00058 for (Utils::uint i = 0; i < path_.getNumPoints(); i++) 00059 addAPoint(path_.getPoints()[i]); 00060 return (_numPoints - 1); 00061 } 00062 00063 inline void clear() { 00064 _points.clear(); 00065 _dist.clear(); 00066 _numPoints = 0; 00067 _totalDist = 0; 00068 _pathChanged = true; 00069 } 00070 00072 inline bool isPathChanged() { 00073 if (_pathChanged) { 00074 _pathChanged = false; 00075 return true; 00076 } 00077 return false; 00078 } 00079 00080 inline void translate(const Math::Point<>& p_) { 00081 for (Utils::uint i = 0; i < _numPoints; i++) 00082 _points[i] = _points[i] + p_; 00083 _pathChanged = true; 00084 } 00085 00093 void calcNaturalCubicSpline(float minDistanceBetweenPoints_=1.0, Utils::uint maxTotalPoints_=0, float tension_=0.0f); 00094 00096 void calcDistances(); 00097 00098 inline float getTotalDist() const { return _totalDist; } 00099 00106 Math::Point<> travelPercentOfPoints(const float& percent_) const; 00107 Math::Point<> travelPercentOfDist(const float& percent_) const; 00109 00113 float getAdditiveFromSpeed(float speed_) const { return speed_ / _totalDist; } 00114 }; 00115 } 00116 } 00117 00118 #endif //MPATH_H