Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/util/MathConvert.h @ 1777

Last change on this file since 1777 was 1777, checked in by rgrieder, 16 years ago

svn save

  • Property svn:eol-style set to native
File size: 6.7 KB
Line 
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
29/*!
30    @file
31    @brief Actual conversion functions.
32*/
33
34#ifndef _MathConvert_H__
35#define _MathConvert_H__
36
37#include "UtilPrereqs.h"
38#include "Convert.h"
39#include "Math.h"
40
41// Note: explicitConversion function is used whenever possible prior to
42//       template specialisations to allow for manual calls and overwrites.
43
44
45////////////////////
46// Math to string //
47////////////////////
48
49// Vector2 to std::string
50inline bool explicitConversion(std::string* output, const orxonox::Vector2& input)
51{
52    std::ostringstream ostream;
53    if (ostream << input.x << "," << input.y)
54    {
55        (*output) = ostream.str();
56        return true;
57    }
58    return false;
59}
60
61// Vector3 to std::string
62inline bool explicitConversion(std::string* output, const orxonox::Vector3& input)
63{
64    std::ostringstream ostream;
65    if (ostream << input.x << "," << input.y << "," << input.z)
66    {
67        (*output) = ostream.str();
68        return true;
69    }
70    return false;
71}
72
73// Vector4 to std::string
74inline bool explicitConversion(std::string* output, const orxonox::Vector4& input)
75{
76    std::ostringstream ostream;
77    if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)
78    {
79        (*output) = ostream.str();
80        return true;
81    }
82    return false;
83}
84
85// Quaternion to std::string
86inline bool explicitConversion(std::string* output, const orxonox::Quaternion& input)
87{
88    std::ostringstream ostream;
89    if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)
90    {
91        (*output) = ostream.str();
92        return true;
93    }
94    return false;
95}
96
97// ColourValue to std::string
98inline bool explicitConversion(std::string* output, const orxonox::ColourValue& input)
99{
100    std::ostringstream ostream;
101    if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
102    {
103        (*output) = ostream.str();
104        return true;
105    }
106    return false;
107}
108
109
110////////////////////
111// string to Math //
112////////////////////
113
114// std::string to Vector2
115_UtilExport bool explicitConversion(orxonox::Vector2* output, const std::string& input);
116// std::string to Vector3
117_UtilExport bool explicitConversion(orxonox::Vector3* output, const std::string& input);
118// std::string to Vector4
119_UtilExport bool explicitConversion(orxonox::Vector4* output, const std::string& input);
120// std::string to Quaternion
121_UtilExport bool explicitConversion(orxonox::Quaternion* output, const std::string& input);
122// std::string to ColourValue
123_UtilExport bool explicitConversion(orxonox::ColourValue* output, const std::string& input);
124
125
126///////////////////////////////
127// From and to Radian/Degree //
128///////////////////////////////
129
130// From Radian
131template <class ToType>
132inline bool explicitConversion(ToType* output, const orxonox::Radian input)
133{
134    return convertValue<ToType, Ogre::Real>(output, input.valueRadians()); 
135}
136
137// From Degree
138template <class ToType>
139inline bool explicitConversion(ToType* output, const orxonox::Degree input)
140{
141    return convertValue<ToType, Ogre::Real>(output, input.valueDegrees()); 
142}
143
144// To Radian
145template <class FromType>
146inline bool explicitConversion(orxonox::Radian* output, const FromType input)
147{
148    float temp;
149    if (convertValue(&temp, input))
150    {
151        *output = temp;
152        return true;
153    }
154    else
155        return false;
156}
157
158// To Degree
159template <class FromType>
160inline bool explicitConversion(orxonox::Degree* output, const FromType input)
161{
162    float temp;
163    if (convertValue(&temp, input))
164    {
165        *output = temp;
166        return true;
167    }
168    else
169        return false;
170}
171// Radian to Radian
172inline bool explicitConversion(orxonox::Radian* output, const orxonox::Radian input)
173{ *output = input; return true; }
174// Degree to Degree
175inline bool explicitConversion(orxonox::Degree* output, const orxonox::Degree input)
176{ *output = input; return true; }
177// Radian to Degree
178inline bool explicitConversion(orxonox::Degree* output, const orxonox::Radian input)
179{ *output = input; return true; }
180// Degree to Radian
181inline bool explicitConversion(orxonox::Radian* output, const orxonox::Degree input)
182{ *output = input; return true; }
183
184//template <class ToType>
185//struct ConverterExplicit<ToType, Ogre::Radian>
186//{
187//    static bool convert(ToType* output, const Ogre::Radian input)
188//    {
189//        return ConverterExplicit<ToType, Ogre::Real>::convert(output, input.valueRadians());
190//    }
191//};
192
193//// Conversion from Ogre::Radian
194//template <class ToType>
195//struct ConverterExplicit<ToType, const Ogre::Radian>
196//{
197//    static bool convert(ToType* output, const Ogre::Radian input)
198//    {
199//        return ConverterExplicit<ToType, Ogre::Real>::convert(output, input.getValueRadian());
200//    }
201//};
202
203//template <class ToType>
204//inline bool explicitConversion(ToType* output, const Ogre::Radian& input)
205//{
206//    return ConvertValue(output, ;
207//}
208
209//// Conversion from Ogre::Degrees
210//inline bool explicitConversion(std::string* output, const orxonox::ColourValue& input)
211//{
212//    std::ostringstream ostream;
213//    if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
214//    {
215//        (*output) = ostream.str();
216//        return true;
217//    }
218//    return false;
219//}
220//
221//// Conversion to Ogre::Radian
222//inline bool explicitConversion(std::string* output, const orxonox::ColourValue& input)
223//{
224//    std::ostringstream ostream;
225//    if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
226//    {
227//        (*output) = ostream.str();
228//        return true;
229//    }
230//    return false;
231//}
232//
233//// Conversion to Ogre::Degrees
234//inline bool explicitConversion(std::string* output, const orxonox::ColourValue& input)
235//{
236//    std::ostringstream ostream;
237//    if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
238//    {
239//        (*output) = ostream.str();
240//        return true;
241//    }
242//    return false;
243//}
244
245#endif /* _MathConvert_H__ */
Note: See TracBrowser for help on using the repository browser.