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