4 // Copyright (C) 2005 Philipp <balinor@pnxs.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
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.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include "lisp/lisp.hpp"
24 #include "lisp/list_iterator.hpp"
25 #include "object_factory.hpp"
31 #define DEFAULT_PIXELS_PER_SECOND 50
34 Path::Path(const lisp::Lisp& reader)
39 lisp::ListIterator iter(&reader);
42 std::string token = iter.item();
43 assert(token == "name");
44 iter.value()->get(name);
49 assert(token == "circular");
50 iter.value()->get(circular);
52 pixels_per_second = DEFAULT_PIXELS_PER_SECOND;
55 if (token == "speed") {
56 iter.value()->get(pixels_per_second);
63 } else if(token == "y") {
65 points.push_back(Vector(x,y));
69 next_target = points.begin();
74 // register this path for lookup:
75 registry[name] = this;
84 Path::update(float elapsed_time)
86 last_movement = velocity * elapsed_time;
88 if ((pos - *next_target).norm() < EPSILON) {
95 Path::draw(DrawingContext& context)
97 // TODO: Add a visible flag, draw the path if true
101 Path::GetPosition() {
107 return *(points.begin());
111 Path::GetLastMovement() {
112 return last_movement;
116 Path::calc_next_velocity()
122 if (next_target == points.end()) {
123 next_target = points.begin();
128 if (next_target == points.end()) {
133 //FIXME: Implement going backwards on the list
134 // I have no f***ing idea how this is done in C++
137 distance = *next_target - pos;
138 velocity = distance.unit() * pixels_per_second;
141 //////////////////////////////////////////////////////////////////////////////
144 PathRegistry Path::registry;
147 Path::GetByName(const std::string& name) {
148 return registry[name];
151 IMPLEMENT_FACTORY(Path, "path");