Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1867 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
RevLine 
[1777]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
[1778]29/**
[1777]30    @file
[1778]31    @brief
32        Math conversion functions. Definitions are in Math.cc
[1777]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
[1779]48template <>
49struct ConverterExplicit<std::string, orxonox::Vector2>
[1777]50{
[1779]51    static bool convert(std::string* output, const orxonox::Vector2& input)
[1777]52    {
[1779]53        std::ostringstream ostream;
54        if (ostream << input.x << "," << input.y)
55        {
56            (*output) = ostream.str();
57            return true;
58        }
59        return false;
[1777]60    }
[1779]61};
[1777]62
63// Vector3 to std::string
[1779]64template <>
65struct ConverterExplicit<std::string, orxonox::Vector3>
[1777]66{
[1779]67    static bool convert(std::string* output, const orxonox::Vector3& input)
[1777]68    {
[1779]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;
[1777]76    }
[1779]77};
[1777]78
79// Vector4 to std::string
[1779]80template <>
81struct ConverterExplicit<std::string, orxonox::Vector4>
[1777]82{
[1779]83    static bool convert(std::string* output, const orxonox::Vector4& input)
[1777]84    {
[1779]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;
[1777]92    }
[1779]93};
[1777]94
95// Quaternion to std::string
[1779]96template <>
97struct ConverterExplicit<std::string, orxonox::Quaternion>
[1777]98{
[1779]99    static bool convert(std::string* output, const orxonox::Quaternion& input)
[1777]100    {
[1779]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;
[1777]108    }
[1779]109};
[1777]110
111// ColourValue to std::string
[1779]112template <>
113struct ConverterExplicit<std::string, orxonox::ColourValue>
[1777]114{
[1779]115    static bool convert(std::string* output, const orxonox::ColourValue& input)
[1777]116    {
[1779]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;
[1777]124    }
[1779]125};
[1777]126
127
128////////////////////
129// string to Math //
130////////////////////
131
132// std::string to Vector2
[1779]133template <> struct _UtilExport ConverterFallback<orxonox::Vector2,     std::string>
134{ static bool convert(orxonox::Vector2*     output, const std::string& input); };
[1777]135// std::string to Vector3
[1779]136template <> struct _UtilExport ConverterFallback<orxonox::Vector3,     std::string>
137{ static bool convert(orxonox::Vector3*     output, const std::string& input); };
[1777]138// std::string to Vector4
[1779]139template <> struct _UtilExport ConverterFallback<orxonox::Vector4,     std::string>
140{ static bool convert(orxonox::Vector4*     output, const std::string& input); };
[1777]141// std::string to Quaternion
[1779]142template <> struct _UtilExport ConverterFallback<orxonox::Quaternion,  std::string>
143{ static bool convert(orxonox::Quaternion*  output, const std::string& input); };
[1777]144// std::string to ColourValue
[1779]145template <> struct _UtilExport ConverterFallback<orxonox::ColourValue, std::string>
146{ static bool convert(orxonox::ColourValue* output, const std::string& input); };
[1777]147
148
149///////////////////////////////
150// From and to Radian/Degree //
151///////////////////////////////
152
153// From Radian
154template <class ToType>
[1778]155inline bool fallbackConversion(ToType* output, const orxonox::Radian input)
[1777]156{
157    return convertValue<ToType, Ogre::Real>(output, input.valueRadians()); 
158}
159
160// From Degree
161template <class ToType>
[1778]162inline bool fallbackConversion(ToType* output, const orxonox::Degree input)
[1777]163{
164    return convertValue<ToType, Ogre::Real>(output, input.valueDegrees()); 
165}
166
167// To Radian
168template <class FromType>
[1778]169inline bool fallbackConversion(orxonox::Radian* output, const FromType input)
[1777]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>
[1778]183inline bool fallbackConversion(orxonox::Degree* output, const FromType input)
[1777]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.