X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fpath.cpp;h=5d7e88a7da8e0cca8a2401e17b3e32cadbc2a711;hb=555d1b7bebb45326d82d934e07463209837309b0;hp=4ed45d0566a6ac9e7ca751507767f72912c38a1c;hpb=67690e081c28b818e94796be284206326bc8a6b9;p=supertux.git diff --git a/src/object/path.cpp b/src/object/path.cpp index 4ed45d056..5d7e88a7d 100644 --- a/src/object/path.cpp +++ b/src/object/path.cpp @@ -1,5 +1,5 @@ // $Id$ -// +// // SuperTux Path // Copyright (C) 2005 Philipp // Copyright (C) 2006 Christoph Sommer @@ -14,7 +14,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 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 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -23,10 +23,11 @@ #include "path.hpp" +#include "lisp/writer.hpp" #include "lisp/lisp.hpp" #include "lisp/list_iterator.hpp" #include "object_factory.hpp" -#include "msg.hpp" +#include "log.hpp" #include #include @@ -66,9 +67,9 @@ Path::read(const lisp::Lisp& reader) } continue; } - + if(iter.item() != "node") { - msg_warning << "unknown token '" << iter.item() << "' in Path nodes list. Ignored." << std::endl; + log_warning << "unknown token '" << iter.item() << "' in Path nodes list. Ignored." << std::endl; continue; } const lisp::Lisp* node_lisp = iter.lisp(); @@ -107,7 +108,7 @@ Path::write(lisp::Writer& writer) writer.write_string("mode", "circular"); break; default: - msg_warning << "Don't know how to write mode " << (int) mode << " ?!?" << std::endl; + log_warning << "Don't know how to write mode " << (int) mode << " ?!?" << std::endl; break; } @@ -130,7 +131,39 @@ Path::get_base() const { if(nodes.empty()) return Vector(0, 0); - + return nodes[0].position; } +int +Path::get_nearest_node_no(Vector reference_point) const +{ + int nearest_node_id = -1; + float nearest_node_dist = 0; + int id = 0; + for (std::vector::const_iterator i = nodes.begin(); i != nodes.end(); i++, id++) { + float dist = (i->position - reference_point).norm(); + if ((nearest_node_id == -1) || (dist < nearest_node_dist)) { + nearest_node_id = id; + nearest_node_dist = dist; + } + } + return nearest_node_id; +} + +int +Path::get_farthest_node_no(Vector reference_point) const +{ + int farthest_node_id = -1; + float farthest_node_dist = 0; + int id = 0; + for (std::vector::const_iterator i = nodes.begin(); i != nodes.end(); i++, id++) { + float dist = (i->position - reference_point).norm(); + if ((farthest_node_id == -1) || (dist > farthest_node_dist)) { + farthest_node_id = id; + farthest_node_dist = dist; + } + } + return farthest_node_id; +} +