Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/util/Math.h @ 1344

Last change on this file since 1344 was 1344, checked in by rgrieder, 17 years ago
  • added scroll wheel support
  • improved mouse input handling
  • added support for mouse input derivation (allows to use the track stick like a joy stick)

About the new key binder in general:
You can assign any button/key/axis any combination of command strings the way you want.
When using simple commands (shortcuts) without parameters depending on the input, there are 3 keybind modes: OnPress, OnRelease and OnHold. For the case you assign such a command to a mouse/joystick axis, the input is translated to switch-like behavior (can be configured by feeding ButtonThreshold argument as ONE key binding).
With parameter controlled commands, keys are simply 1 or 0, axis are of course continuous. There are two ways a command can expect a value: relative or absolute input. For instance the joystick axis state (-1 to 1) is an absolute value, mouse movement is relative. Once again, everything is translated in the right way.
There's a lot more to explain, but I guess I'm gonna write a wiki page for that…

one last note: I haven't yet changed the way input is handled in the space ship. I shall do that after the merge tomorrow.

File size: 3.6 KB
RevLine 
[871]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[871]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 *   Co-authors:
25 *      ...
26 *
27 */
28
[1052]29#ifndef _Util_Math_H__
30#define _Util_Math_H__
[871]31
[1062]32#include "UtilPrereqs.h"
33
[871]34#include <ostream>
35
[708]36#include <OgreMath.h>
[716]37#include <OgreVector2.h>
38#include <OgreVector3.h>
39#include <OgreVector4.h>
40#include <OgreMatrix3.h>
41#include <OgreQuaternion.h>
42#include <OgreColourValue.h>
[708]43
44namespace orxonox
45{
46  typedef Ogre::Radian Radian;
47  typedef Ogre::Degree Degree;
[716]48  typedef Ogre::Vector2 Vector2;
49  typedef Ogre::Vector3 Vector3;
50  typedef Ogre::Vector4 Vector4;
51  typedef Ogre::Matrix3 Matrix3;
52  typedef Ogre::Quaternion Quaternion;
53  typedef Ogre::ColourValue ColourValue;
[708]54}
[871]55
56_UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Radian& radian);
57_UtilExport std::istream& operator>>(std::istream& in, orxonox::Radian& radian);
58_UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree);
59_UtilExport std::istream& operator>>(std::istream& in, orxonox::Degree& degree);
60
61template <typename T>
62inline T sgn(T x)
63{
64    return (x >= 0) ? 1 : -1;
65}
66
67template <typename T>
68inline T min(T a, T b)
69{
70    return (a <= b) ? a : b;
71}
72
73template <typename T>
74inline T max(T a, T b)
75{
76    return (a >= b) ? a : b;
77}
78
79template <typename T>
80inline T clamp(T x, T min, T max)
81{
82    if (x < min)
83        return min;
84
85    if (x > max)
86        return max;
87
88    return x;
89}
90
91template <typename T>
92inline T square(T x)
93{
94    return x*x;
95}
96
97template <typename T>
98inline T cube(T x)
99{
100    return x*x*x;
101}
102
103template <typename T>
104inline int floor(T x)
105{
106    return (int)(x);
107}
108
109template <typename T>
110inline int ceil(T x)
111{
112    int temp = floor(x);
113    return (temp != x) ? (temp + 1) : temp;
114}
115
116template <typename T>
117inline int round(T x)
118{
119    return (int)(x + 0.5);
120}
121
122template <typename T>
123T interpolate(float time, const T& start, const T& end)
124{
125    return time * (end - start) + start;
126}
127
128template <typename T>
129T interpolateSmooth(float time, const T& start, const T& end)
130{
131    return (-2 * (end - start) * cube(time)) + (3 * (end - start) * square(time)) + start;
132}
133
134inline _UtilExport float rnd()
135{
136    return ((float)rand() / RAND_MAX);
137}
138
139inline _UtilExport float rnd(float max)
140{
141    return rnd() * max;
142}
143
144inline _UtilExport float rnd(float min, float max)
145{
146    return rnd(max - min) + min;
147}
148
[1323]149class _UtilExport IntVector2
150{
151public:
152  IntVector2() : x(0), y(0) { }
153  IntVector2(int _x, int _y) : x(_x), y(_y) { }
154  int x;
155  int y;
156};
157
[1344]158class _UtilExport IntVector3
159{
160public:
161  IntVector3() : x(0), y(0), z(0) { }
162  IntVector3(int _x, int _y, int _z) : x(_x), y(_y), z(_z) { }
163  int x;
164  int y;
165  int z;
166};
167
[1052]168#endif /* _Util_Math_H__ */
Note: See TracBrowser for help on using the repository browser.