Path Class Reference

#include <path.hpp>

List of all members.

Public Member Functions

 Path ()
 ~Path ()
void read (const Reader &reader)
Vector get_base () const
int get_nearest_node_no (Vector reference_point) const
 returns Node index nearest to reference_point or -1 if not applicable
int get_farthest_node_no (Vector reference_point) const
 returns Node index farthest from reference_point or -1 if not applicable

Public Attributes

std::vector< Nodenodes

Private Types

enum  WalkMode { ONE_SHOT, PING_PONG, CIRCULAR }

Private Attributes

WalkMode mode

Friends

class PathWalker

Classes

class  Node
 Helper class that stores an individual node of a Path. More...


Detailed Description

Definition at line 28 of file path.hpp.


Member Enumeration Documentation

enum Path::WalkMode [private]

Enumerator:
ONE_SHOT 
PING_PONG 
CIRCULAR 

Definition at line 68 of file path.hpp.

00068                 {
00069     // moves from first to last path node and stops
00070     ONE_SHOT,
00071     // moves from first to last node then in reverse order back to first
00072     PING_PONG,
00073     // moves from last node back to the first node
00074     CIRCULAR
00075   };


Constructor & Destructor Documentation

Path::Path (  ) 

Definition at line 27 of file path.cpp.

00027            :
00028   nodes(),
00029   mode()
00030 {
00031 }

Path::~Path (  ) 

Definition at line 33 of file path.cpp.

00034 {
00035 }


Member Function Documentation

void Path::read ( const Reader reader  ) 

Definition at line 38 of file path.cpp.

References CIRCULAR, lisp::Lisp::get(), lisp::ListIterator::item(), lisp::ListIterator::lisp(), log_warning, mode, lisp::ListIterator::next(), nodes, ONE_SHOT, PING_PONG, Path::Node::position, Path::Node::time, lisp::ListIterator::value(), Vector::x, and Vector::y.

00039 {
00040   lisp::ListIterator iter(&reader);
00041 
00042   mode = CIRCULAR;
00043   while(iter.next()) {
00044     if(iter.item() == "mode") {
00045       std::string mode_string;
00046       if(!iter.value()->get(mode_string))
00047         throw std::runtime_error("Pathmode not a string");
00048 
00049       if(mode_string == "oneshot")
00050         mode = ONE_SHOT;
00051       else if(mode_string == "pingpong")
00052         mode = PING_PONG;
00053       else if(mode_string == "circular")
00054         mode = CIRCULAR;
00055       else {
00056         std::ostringstream msg;
00057         msg << "Unknown pathmode '" << mode_string << "' found";
00058         throw std::runtime_error(msg.str());
00059       }
00060       continue;
00061     }
00062 
00063     if(iter.item() != "node") {
00064       log_warning << "unknown token '" << iter.item() << "' in Path nodes list. Ignored." << std::endl;
00065       continue;
00066     }
00067     const lisp::Lisp* node_lisp = iter.lisp();
00068 
00069     // each new node will inherit all values from the last one
00070     Node node;
00071     node.time = 1;
00072     if( (!node_lisp->get("x", node.position.x) ||
00073          !node_lisp->get("y", node.position.y)))
00074       throw std::runtime_error("Path node without x and y coordinate specified");
00075     node_lisp->get("time", node.time);
00076 
00077     if(node.time <= 0)
00078       throw std::runtime_error("Path node with non-positive time");
00079 
00080     nodes.push_back(node);
00081   }
00082 
00083   if (nodes.empty())
00084     throw std::runtime_error("Path with zero nodes");
00085 }

Vector Path::get_base (  )  const

Definition at line 88 of file path.cpp.

References nodes.

00089 {
00090   if(nodes.empty())
00091     return Vector(0, 0);
00092 
00093   return nodes[0].position;
00094 }

int Path::get_nearest_node_no ( Vector  reference_point  )  const

returns Node index nearest to reference_point or -1 if not applicable

Definition at line 97 of file path.cpp.

References nodes.

00098 {
00099   int nearest_node_id = -1;
00100   float nearest_node_dist = 0;
00101   int id = 0;
00102   for (std::vector<Node>::const_iterator i = nodes.begin(); i != nodes.end(); i++, id++) {
00103     float dist = (i->position - reference_point).norm();
00104     if ((nearest_node_id == -1) || (dist < nearest_node_dist)) {
00105       nearest_node_id = id;
00106       nearest_node_dist = dist;
00107     }
00108   }
00109   return nearest_node_id;
00110 }

int Path::get_farthest_node_no ( Vector  reference_point  )  const

returns Node index farthest from reference_point or -1 if not applicable

Definition at line 113 of file path.cpp.

References nodes.

00114 {
00115   int farthest_node_id = -1;
00116   float farthest_node_dist = 0;
00117   int id = 0;
00118   for (std::vector<Node>::const_iterator i = nodes.begin(); i != nodes.end(); i++, id++) {
00119     float dist = (i->position - reference_point).norm();
00120     if ((farthest_node_id == -1) || (dist > farthest_node_dist)) {
00121       farthest_node_id = id;
00122       farthest_node_dist = dist;
00123     }
00124   }
00125   return farthest_node_id;
00126 }


Friends And Related Function Documentation

friend class PathWalker [friend]

Definition at line 66 of file path.hpp.


Member Data Documentation

std::vector<Node> Path::nodes

Definition at line 53 of file path.hpp.

Referenced by PathWalker::advance(), PathWalker::advance_node(), get_base(), get_farthest_node_no(), get_nearest_node_no(), PathWalker::get_pos(), PathWalker::goback_node(), PathWalker::PathWalker(), read(), and FlipLevelTransformer::transform_path().

WalkMode Path::mode [private]

Definition at line 77 of file path.hpp.

Referenced by PathWalker::advance_node(), PathWalker::goback_node(), and read().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:33 2014 for SuperTux by  doxygen 1.5.1