Add min / max height testing for all graphs
This commit is contained in:
parent
f7397028ff
commit
f07a7062b3
@ -158,6 +158,18 @@ void ArenaGraph::loadNavmesh(const std::string &navmesh)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const XMLNode* ht = xml->getNode("height-testing");
|
||||||
|
if (ht)
|
||||||
|
{
|
||||||
|
float min = Graph::MIN_HEIGHT_TESTING;
|
||||||
|
float max = Graph::MAX_HEIGHT_TESTING;
|
||||||
|
ht->get("min", &min);
|
||||||
|
ht->get("max", &max);
|
||||||
|
for (unsigned i = 0; i < m_all_nodes.size(); i++)
|
||||||
|
{
|
||||||
|
m_all_nodes[i]->setHeightTesting(min, max);
|
||||||
|
}
|
||||||
|
}
|
||||||
delete xml;
|
delete xml;
|
||||||
|
|
||||||
} // loadNavmesh
|
} // loadNavmesh
|
||||||
|
@ -97,16 +97,24 @@ void DriveGraph::load(const std::string &quad_file_name,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float min_height_testing = Graph::MIN_HEIGHT_TESTING;
|
||||||
|
float max_height_testing = Graph::MAX_HEIGHT_TESTING;
|
||||||
// Each quad is part of the graph exactly once now.
|
// Each quad is part of the graph exactly once now.
|
||||||
for (unsigned int i = 0; i < quad->getNumNodes(); i++)
|
for (unsigned int i = 0; i < quad->getNumNodes(); i++)
|
||||||
{
|
{
|
||||||
const XMLNode *xml_node = quad->getNode(i);
|
const XMLNode *xml_node = quad->getNode(i);
|
||||||
if (xml_node->getName() != "quad")
|
if (!(xml_node->getName() == "quad" || xml_node->getName() == "height-testing"))
|
||||||
{
|
{
|
||||||
Log::warn("DriveGraph: Unsupported node type '%s' found in '%s' - ignored.",
|
Log::warn("DriveGraph: Unsupported node type '%s' found in '%s' - ignored.",
|
||||||
xml_node->getName().c_str(), filename.c_str());
|
xml_node->getName().c_str(), filename.c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (xml_node->getName() == "height-testing")
|
||||||
|
{
|
||||||
|
xml_node->get("min", &min_height_testing);
|
||||||
|
xml_node->get("max", &max_height_testing);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Note that it's not easy to do the reading of the parameters here
|
// Note that it's not easy to do the reading of the parameters here
|
||||||
// in quad, since the specification in the xml can contain references
|
// in quad, since the specification in the xml can contain references
|
||||||
@ -141,6 +149,11 @@ void DriveGraph::load(const std::string &quad_file_name,
|
|||||||
createQuad(p0, p1, p2, p3, m_all_nodes.size(), invisible, ai_ignore,
|
createQuad(p0, p1, p2, p3, m_all_nodes.size(), invisible, ai_ignore,
|
||||||
false/*is_arena*/, ignored);
|
false/*is_arena*/, ignored);
|
||||||
}
|
}
|
||||||
|
for (unsigned i = 0; i < m_all_nodes.size(); i++)
|
||||||
|
{
|
||||||
|
m_all_nodes[i]->setHeightTesting(min_height_testing,
|
||||||
|
max_height_testing);
|
||||||
|
}
|
||||||
delete quad;
|
delete quad;
|
||||||
|
|
||||||
const XMLNode *xml = file_manager->createXMLTree(filename);
|
const XMLNode *xml = file_manager->createXMLTree(filename);
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
#include "utils/log.hpp"
|
#include "utils/log.hpp"
|
||||||
|
|
||||||
const int Graph::UNKNOWN_SECTOR = -1;
|
const int Graph::UNKNOWN_SECTOR = -1;
|
||||||
|
const float Graph::MIN_HEIGHT_TESTING = -1.0f;
|
||||||
|
const float Graph::MAX_HEIGHT_TESTING = 5.0f;
|
||||||
Graph *Graph::m_graph = NULL;
|
Graph *Graph::m_graph = NULL;
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
Graph::Graph()
|
Graph::Graph()
|
||||||
|
@ -103,6 +103,9 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static const int UNKNOWN_SECTOR;
|
static const int UNKNOWN_SECTOR;
|
||||||
|
// For 2d Quad
|
||||||
|
static const float MIN_HEIGHT_TESTING;
|
||||||
|
static const float MAX_HEIGHT_TESTING;
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the one instance of this object. It is possible that there
|
/** Returns the one instance of this object. It is possible that there
|
||||||
* is no instance created (e.g. arena without navmesh) so we don't assert
|
* is no instance created (e.g. arena without navmesh) so we don't assert
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "tracks/quad.hpp"
|
#include "tracks/quad.hpp"
|
||||||
|
#include "tracks/graph.hpp"
|
||||||
#include "utils/log.hpp"
|
#include "utils/log.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -36,6 +37,8 @@ Quad::Quad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3,
|
|||||||
std::min(p2.getY(), p3.getY()) );
|
std::min(p2.getY(), p3.getY()) );
|
||||||
m_max_height = std::max ( std::max(p0.getY(), p1.getY()),
|
m_max_height = std::max ( std::max(p0.getY(), p1.getY()),
|
||||||
std::max(p2.getY(), p3.getY()) );
|
std::max(p2.getY(), p3.getY()) );
|
||||||
|
m_min_height_testing = Graph::MIN_HEIGHT_TESTING;
|
||||||
|
m_max_height_testing = Graph::MAX_HEIGHT_TESTING;
|
||||||
} // Quad
|
} // Quad
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -77,8 +80,8 @@ bool Quad::pointInside(const Vec3& p, bool ignore_vertical) const
|
|||||||
// with the minimum height of the quad (and not with the actual
|
// with the minimum height of the quad (and not with the actual
|
||||||
// height of the quad at the point where the kart is).
|
// height of the quad at the point where the kart is).
|
||||||
if(!ignore_vertical &&
|
if(!ignore_vertical &&
|
||||||
(p.getY() - m_max_height > 5.0f ||
|
(p.getY() - m_max_height > m_max_height_testing ||
|
||||||
p.getY() - m_min_height < -1.0f ))
|
p.getY() - m_min_height < m_min_height_testing ))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If a point is exactly on the line of two quads (e.g. between points
|
// If a point is exactly on the line of two quads (e.g. between points
|
||||||
|
@ -58,11 +58,11 @@ private:
|
|||||||
|
|
||||||
/** The minimum height of the quad, used in case that several quads
|
/** The minimum height of the quad, used in case that several quads
|
||||||
* are on top of each other when determining the sector a kart is on. */
|
* are on top of each other when determining the sector a kart is on. */
|
||||||
float m_min_height;
|
float m_min_height, m_min_height_testing;
|
||||||
|
|
||||||
/** The maximum height of the quad, used together with m_min_height
|
/** The maximum height of the quad, used together with m_min_height
|
||||||
* to distinguish between quads which are on top of each other. */
|
* to distinguish between quads which are on top of each other. */
|
||||||
float m_max_height;
|
float m_max_height, m_max_height_testing;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LEAK_CHECK()
|
LEAK_CHECK()
|
||||||
@ -81,6 +81,12 @@ public:
|
|||||||
/** Returns the center of a quad. */
|
/** Returns the center of a quad. */
|
||||||
const Vec3& getCenter () const { return m_center; }
|
const Vec3& getCenter () const { return m_center; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
void setHeightTesting(float min, float max)
|
||||||
|
{
|
||||||
|
m_min_height_testing = min;
|
||||||
|
m_max_height_testing = max;
|
||||||
|
}
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the minimum height of a quad. */
|
/** Returns the minimum height of a quad. */
|
||||||
float getMinHeight() const { return m_min_height; }
|
float getMinHeight() const { return m_min_height; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user