Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem2/src/util/MathConvert.h @ 2677

Last change on this file since 2677 was 2087, checked in by landauf, 16 years ago

merged objecthierarchy branch back to trunk

  • Property svn:eol-style set to native
File size: 5.5 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 "Math.h"
40#include "Convert.h"
41
42
43////////////////////
44// Math to string //
45////////////////////
46
47// Vector2 to std::string
48template <>
49struct ConverterExplicit<orxonox::Vector2, std::string>
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<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
80template <>
81struct 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
96template <>
97struct 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
112template <>
113struct 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
133template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector2>
134{ static bool convert(orxonox::Vector2*     output, const std::string& input); };
135// std::string to Vector3
136template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector3>
137{ static bool convert(orxonox::Vector3*     output, const std::string& input); };
138// std::string to Vector4
139template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector4>
140{ static bool convert(orxonox::Vector4*     output, const std::string& input); };
141// std::string to Quaternion
142template <> struct _UtilExport ConverterFallback<std::string, orxonox::Quaternion>
143{ static bool convert(orxonox::Quaternion*  output, const std::string& input); };
144// std::string to ColourValue
145template <> 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
154template <class ToType>
155struct 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
164template <class ToType>
165struct 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
174template <class FromType>
175struct 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
191template <class FromType>
192struct 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};
206
207#endif /* _MathConvert_H__ */
Note: See TracBrowser for help on using the repository browser.