Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gcc didn't like me..

  • Property svn:eol-style set to native
File size: 5.2 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
32        Math conversion functions. Definitions are in Math.cc
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
48template <>
49struct ConverterExplicit<std::string, orxonox::Vector2>
50{
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
64template <>
65struct ConverterExplicit<std::string, orxonox::Vector3>
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
80template <>
81struct ConverterExplicit<std::string, orxonox::Vector4>
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
96template <>
97struct ConverterExplicit<std::string, orxonox::Quaternion>
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
112template <>
113struct ConverterExplicit<std::string, orxonox::ColourValue>
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
133template <> struct _UtilExport ConverterFallback<orxonox::Vector2,     std::string>
134{ static bool convert(orxonox::Vector2*     output, const std::string& input); };
135// std::string to Vector3
136template <> struct _UtilExport ConverterFallback<orxonox::Vector3,     std::string>
137{ static bool convert(orxonox::Vector3*     output, const std::string& input); };
138// std::string to Vector4
139template <> struct _UtilExport ConverterFallback<orxonox::Vector4,     std::string>
140{ static bool convert(orxonox::Vector4*     output, const std::string& input); };
141// std::string to Quaternion
142template <> struct _UtilExport ConverterFallback<orxonox::Quaternion,  std::string>
143{ static bool convert(orxonox::Quaternion*  output, const std::string& input); };
144// std::string to ColourValue
145template <> struct _UtilExport ConverterFallback<orxonox::ColourValue, std::string>
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
154template <class ToType>
155inline bool fallbackConversion(ToType* output, const orxonox::Radian input)
156{
157    return convertValue<ToType, Ogre::Real>(output, input.valueRadians()); 
158}
159
160// From Degree
161template <class ToType>
162inline bool fallbackConversion(ToType* output, const orxonox::Degree input)
163{
164    return convertValue<ToType, Ogre::Real>(output, input.valueDegrees()); 
165}
166
167// To Radian
168template <class FromType>
169inline bool fallbackConversion(orxonox::Radian* output, const FromType input)
170{
171    float temp;
172    if (convertValue(&temp, input))
173    {
174        *output = temp;
175        return true;
176    }
177    else
178        return false;
179}
180
181// To Degree
182template <class FromType>
183inline bool fallbackConversion(orxonox::Degree* output, const FromType input)
184{
185    float temp;
186    if (convertValue(&temp, input))
187    {
188        *output = temp;
189        return true;
190    }
191    else
192        return false;
193}
194
195#endif /* _MathConvert_H__ */
Note: See TracBrowser for help on using the repository browser.