1) Bugfix: lap length was sometimes computed using the distance between consecutive

center-points of quads instead of the length of the current quad, resulting in
   lap length being somewhat wrong.
2) Bugfix: the first quad would have a distance along track that's not 0.
3) New-lap lines can now be anywhere on the quad graph, as long as the line is
   'on' a line dividing two consecutive quads.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4022 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2009-09-15 03:58:41 +00:00
parent d863d37c72
commit 6fd6063bcd
4 changed files with 59 additions and 11 deletions

View File

@@ -71,9 +71,10 @@ void GraphNode::addSuccessor(unsigned int to)
const Quad &this_quad = m_all_quads->getQuad(m_index);
// to is the graph node, so we have to use m_all_nodes to get the right quad
const Quad &next_quad = m_all_nodes->getQuad(to);
core::vector2df d2=m_lower_center-m_all_nodes->getNode(to).getLowerCenter();
Vec3 diff = next_quad.getCenter() - this_quad.getCenter();
m_distance_to_next.push_back(diff.length());
m_distance_to_next.push_back(d2.getLength());
float theta = -atan2(diff.getX(), diff.getY());
m_angle_to_next.push_back(theta);
@@ -82,10 +83,14 @@ void GraphNode::addSuccessor(unsigned int to)
float distance_to_next = ( this_quad[2].distance(this_quad[1])
+ this_quad[3].distance(this_quad[0]) ) *0.5f;
// The distance from start for the successor node
m_all_nodes->getNode(to).m_distance_from_start =
std::max(m_all_nodes->getNode(to).m_distance_from_start,
m_distance_from_start+distance_to_next);
if(to!=0)
{
m_all_nodes->getNode(to).m_distance_from_start =
std::max(m_all_nodes->getNode(to).m_distance_from_start,
m_distance_from_start+distance_to_next);
}
} // addSuccessor
// ----------------------------------------------------------------------------
/** Returns the distance a point has from this quad in forward and sidewards
* direction, i.e. how far forwards the point is from the beginning of the

View File

@@ -108,7 +108,10 @@ public:
{ return m_distance_from_start; }
// -------------------------------------------------------------------
/** Returns the width of the part for this quad. */
float getPathWidth() const { return m_width; }
float getPathWidth() const { return m_width; }
// -------------------------------------------------------------------
/** Returns the center point of the lower edge of this graph node. */
const core::vector2df& getLowerCenter() const {return m_lower_center;}
}; // GraphNode
#endif

View File

@@ -35,11 +35,13 @@ const int QuadGraph::UNKNOWN_SECTOR = -1;
QuadGraph::QuadGraph(const std::string &quad_file_name,
const std::string graph_file_name)
{
m_node = NULL;
m_mesh = NULL;
m_mesh_buffer = NULL;
m_lap_length = 0;
m_all_quads = new QuadSet(quad_file_name);
m_node = NULL;
m_mesh = NULL;
m_mesh_buffer = NULL;
m_lap_length = 0;
m_offset_for_startline = 0;
m_all_quads = new QuadSet(quad_file_name);
m_quad_filename = quad_file_name;
GraphNode::m_all_quads = m_all_quads;
GraphNode::m_all_nodes = this;
load(graph_file_name);
@@ -55,6 +57,29 @@ QuadGraph::~QuadGraph()
}
} // ~QuadGraph
// -----------------------------------------------------------------------------
/** Sets the offset from the middle point of the lap counting line to the
* beginning of quad 0. All reported values for distance along track will use
* this offset. As a result a kart on the start line will have distance 0,
* and a kart just before the start line will have a getDistanceFromStart()
* which is the length of the track.
*/
void QuadGraph::setStartCoordinate(const Vec3 &start_point)
{
int sector=UNKNOWN_SECTOR;
findRoadSector(start_point, &sector);
if(sector==UNKNOWN_SECTOR)
{
fprintf(stderr,
"Start line not on quads in file '%s'. Lap counting might not work.\n",
m_quad_filename.c_str());
return;
}
Vec3 xyz;
spatialToTrack(&xyz, start_point, sector);
m_offset_for_startline = xyz.getY();
} // setStartCoordinate
// -----------------------------------------------------------------------------
/** Loads a quad graph from a file.
* \param filename Name of the file to load.
@@ -72,6 +97,8 @@ void QuadGraph::load(const std::string &filename)
m_all_nodes.push_back(new GraphNode(i));
// Then set the default loop:
setDefaultSuccessors();
m_lap_length = m_all_nodes[m_all_nodes.size()-1]->getDistanceFromStart()
+ m_all_nodes[m_all_nodes.size()-1]->getDistanceToSuccessor(0);
return;
}
@@ -283,7 +310,10 @@ void QuadGraph::spatialToTrack(Vec3 *dst, const Vec3& xyz,
}
getNode(sector).getDistances(xyz, dst);
float y=dst->getY();
y=y-m_offset_for_startline;
if(y<0) y+=m_lap_length;
dst->setY(y);
} // spatialToTrack
//-----------------------------------------------------------------------------

View File

@@ -50,6 +50,14 @@ private:
/** Scaling for mini map, only x and y components are used. */
Vec3 m_scaling;
/** This is the track coordinate for the start line. This offset is
* added to the Y value of spatialToTrack. It guarantees that the
* start line is always at track coordinates 0 (for Y). */
float m_offset_for_startline;
/** Stores the filename - just used for error messages. */
std::string m_quad_filename;
void setDefaultSuccessors();
void load (const std::string &filename);
void createMesh(bool show_invisible=true);
@@ -83,6 +91,7 @@ public:
=video::SColor(127, 255, 255, 255) );
#endif
void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const;
void setStartCoordinate(const Vec3 &start_point);
/** Returns the number of nodes in the graph. */
unsigned int getNumNodes() const { return m_all_nodes.size(); }
@@ -113,6 +122,7 @@ public:
// ----------------------------------------------------------------------
/** Returns the length of the main driveline. */
float getLapLength() const {return m_lap_length; }
// ----------------------------------------------------------------------
}; // QuadGraph
#endif