[1777] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Reto Grieder |
---|
| 25 | * Co-authors: |
---|
| 26 | * ... |
---|
| 27 | */ |
---|
| 28 | |
---|
[1778] | 29 | /** |
---|
[1777] | 30 | @file |
---|
[1778] | 31 | @brief |
---|
| 32 | Math conversion functions. Definitions are in Math.cc |
---|
[1777] | 33 | */ |
---|
| 34 | |
---|
| 35 | #ifndef _MathConvert_H__ |
---|
| 36 | #define _MathConvert_H__ |
---|
| 37 | |
---|
| 38 | #include "UtilPrereqs.h" |
---|
| 39 | #include "Convert.h" |
---|
| 40 | #include "Math.h" |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | //////////////////// |
---|
| 44 | // Math to string // |
---|
| 45 | //////////////////// |
---|
| 46 | |
---|
| 47 | // Vector2 to std::string |
---|
| 48 | inline bool explicitConversion(std::string* output, const orxonox::Vector2& input) |
---|
| 49 | { |
---|
| 50 | std::ostringstream ostream; |
---|
| 51 | if (ostream << input.x << "," << input.y) |
---|
| 52 | { |
---|
| 53 | (*output) = ostream.str(); |
---|
| 54 | return true; |
---|
| 55 | } |
---|
| 56 | return false; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | // Vector3 to std::string |
---|
| 60 | inline bool explicitConversion(std::string* output, const orxonox::Vector3& input) |
---|
| 61 | { |
---|
| 62 | std::ostringstream ostream; |
---|
| 63 | if (ostream << input.x << "," << input.y << "," << input.z) |
---|
| 64 | { |
---|
| 65 | (*output) = ostream.str(); |
---|
| 66 | return true; |
---|
| 67 | } |
---|
| 68 | return false; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | // Vector4 to std::string |
---|
| 72 | inline bool explicitConversion(std::string* output, const orxonox::Vector4& input) |
---|
| 73 | { |
---|
| 74 | std::ostringstream ostream; |
---|
| 75 | if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w) |
---|
| 76 | { |
---|
| 77 | (*output) = ostream.str(); |
---|
| 78 | return true; |
---|
| 79 | } |
---|
| 80 | return false; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | // Quaternion to std::string |
---|
| 84 | inline bool explicitConversion(std::string* output, const orxonox::Quaternion& input) |
---|
| 85 | { |
---|
| 86 | std::ostringstream ostream; |
---|
| 87 | if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z) |
---|
| 88 | { |
---|
| 89 | (*output) = ostream.str(); |
---|
| 90 | return true; |
---|
| 91 | } |
---|
| 92 | return false; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | // ColourValue to std::string |
---|
| 96 | inline bool explicitConversion(std::string* output, const orxonox::ColourValue& input) |
---|
| 97 | { |
---|
| 98 | std::ostringstream ostream; |
---|
| 99 | if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a) |
---|
| 100 | { |
---|
| 101 | (*output) = ostream.str(); |
---|
| 102 | return true; |
---|
| 103 | } |
---|
| 104 | return false; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | //////////////////// |
---|
| 109 | // string to Math // |
---|
| 110 | //////////////////// |
---|
| 111 | |
---|
| 112 | // std::string to Vector2 |
---|
[1778] | 113 | _UtilExport bool fallbackConversion(orxonox::Vector2* output, const std::string& input); |
---|
[1777] | 114 | // std::string to Vector3 |
---|
[1778] | 115 | _UtilExport bool fallbackConversion(orxonox::Vector3* output, const std::string& input); |
---|
[1777] | 116 | // std::string to Vector4 |
---|
[1778] | 117 | _UtilExport bool fallbackConversion(orxonox::Vector4* output, const std::string& input); |
---|
[1777] | 118 | // std::string to Quaternion |
---|
[1778] | 119 | _UtilExport bool fallbackConversion(orxonox::Quaternion* output, const std::string& input); |
---|
[1777] | 120 | // std::string to ColourValue |
---|
[1778] | 121 | _UtilExport bool fallbackConversion(orxonox::ColourValue* output, const std::string& input); |
---|
[1777] | 122 | |
---|
| 123 | |
---|
| 124 | /////////////////////////////// |
---|
| 125 | // From and to Radian/Degree // |
---|
| 126 | /////////////////////////////// |
---|
| 127 | |
---|
| 128 | // From Radian |
---|
| 129 | template <class ToType> |
---|
[1778] | 130 | inline bool fallbackConversion(ToType* output, const orxonox::Radian input) |
---|
[1777] | 131 | { |
---|
| 132 | return convertValue<ToType, Ogre::Real>(output, input.valueRadians()); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | // From Degree |
---|
| 136 | template <class ToType> |
---|
[1778] | 137 | inline bool fallbackConversion(ToType* output, const orxonox::Degree input) |
---|
[1777] | 138 | { |
---|
| 139 | return convertValue<ToType, Ogre::Real>(output, input.valueDegrees()); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | // To Radian |
---|
| 143 | template <class FromType> |
---|
[1778] | 144 | inline bool fallbackConversion(orxonox::Radian* output, const FromType input) |
---|
[1777] | 145 | { |
---|
| 146 | float temp; |
---|
| 147 | if (convertValue(&temp, input)) |
---|
| 148 | { |
---|
| 149 | *output = temp; |
---|
| 150 | return true; |
---|
| 151 | } |
---|
| 152 | else |
---|
| 153 | return false; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | // To Degree |
---|
| 157 | template <class FromType> |
---|
[1778] | 158 | inline bool fallbackConversion(orxonox::Degree* output, const FromType input) |
---|
[1777] | 159 | { |
---|
| 160 | float temp; |
---|
| 161 | if (convertValue(&temp, input)) |
---|
| 162 | { |
---|
| 163 | *output = temp; |
---|
| 164 | return true; |
---|
| 165 | } |
---|
| 166 | else |
---|
| 167 | return false; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | #endif /* _MathConvert_H__ */ |
---|