diff --git a/ReflexToQ3/includes/EntityConverter.cpp b/ReflexToQ3/includes/EntityConverter.cpp index 4343d74..dff0036 100644 --- a/ReflexToQ3/includes/EntityConverter.cpp +++ b/ReflexToQ3/includes/EntityConverter.cpp @@ -24,8 +24,20 @@ #include #include +// shifts the position of an entity in a given axis. +// for discrepancies between origin points between games. +#define OFFSET_PLAYER 32 // in reflex is origin the feet; in quake it's the center +#define OFFSET_PICKUP 2 // reflex items are on-ground, while quake's are floating +std::string offset(std::string axis, float amount) { + std::istringstream iss(axis); + float c; + iss >> c; + c += amount; - + std::stringstream ss; + ss << std::fixed << std::setprecision(5) << c; + return ss.str(); +} /*----------------------------------------------------------------------------- * PUBLIC @@ -273,7 +285,7 @@ EntityConverter::convertPickup(std::vector &lines) // coordinates reordered to x, z, y std::stringstream oss2; oss2 << "\"origin\" \"" << coords[0] << " " << coords[2] << " " << - offsetHeight(coords[1]) << "\"" << std::endl; + offset(coords[1], OFFSET_PICKUP) << "\"" << std::endl; convertedLines.push_back ( oss2.str() ); return convertedLines; } @@ -368,7 +380,7 @@ EntityConverter::convertPlayerSpawn(std::vector &lines) std::stringstream oss; // coordinates reordered to x, z, y oss << "\"origin\" \"" << coords[0] << " " << coords[2] << " " << - offsetHeight(coords[1]) << "\"" << std::endl; + offset(coords[1], OFFSET_PLAYER) << "\"" << std::endl; convertedLines.push_back ( oss.str() ); std::stringstream oss2; oss2 << "\"angle\" \"" << angle << "\"" << std::endl; @@ -487,7 +499,7 @@ EntityConverter::convertTarget(std::vector &lines) // teleporter height is OFFSET std::stringstream oss; oss << "\"origin\" \"" << coords[0] << " " << coords[2] << " " << - offsetHeight(coords[1]) << "\"" << std::endl; + offset(coords[1], OFFSET_PLAYER) << "\"" << std::endl; convertedLines.push_back ( oss.str() ); } else if ( targetMap_[targetName] == "JumpPad") { @@ -540,23 +552,6 @@ EntityConverter::convertRaceFinish(std::vector &lines) return convertedLines; } - - -std::string -EntityConverter::offsetHeight(std::string coordinate) -{ - std::istringstream iss(coordinate); - float c; - iss >> c; - c += getHeightOffset(); - - std::stringstream ss; - ss << std::fixed << std::setprecision(5) << c; - return ss.str(); -} - - - // DEBUG void EntityConverter::printMapping() diff --git a/ReflexToQ3/includes/EntityConverter.hpp b/ReflexToQ3/includes/EntityConverter.hpp index 5749f42..824cc14 100644 --- a/ReflexToQ3/includes/EntityConverter.hpp +++ b/ReflexToQ3/includes/EntityConverter.hpp @@ -31,6 +31,16 @@ #include #include +/* + *-------------------------------------------------------------------------------------- + * Description: Reflex coordinates place entities at the ground and Xonotic entities + * are at about center of player height. Offset accordingly. + * Paramater: string coordinate, float value passed as string + * Return: string, float value passed as string + *-------------------------------------------------------------------------------------- + */ +std::string offsetHeight(std::string coordinate); + class EntityConverter { public: @@ -129,17 +139,6 @@ class EntityConverter *-------------------------------------------------------------------------------------- */ void addIfRelated(std::string &line, std::istream &is); - /* - *-------------------------------------------------------------------------------------- - * Class: EntityConverter - * Method: EntityConverter :: offsetHeight - * Description: Reflex coordinates place entities at the ground and Xonotic entities - * are at about center of player height. Offset accordingly. - * Paramater: string coordinate, float value passed as string - * Return: string, float value passed as string - *-------------------------------------------------------------------------------------- - */ - std::string offsetHeight(std::string coordinate); /* *--------------------------------------------------------------------------------------