diff --git a/src/tracks/quad.cpp b/src/tracks/quad.cpp index 8a62bceb6..3f9dc24ce 100644 --- a/src/tracks/quad.cpp +++ b/src/tracks/quad.cpp @@ -131,3 +131,14 @@ void Quad::transform(const btTransform &t, Quad *result) const std::min(result->m_p[2].getY(), result->m_p[3].getY()) ); } // transform + +// ---------------------------------------------------------------------------- +/** Reverse the quad */ +void Quad::reverse() { + Vec3 tmp = m_p[0]; + m_p[0] = m_p[2]; + m_p[2] = tmp; + tmp = m_p[1]; + m_p[1] = m_p[3]; + m_p[3] = tmp; +} diff --git a/src/tracks/quad.hpp b/src/tracks/quad.hpp index fb123f407..47566ded9 100644 --- a/src/tracks/quad.hpp +++ b/src/tracks/quad.hpp @@ -75,5 +75,8 @@ public: // ------------------------------------------------------------------------ /** True if this quad should be ignored by the AI. */ bool letAIIgnore() const { return m_ai_ignore; } + + /** Reverse the quad */ + void reverse(); }; // class Quad #endif diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index a78d4dbdb..519fa3e57 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -44,13 +44,16 @@ QuadGraph *QuadGraph::m_quad_graph = NULL; */ QuadGraph::QuadGraph(const std::string &quad_file_name, const std::string graph_file_name, - const bool reverse) + const bool reverse) : m_reverse(reverse) { m_node = NULL; m_mesh = NULL; m_mesh_buffer = NULL; m_lap_length = 0; m_all_quads = new QuadSet(quad_file_name); + if(m_reverse) { + m_all_quads->reverse_all_quads(); + } m_quad_filename = quad_file_name; GraphNode::m_all_quads = m_all_quads; GraphNode::m_all_nodes = this; @@ -70,6 +73,14 @@ QuadGraph::~QuadGraph() } // ~QuadGraph // ----------------------------------------------------------------------------- + +void QuadGraph::addSuccessor(unsigned int from, unsigned int to) { + if(m_reverse) + m_all_nodes[to]->addSuccessor(from); + else + m_all_nodes[from]->addSuccessor(to); +} + /** Loads a quad graph from a file. * \param filename Name of the file to load. */ @@ -138,7 +149,8 @@ void QuadGraph::load(const std::string &filename) for(unsigned int i=from; i<=to; i++) { assert(i!=to ? i+1 : from addSuccessor(i!=to ? i+1 : from); + addSuccessor(i,(i!=to ? i+1 : from)); + //~ m_all_nodes[i]->addSuccessor(i!=to ? i+1 : from); } } else if(xml_node->getName()=="edge-line") @@ -149,7 +161,8 @@ void QuadGraph::load(const std::string &filename) xml_node->get("to", &to); for(unsigned int i=from; iaddSuccessor(i+1); + addSuccessor(i,i+1); + //~ m_all_nodes[i]->addSuccessor(i+1); } } else if(xml_node->getName()=="edge") @@ -159,7 +172,8 @@ void QuadGraph::load(const std::string &filename) xml_node->get("from", &from); xml_node->get("to", &to); assert(toaddSuccessor(to); + addSuccessor(from,to); + //~ m_all_nodes[from]->addSuccessor(to); } // edge else { @@ -281,7 +295,8 @@ void QuadGraph::setDefaultSuccessors() { for(unsigned int i=0; igetNumberOfSuccessors()==0) { - m_all_nodes[i]->addSuccessor(i+1>=m_all_nodes.size() ? 0 : i+1); + addSuccessor(i,i+1>=m_all_nodes.size() ? 0 : i+1); + //~ m_all_nodes[i]->addSuccessor(i+1>=m_all_nodes.size() ? 0 : i+1); } // if size==0 } // for i +#include #include "io/file_manager.hpp" #include "io/xml_node.hpp" @@ -44,6 +45,12 @@ QuadSet::~QuadSet() } // ~QuadSet // ----------------------------------------------------------------------------- +void reverse_quad(Quad* q) { + q->reverse(); +} +void QuadSet::reverse_all_quads() { + for_each(m_all_quads.begin(),m_all_quads.end(),reverse_quad); +} /** This function interprets a point specification as an attribute in the xml quadset file. It understands two different specifications: p1="n:p" : get point p from square n (n, p integers) diff --git a/src/tracks/quad_set.hpp b/src/tracks/quad_set.hpp index 39a897015..2d2006b26 100644 --- a/src/tracks/quad_set.hpp +++ b/src/tracks/quad_set.hpp @@ -47,6 +47,7 @@ public: QuadSet (const std::string& filename); ~QuadSet (); + void reverse_all_quads(); int getCurrentQuad(const Vec3& p, int oldQuad) const; const Quad& getQuad(int n) const {return *(m_all_quads[n]); }