Orxonox  0.0.5 Codename: Arcturus
MathConvert.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
4  *
5  *
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
36 #ifndef _MathConvert_H__
37 #define _MathConvert_H__
38
39 #include "UtilPrereqs.h"
40 #include "Math.h"
41 #include "Convert.h"
42
43 namespace orxonox
44 {
46  // Math to string //
48
50  template <>
52  {
53  ORX_FORCEINLINE static bool convert(std::string* output, const orxonox::Vector2& input)
54  {
55  std::ostringstream ostream;
56  if (ostream << input.x << ',' << input.y)
57  {
58  (*output) = ostream.str();
59  return true;
60  }
61  return false;
62  }
63  };
64
66  template <>
68  {
69  ORX_FORCEINLINE static bool convert(std::string* output, const orxonox::Vector3& input)
70  {
71  std::ostringstream ostream;
72  if (ostream << input.x << ',' << input.y << ',' << input.z)
73  {
74  (*output) = ostream.str();
75  return true;
76  }
77  return false;
78  }
79  };
80
82  template <>
84  {
85  ORX_FORCEINLINE static bool convert(std::string* output, const orxonox::Vector4& input)
86  {
87  std::ostringstream ostream;
88  if (ostream << input.x << ',' << input.y << ',' << input.z << ',' << input.w)
89  {
90  (*output) = ostream.str();
91  return true;
92  }
93  return false;
94  }
95  };
96
98  template <>
99  struct ConverterExplicit<orxonox::Quaternion, std::string>
100  {
101  ORX_FORCEINLINE static bool convert(std::string* output, const orxonox::Quaternion& input)
102  {
103  std::ostringstream ostream;
104  if (ostream << input.w << ',' << input.x << ',' << input.y << ',' << input.z)
105  {
106  (*output) = ostream.str();
107  return true;
108  }
109  return false;
110  }
111  };
112
114  template <>
115  struct ConverterExplicit<orxonox::ColourValue, std::string>
116  {
117  ORX_FORCEINLINE static bool convert(std::string* output, const orxonox::ColourValue& input)
118  {
119  std::ostringstream ostream;
120  if (ostream << input.r << ',' << input.g << ',' << input.b << ',' << input.a)
121  {
122  (*output) = ostream.str();
123  return true;
124  }
125  return false;
126  }
127  };
128
129
131  // string to Math //
133
135  template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector2>
136  { static bool convert(orxonox::Vector2* output, const std::string& input); };
138  template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector3>
139  { static bool convert(orxonox::Vector3* output, const std::string& input); };
141  template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector4>
142  { static bool convert(orxonox::Vector4* output, const std::string& input); };
144  template <> struct _UtilExport ConverterFallback<std::string, orxonox::Quaternion>
145  { static bool convert(orxonox::Quaternion* output, const std::string& input); };
147  template <> struct _UtilExport ConverterFallback<std::string, orxonox::ColourValue>
148  { static bool convert(orxonox::ColourValue* output, const std::string& input); };
149
150
152  // From and to Radian/Degree //
154
156  template <class ToType>
158  {
159  ORX_FORCEINLINE static bool convert(ToType* output, const orxonox::Radian& input)
160  {
162  }
163  };
164
166  template <class ToType>
167  struct ConverterFallback<orxonox::Degree, ToType>
168  {
169  ORX_FORCEINLINE static bool convert(ToType* output, const orxonox::Degree& input)
170  {
171  return convertValue<Ogre::Real, ToType>(output, input.valueDegrees());
172  }
173  };
174
176  template <class FromType>
178  {
179  ORX_FORCEINLINE static bool convert(orxonox::Radian* output, const FromType& input)
180  {
181  float temp;
182  if (convertValue(&temp, input))
183  {
184  *output = temp;
185  return true;
186  }
187  else
188  return false;
189  }
190  };
191
193  template <class FromType>
194  struct ConverterFallback<FromType, orxonox::Degree>
195  {
196  ORX_FORCEINLINE static bool convert(orxonox::Degree* output, const FromType& input)
197  {
198  float temp;
199  if (convertValue(&temp, input))
200  {
201  *output = temp;
202  return true;
203  }
204  else
205  return false;
206  }
207  };
208 }
209
210 #endif /* _MathConvert_H__ */
#define _UtilExport
Definition: UtilPrereqs.h:60
static ORX_FORCEINLINE bool convert(orxonox::Radian *output, const FromType &input)
Definition: MathConvert.h:179
::std::string string
Definition: gtest-port.h:756
Default template if no orxonox::ConverterExplicit is available.
Definition: Convert.h:308
static ORX_FORCEINLINE bool convert(ToType *output, const orxonox::Radian &input)
Definition: MathConvert.h:159
STL namespace.
static ORX_FORCEINLINE bool convert(std::string *output, const orxonox::Vector4 &input)
Definition: MathConvert.h:85
static ORX_FORCEINLINE bool convert(std::string *output, const orxonox::ColourValue &input)
Definition: MathConvert.h:117
Default template. No conversion available at all.
Definition: Convert.h:149
Functions that convert values between different types.
Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the ...
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
ORX_FORCEINLINE bool convertValue(ToType *output, const FromType &input)
Converts any value to any other as long as there exists a conversion.
Definition: Convert.h:335
Shared library macros, enums, constants and forward declarations for the util library ...
static ORX_FORCEINLINE bool convert(std::string *output, const orxonox::Vector2 &input)
Definition: MathConvert.h:53
static ORX_FORCEINLINE bool convert(std::string *output, const orxonox::Vector3 &input)
Definition: MathConvert.h:69
static ORX_FORCEINLINE bool convert(orxonox::Degree *output, const FromType &input)
Definition: MathConvert.h:196
static ORX_FORCEINLINE bool convert(std::string *output, const orxonox::Quaternion &input)
Definition: MathConvert.h:101
#define ORX_FORCEINLINE
Definition: OrxonoxConfig.h:95
static ORX_FORCEINLINE bool convert(ToType *output, const orxonox::Degree &input)
Definition: MathConvert.h:169
static ORX_FORCEINLINE bool convert(ToType *output, const FromType &input)
Definition: Convert.h:311