Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/util/MathConvert.h @ 2119

Last change on this file since 2119 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
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"
[2014]39#include "Math.h"
[1777]40#include "Convert.h"
41
42
43////////////////////
44// Math to string //
45////////////////////
46
47// Vector2 to std::string
[1779]48template <>
[2016]49struct ConverterExplicit<orxonox::Vector2, std::string>
[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 <>
[2016]65struct ConverterExplicit<orxonox::Vector3, std::string>
[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 <>
[2016]81struct ConverterExplicit<orxonox::Vector4, std::string>
[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 <>
[2016]97struct ConverterExplicit<orxonox::Quaternion, std::string>
[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 <>
[2016]113struct ConverterExplicit<orxonox::ColourValue, std::string>
[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
[2016]133template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector2>
[1779]134{ static bool convert(orxonox::Vector2*     output, const std::string& input); };
[1777]135// std::string to Vector3
[2016]136template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector3>
[1779]137{ static bool convert(orxonox::Vector3*     output, const std::string& input); };
[1777]138// std::string to Vector4
[2016]139template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector4>
[1779]140{ static bool convert(orxonox::Vector4*     output, const std::string& input); };
[1777]141// std::string to Quaternion
[2016]142template <> struct _UtilExport ConverterFallback<std::string, orxonox::Quaternion>
[1779]143{ static bool convert(orxonox::Quaternion*  output, const std::string& input); };
[1777]144// std::string to ColourValue
[2016]145template <> struct _UtilExport ConverterFallback<std::string, orxonox::ColourValue>
[1779]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>
[2016]155struct ConverterFallback<orxonox::Radian, ToType>
[1777]156{
[2014]157    static bool convert(ToType* output, const orxonox::Radian& input)
158    {
[2016]159        return convertValue<Ogre::Real, ToType>(output, input.valueRadians());
[2014]160    }
161};
[1777]162
163// From Degree
164template <class ToType>
[2016]165struct ConverterFallback<orxonox::Degree, ToType>
[1777]166{
[2014]167    static bool convert(ToType* output, const orxonox::Degree& input)
168    {
[2016]169        return convertValue<Ogre::Real, ToType>(output, input.valueDegrees());
[2014]170    }
171};
[1777]172
173// To Radian
174template <class FromType>
[2016]175struct ConverterFallback<FromType, orxonox::Radian>
[1777]176{
[2014]177    static bool convert(orxonox::Radian* output, const FromType& input)
[1777]178    {
[2014]179        float temp;
180        if (convertValue(&temp, input))
181        {
182            *output = temp;
183            return true;
184        }
185        else
186            return false;
[1777]187    }
[2014]188};
[1777]189
190// To Degree
191template <class FromType>
[2016]192struct ConverterFallback<FromType, orxonox::Degree>
[1777]193{
[2014]194    static bool convert(orxonox::Degree* output, const FromType& input)
[1777]195    {
[2014]196        float temp;
197        if (convertValue(&temp, input))
198        {
199            *output = temp;
200            return true;
201        }
202        else
203            return false;
[1777]204    }
[2014]205};
[1777]206
207#endif /* _MathConvert_H__ */
Note: See TracBrowser for help on using the repository browser.