[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" |
---|
[2014] | 39 | #include "Math.h" |
---|
[1777] | 40 | #include "Convert.h" |
---|
| 41 | |
---|
[2171] | 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | //////////////////// |
---|
| 45 | // Math to string // |
---|
| 46 | //////////////////// |
---|
[1777] | 47 | |
---|
[2171] | 48 | // Vector2 to std::string |
---|
| 49 | template <> |
---|
| 50 | struct ConverterExplicit<orxonox::Vector2, std::string> |
---|
[1777] | 51 | { |
---|
[3196] | 52 | FORCEINLINE static bool convert(std::string* output, const orxonox::Vector2& input) |
---|
[1779] | 53 | { |
---|
[2171] | 54 | std::ostringstream ostream; |
---|
[6417] | 55 | if (ostream << input.x << ',' << input.y) |
---|
[2171] | 56 | { |
---|
| 57 | (*output) = ostream.str(); |
---|
| 58 | return true; |
---|
| 59 | } |
---|
| 60 | return false; |
---|
[1779] | 61 | } |
---|
[2171] | 62 | }; |
---|
[1777] | 63 | |
---|
[2171] | 64 | // Vector3 to std::string |
---|
| 65 | template <> |
---|
| 66 | struct ConverterExplicit<orxonox::Vector3, std::string> |
---|
[1777] | 67 | { |
---|
[3196] | 68 | FORCEINLINE static bool convert(std::string* output, const orxonox::Vector3& input) |
---|
[1779] | 69 | { |
---|
[2171] | 70 | std::ostringstream ostream; |
---|
[6417] | 71 | if (ostream << input.x << ',' << input.y << ',' << input.z) |
---|
[2171] | 72 | { |
---|
| 73 | (*output) = ostream.str(); |
---|
| 74 | return true; |
---|
| 75 | } |
---|
| 76 | return false; |
---|
[1779] | 77 | } |
---|
[2171] | 78 | }; |
---|
[1777] | 79 | |
---|
[2171] | 80 | // Vector4 to std::string |
---|
| 81 | template <> |
---|
| 82 | struct ConverterExplicit<orxonox::Vector4, std::string> |
---|
[1777] | 83 | { |
---|
[3196] | 84 | FORCEINLINE static bool convert(std::string* output, const orxonox::Vector4& input) |
---|
[1779] | 85 | { |
---|
[2171] | 86 | std::ostringstream ostream; |
---|
[6417] | 87 | if (ostream << input.x << ',' << input.y << ',' << input.z << ',' << input.w) |
---|
[2171] | 88 | { |
---|
| 89 | (*output) = ostream.str(); |
---|
| 90 | return true; |
---|
| 91 | } |
---|
| 92 | return false; |
---|
[1779] | 93 | } |
---|
[2171] | 94 | }; |
---|
[1777] | 95 | |
---|
[2171] | 96 | // Quaternion to std::string |
---|
| 97 | template <> |
---|
| 98 | struct ConverterExplicit<orxonox::Quaternion, std::string> |
---|
[1777] | 99 | { |
---|
[3196] | 100 | FORCEINLINE static bool convert(std::string* output, const orxonox::Quaternion& input) |
---|
[1779] | 101 | { |
---|
[2171] | 102 | std::ostringstream ostream; |
---|
[6417] | 103 | if (ostream << input.w << ',' << input.x << ',' << input.y << ',' << input.z) |
---|
[2171] | 104 | { |
---|
| 105 | (*output) = ostream.str(); |
---|
| 106 | return true; |
---|
| 107 | } |
---|
| 108 | return false; |
---|
[1779] | 109 | } |
---|
[2171] | 110 | }; |
---|
[1777] | 111 | |
---|
[2171] | 112 | // ColourValue to std::string |
---|
| 113 | template <> |
---|
| 114 | struct ConverterExplicit<orxonox::ColourValue, std::string> |
---|
[1777] | 115 | { |
---|
[3196] | 116 | FORCEINLINE static bool convert(std::string* output, const orxonox::ColourValue& input) |
---|
[1779] | 117 | { |
---|
[2171] | 118 | std::ostringstream ostream; |
---|
[6417] | 119 | if (ostream << input.r << ',' << input.g << ',' << input.b << ',' << input.a) |
---|
[2171] | 120 | { |
---|
| 121 | (*output) = ostream.str(); |
---|
| 122 | return true; |
---|
| 123 | } |
---|
| 124 | return false; |
---|
[1779] | 125 | } |
---|
[2171] | 126 | }; |
---|
[1777] | 127 | |
---|
| 128 | |
---|
[2171] | 129 | //////////////////// |
---|
| 130 | // string to Math // |
---|
| 131 | //////////////////// |
---|
[1777] | 132 | |
---|
[2171] | 133 | // std::string to Vector2 |
---|
| 134 | template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector2> |
---|
| 135 | { static bool convert(orxonox::Vector2* output, const std::string& input); }; |
---|
| 136 | // std::string to Vector3 |
---|
| 137 | template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector3> |
---|
| 138 | { static bool convert(orxonox::Vector3* output, const std::string& input); }; |
---|
| 139 | // std::string to Vector4 |
---|
| 140 | template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector4> |
---|
| 141 | { static bool convert(orxonox::Vector4* output, const std::string& input); }; |
---|
| 142 | // std::string to Quaternion |
---|
| 143 | template <> struct _UtilExport ConverterFallback<std::string, orxonox::Quaternion> |
---|
| 144 | { static bool convert(orxonox::Quaternion* output, const std::string& input); }; |
---|
| 145 | // std::string to ColourValue |
---|
| 146 | template <> struct _UtilExport ConverterFallback<std::string, orxonox::ColourValue> |
---|
| 147 | { static bool convert(orxonox::ColourValue* output, const std::string& input); }; |
---|
[1777] | 148 | |
---|
| 149 | |
---|
[2171] | 150 | /////////////////////////////// |
---|
| 151 | // From and to Radian/Degree // |
---|
| 152 | /////////////////////////////// |
---|
[1777] | 153 | |
---|
[2171] | 154 | // From Radian |
---|
| 155 | template <class ToType> |
---|
| 156 | struct ConverterFallback<orxonox::Radian, ToType> |
---|
[2014] | 157 | { |
---|
[3196] | 158 | FORCEINLINE static bool convert(ToType* output, const orxonox::Radian& input) |
---|
[2171] | 159 | { |
---|
| 160 | return convertValue<Ogre::Real, ToType>(output, input.valueRadians()); |
---|
| 161 | } |
---|
| 162 | }; |
---|
[1777] | 163 | |
---|
[2171] | 164 | // From Degree |
---|
| 165 | template <class ToType> |
---|
| 166 | struct ConverterFallback<orxonox::Degree, ToType> |
---|
[2014] | 167 | { |
---|
[3196] | 168 | FORCEINLINE static bool convert(ToType* output, const orxonox::Degree& input) |
---|
[2171] | 169 | { |
---|
| 170 | return convertValue<Ogre::Real, ToType>(output, input.valueDegrees()); |
---|
| 171 | } |
---|
| 172 | }; |
---|
[1777] | 173 | |
---|
[2171] | 174 | // To Radian |
---|
| 175 | template <class FromType> |
---|
| 176 | struct ConverterFallback<FromType, orxonox::Radian> |
---|
[1777] | 177 | { |
---|
[3196] | 178 | FORCEINLINE static bool convert(orxonox::Radian* output, const FromType& input) |
---|
[2014] | 179 | { |
---|
[2171] | 180 | float temp; |
---|
| 181 | if (convertValue(&temp, input)) |
---|
| 182 | { |
---|
| 183 | *output = temp; |
---|
| 184 | return true; |
---|
| 185 | } |
---|
| 186 | else |
---|
| 187 | return false; |
---|
[2014] | 188 | } |
---|
[2171] | 189 | }; |
---|
[1777] | 190 | |
---|
[2171] | 191 | // To Degree |
---|
| 192 | template <class FromType> |
---|
| 193 | struct ConverterFallback<FromType, orxonox::Degree> |
---|
[1777] | 194 | { |
---|
[3196] | 195 | FORCEINLINE static bool convert(orxonox::Degree* output, const FromType& input) |
---|
[2014] | 196 | { |
---|
[2171] | 197 | float temp; |
---|
| 198 | if (convertValue(&temp, input)) |
---|
| 199 | { |
---|
| 200 | *output = temp; |
---|
| 201 | return true; |
---|
| 202 | } |
---|
| 203 | else |
---|
| 204 | return false; |
---|
[2014] | 205 | } |
---|
[2171] | 206 | }; |
---|
| 207 | } |
---|
[1777] | 208 | |
---|
| 209 | #endif /* _MathConvert_H__ */ |
---|