From f07a7062b3fa77d2ea092f0ee19a8b2c4dea6ce8 Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 1 Sep 2017 14:12:10 +0800 Subject: [PATCH] Add min / max height testing for all graphs --- src/tracks/arena_graph.cpp | 12 ++++++++++++ src/tracks/drive_graph.cpp | 15 ++++++++++++++- src/tracks/graph.cpp | 2 ++ src/tracks/graph.hpp | 3 +++ src/tracks/quad.cpp | 7 +++++-- src/tracks/quad.hpp | 10 ++++++++-- 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/tracks/arena_graph.cpp b/src/tracks/arena_graph.cpp index d888e4c47..6fa3e6ac1 100644 --- a/src/tracks/arena_graph.cpp +++ b/src/tracks/arena_graph.cpp @@ -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; } // loadNavmesh diff --git a/src/tracks/drive_graph.cpp b/src/tracks/drive_graph.cpp index e73b730fb..8155b2ab0 100644 --- a/src/tracks/drive_graph.cpp +++ b/src/tracks/drive_graph.cpp @@ -97,16 +97,24 @@ void DriveGraph::load(const std::string &quad_file_name, 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. for (unsigned int i = 0; i < quad->getNumNodes(); 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.", xml_node->getName().c_str(), filename.c_str()); 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 // 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, 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; const XMLNode *xml = file_manager->createXMLTree(filename); diff --git a/src/tracks/graph.cpp b/src/tracks/graph.cpp index 117da8e72..704e78c0b 100644 --- a/src/tracks/graph.cpp +++ b/src/tracks/graph.cpp @@ -31,6 +31,8 @@ #include "utils/log.hpp" 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() diff --git a/src/tracks/graph.hpp b/src/tracks/graph.hpp index 31ab048fb..54de20be0 100644 --- a/src/tracks/graph.hpp +++ b/src/tracks/graph.hpp @@ -103,6 +103,9 @@ private: public: 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 * is no instance created (e.g. arena without navmesh) so we don't assert diff --git a/src/tracks/quad.cpp b/src/tracks/quad.cpp index 48b66035f..a8c4c9f30 100644 --- a/src/tracks/quad.cpp +++ b/src/tracks/quad.cpp @@ -17,6 +17,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "tracks/quad.hpp" +#include "tracks/graph.hpp" #include "utils/log.hpp" #include @@ -36,6 +37,8 @@ Quad::Quad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3, std::min(p2.getY(), p3.getY()) ); m_max_height = std::max ( std::max(p0.getY(), p1.getY()), std::max(p2.getY(), p3.getY()) ); + m_min_height_testing = Graph::MIN_HEIGHT_TESTING; + m_max_height_testing = Graph::MAX_HEIGHT_TESTING; } // 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 // height of the quad at the point where the kart is). if(!ignore_vertical && - (p.getY() - m_max_height > 5.0f || - p.getY() - m_min_height < -1.0f )) + (p.getY() - m_max_height > m_max_height_testing || + p.getY() - m_min_height < m_min_height_testing )) return false; // If a point is exactly on the line of two quads (e.g. between points diff --git a/src/tracks/quad.hpp b/src/tracks/quad.hpp index 2f046d3b3..396f618cf 100644 --- a/src/tracks/quad.hpp +++ b/src/tracks/quad.hpp @@ -58,11 +58,11 @@ private: /** 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. */ - float m_min_height; + float m_min_height, m_min_height_testing; /** The maximum height of the quad, used together with m_min_height * to distinguish between quads which are on top of each other. */ - float m_max_height; + float m_max_height, m_max_height_testing; public: LEAK_CHECK() @@ -81,6 +81,12 @@ public: /** Returns the center of a quad. */ 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. */ float getMinHeight() const { return m_min_height; } // ------------------------------------------------------------------------