From 5eafaaa918824a9f68003ecd454bb4df1cd5ad67 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Wed, 18 Apr 2012 22:07:45 +0000 Subject: [PATCH] Added support for checklines to be specified by two 3d points instead of 2d points and the minimum height. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11125 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/tracks/check_line.cpp | 27 ++++++++++++++++++++------- src/tracks/check_line.hpp | 5 +++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/tracks/check_line.cpp b/src/tracks/check_line.cpp index b38db4ea9..2e04b5415 100644 --- a/src/tracks/check_line.cpp +++ b/src/tracks/check_line.cpp @@ -18,15 +18,16 @@ #include "tracks/check_line.hpp" -#include - -#include "irrlicht.h" - #include "io/xml_node.hpp" #include "karts/abstract_kart.hpp" #include "modes/world.hpp" #include "race/race_manager.hpp" +#include "irrlicht.h" + +#include +#include + /** Constructor for a checkline. * \param node XML node containing the parameters for this checkline. * \param index Index of this check structure in the check manager. @@ -38,9 +39,21 @@ CheckLine::CheckLine(const XMLNode &node, unsigned int index) // in world, so we can't call world->getNumKarts() m_previous_sign.resize(race_manager->getNumberOfKarts()); core::vector2df p1, p2; - node.get("p1", &p1); - node.get("p2", &p2); - node.get("min-height", &m_min_height); + if(node.get("p1", &p1) && + node.get("p2", &p2) && + node.get("min-height", &m_min_height)) + { + m_left_point = Vec3(p1.X, m_min_height, p1.Y); + m_right_point = Vec3(p2.X, m_min_height, p2.Y); + } + else + { + node.get("p1", &m_left_point); + p1 = core::vector2df(m_left_point.getX(), m_left_point.getZ()); + node.get("p2", &m_right_point); + p2 = core::vector2df(m_right_point.getX(), m_right_point.getZ()); + m_min_height = std::min(m_left_point.getY(), m_right_point.getY()); + } m_line.setLine(p1, p2); if(UserConfigParams::m_check_debug) { diff --git a/src/tracks/check_line.hpp b/src/tracks/check_line.hpp index 893417365..db6945bd2 100644 --- a/src/tracks/check_line.hpp +++ b/src/tracks/check_line.hpp @@ -51,6 +51,11 @@ private: /** The minimum height of the checkline. */ float m_min_height; + /** The actual (or estimated) left and right end points in 3d. This is + * used by the cannon. If the xml file stores only the min_height, those + * points are set from the 2d points and the min height. */ + Vec3 m_left_point, m_right_point; + /** Stores the sign (i.e. side) of the previous line to save some * computations. True if the value is >=0, i.e. the point is on * or to the right of the line. */