Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / object / path.hpp
1 //  SuperTux Path
2 //  Copyright (C) 2005 Philipp <balinor@pnxs.de>
3 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software: you can redistribute it and/or modify
7 //  it under the terms of the GNU General Public License as published by
8 //  the Free Software Foundation, either version 3 of the License, or
9 //  (at your option) any later version.
10 //
11 //  This program 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
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 #ifndef HEADER_SUPERTUX_OBJECT_PATH_HPP
20 #define HEADER_SUPERTUX_OBJECT_PATH_HPP
21
22 #include <vector>
23
24 #include "math/vector.hpp"
25 #include "util/reader_fwd.hpp"
26 #include "util/writer_fwd.hpp"
27
28 class Path
29 {
30 public:
31   Path();
32   ~Path();
33
34   void read(const Reader& reader);
35
36   Vector get_base() const;
37
38   /**
39    * Helper class that stores an individual node of a Path
40    */
41   class Node
42   {
43   public:
44     Vector position; /**< the position of this node */
45     float time; /**< time (in seconds) to get from this node to next node */
46   };
47
48   std::vector<Node> nodes;
49
50   /**
51    * returns Node index nearest to reference_point or -1 if not applicable
52    */
53   int get_nearest_node_no(Vector reference_point) const;
54
55   /**
56    * returns Node index farthest from reference_point or -1 if not applicable
57    */
58   int get_farthest_node_no(Vector reference_point) const;
59
60 private:
61   friend class PathWalker;
62
63   enum WalkMode {
64     // moves from first to last path node and stops
65     ONE_SHOT,
66     // moves from first to last node then in reverse order back to first
67     PING_PONG,
68     // moves from last node back to the first node
69     CIRCULAR
70   };
71
72   WalkMode mode;
73 };
74
75 #endif
76
77 /* EOF */