Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Convert.h done. Has yet to be tested with gcc. And the comments have to be adapted.

  • Property svn:eol-style set to native
File size: 4.4 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
48inline bool explicitConversion(std::string* output, const orxonox::Vector2& input)
49{
50    std::ostringstream ostream;
51    if (ostream << input.x << "," << input.y)
52    {
53        (*output) = ostream.str();
54        return true;
55    }
56    return false;
57}
58
59// Vector3 to std::string
60inline bool explicitConversion(std::string* output, const orxonox::Vector3& input)
61{
62    std::ostringstream ostream;
63    if (ostream << input.x << "," << input.y << "," << input.z)
64    {
65        (*output) = ostream.str();
66        return true;
67    }
68    return false;
69}
70
71// Vector4 to std::string
72inline bool explicitConversion(std::string* output, const orxonox::Vector4& input)
73{
74    std::ostringstream ostream;
75    if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)
76    {
77        (*output) = ostream.str();
78        return true;
79    }
80    return false;
81}
82
83// Quaternion to std::string
84inline bool explicitConversion(std::string* output, const orxonox::Quaternion& input)
85{
86    std::ostringstream ostream;
87    if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)
88    {
89        (*output) = ostream.str();
90        return true;
91    }
92    return false;
93}
94
95// ColourValue to std::string
96inline bool explicitConversion(std::string* output, const orxonox::ColourValue& input)
97{
98    std::ostringstream ostream;
99    if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
100    {
101        (*output) = ostream.str();
102        return true;
103    }
104    return false;
105}
106
107
108////////////////////
109// string to Math //
110////////////////////
111
112// std::string to Vector2
113_UtilExport bool fallbackConversion(orxonox::Vector2* output, const std::string& input);
114// std::string to Vector3
115_UtilExport bool fallbackConversion(orxonox::Vector3* output, const std::string& input);
116// std::string to Vector4
117_UtilExport bool fallbackConversion(orxonox::Vector4* output, const std::string& input);
118// std::string to Quaternion
119_UtilExport bool fallbackConversion(orxonox::Quaternion* output, const std::string& input);
120// std::string to ColourValue
121_UtilExport bool fallbackConversion(orxonox::ColourValue* output, const std::string& input);
122
123
124///////////////////////////////
125// From and to Radian/Degree //
126///////////////////////////////
127
128// From Radian
129template <class ToType>
130inline bool fallbackConversion(ToType* output, const orxonox::Radian input)
131{
132    return convertValue<ToType, Ogre::Real>(output, input.valueRadians()); 
133}
134
135// From Degree
136template <class ToType>
137inline bool fallbackConversion(ToType* output, const orxonox::Degree input)
138{
139    return convertValue<ToType, Ogre::Real>(output, input.valueDegrees()); 
140}
141
142// To Radian
143template <class FromType>
144inline bool fallbackConversion(orxonox::Radian* output, const FromType input)
145{
146    float temp;
147    if (convertValue(&temp, input))
148    {
149        *output = temp;
150        return true;
151    }
152    else
153        return false;
154}
155
156// To Degree
157template <class FromType>
158inline bool fallbackConversion(orxonox::Degree* output, const FromType input)
159{
160    float temp;
161    if (convertValue(&temp, input))
162    {
163        *output = temp;
164        return true;
165    }
166    else
167        return false;
168}
169
170#endif /* _MathConvert_H__ */
Note: See TracBrowser for help on using the repository browser.