40 #ifndef _Util_Math_H__ 41 #define _Util_Math_H__ 49 #include <type_traits> 52 #include <OgreVector2.h> 53 #include <OgreVector3.h> 54 #include <OgreVector4.h> 55 #include <OgreQuaternion.h> 56 #include <OgreColourValue.h> 77 constexpr
float twoPi = 6.283185482025146484375f;
78 constexpr
float pi = 3.1415927410125732421875f;
79 constexpr
float pi_2 = 1.57079637050628662109375f;
80 constexpr
float pi_4 = 0.785398185253143310546875f;
81 constexpr
float e = 2.718281269073486328125f;
82 constexpr
float sqrt2 = 1.41421353816986083984375f;
83 constexpr
float sqrt2_2 = 0.707106769084930419921875f;
86 #if OGRE_VERSION < 0x010603 93 _UtilExport float getAngle(
const orxonox::Vector3& myposition,
const orxonox::Vector3& mydirection,
const orxonox::Vector3& otherposition);
94 _UtilExport orxonox::Vector2
get2DViewdirection(
const orxonox::Vector3& myposition,
const orxonox::Vector3& mydirection,
const orxonox::Vector3& myorthonormal,
const orxonox::Vector3& otherposition);
95 _UtilExport orxonox::Vector2
get2DViewCoordinates(
const orxonox::Vector3& myposition,
const orxonox::Vector3& mydirection,
const orxonox::Vector3& myorthonormal,
const orxonox::Vector3& otherposition);
96 _UtilExport orxonox::Vector2
get3DProjection(
const orxonox::Vector3& myposition,
const orxonox::Vector3& mydirection,
const orxonox::Vector3& myorthonormal,
const orxonox::Vector3& otherposition,
const float mapangle,
const float detectionlimit);
97 _UtilExport bool isObjectHigherThanShipOnMap(
const orxonox::Vector3& myposition,
const orxonox::Vector3& mydirection,
const orxonox::Vector3& myorthonormal,
const orxonox::Vector3& otherposition,
const float mapangle);
98 _UtilExport int determineMap3DZOrder(
const orxonox::Vector3& myposition,
const orxonox::Vector3& mydirection,
const orxonox::Vector3& myorthonormal,
const orxonox::Vector3& otherposition,
const float detectionlimit);
99 _UtilExport orxonox::Vector3
getTransformedVector(
const orxonox::Vector3& distance,
const orxonox::Vector3& mydirection,
const orxonox::Vector3& myorthonormal,
const orxonox::Vector3& myside);
100 _UtilExport orxonox::Vector3
getPredictedPosition(
const orxonox::Vector3& myposition,
float projectilespeed,
const orxonox::Vector3& targetposition,
const orxonox::Vector3& targetvelocity);
107 template <
typename T>
110 return (x >= 0) ? (
T)1 : (
T)-1;
119 template <
typename T>
122 return x < min ? min : (x > max ? max : x);
128 template <
typename T>
137 template <
typename T>
161 template <
typename T>
169 return (temp < 0) ? (temp + max) : temp;
181 template <
typename T>
typename std::enable_if<!std::is_enum<T>::value,
T>::type
185 static_assert(
sizeof(
T) !=
sizeof(
T),
"No template specialization available for T");
188 template <
typename T>
typename std::enable_if<std::is_enum<T>::value,
T>::type
191 return static_cast<T>(zeroise<typename std::underlying_type<T>::type>());
210 template <>
inline orxonox::Radian zeroise<orxonox::Radian>() {
return orxonox::Radian(0.0f); }
211 template <>
inline orxonox::Degree zeroise<orxonox::Degree>() {
return orxonox::Degree(0.0f); }
212 template <>
inline orxonox::Vector2 zeroise<orxonox::Vector2>() {
return orxonox::Vector2 (0, 0) ; }
213 template <>
inline orxonox::Vector3 zeroise<orxonox::Vector3>() {
return orxonox::Vector3 (0, 0, 0) ; }
214 template <>
inline orxonox::Vector4 zeroise<orxonox::Vector4>() {
return orxonox::Vector4 (0, 0, 0, 0); }
215 template <>
inline orxonox::ColourValue zeroise<orxonox::ColourValue>() {
return orxonox::ColourValue(0, 0, 0, 0); }
216 template <>
inline orxonox::Quaternion zeroise<orxonox::Quaternion>() {
return orxonox::Quaternion (0, 0, 0, 0); }
222 template <
typename T>
225 inline operator const T&()
const 231 template <
typename T>
241 template <
typename T>
244 return static_cast<T>(time * (end - start) + start);
254 template <
typename T>
257 return static_cast<T>((-2 * (end - start) *
cube(time)) + (3 * (end - start) *
square(time)) + start);
273 detail::rngen.seed(seed);
281 inline float rnd(
float min,
float max)
283 std::uniform_real_distribution<float> dist(min, max);
284 return dist(detail::rngen);
299 inline float rnd(
float max)
309 std::uniform_int_distribution<> dist;
310 return static_cast<float>((dist(detail::rngen) & 0x2) - 1);
unsigned long getUniqueNumber()
Returns a unique number.
Definition: Math.cc:382
constexpr T square(T x)
Returns the squared value (x^2).
Definition: Math.h:129
#define _UtilExport
Definition: UtilPrereqs.h:60
constexpr float e
e
Definition: Math.h:81
T interpolateSmooth(float time, const T &start, const T &end)
Interpolates smoothly between two values for a time between 0 and 1.
Definition: Math.h:255
Provides zero value symbols that can be returned as reference.
Definition: Math.h:223
float rndsgn()
Returns randomly 1 or -1 with equal probability.
Definition: Math.h:307
long double zeroise< long double >()
Definition: Math.h:206
static T value
Definition: Math.h:229
unsigned char zeroise< unsigned char >()
Definition: Math.h:195
constexpr T sgn(T x)
Returns the sign of the given value.
Definition: Math.h:108
::std::string string
Definition: gtest-port.h:756
constexpr float pi
PI.
Definition: Math.h:78
float rnd(float min, float max)
Returns a random number between min and almost max: min <= rnd < max.
Definition: Math.h:281
orxonox::Vector2 get2DViewdirection(const orxonox::Vector3 &myposition, const orxonox::Vector3 &mydirection, const orxonox::Vector3 &myorthonormal, const orxonox::Vector3 &otherposition)
Gets the 2D viewing direction (up/down, left/right) to the position of the other object.
Definition: Math.cc:123
bool zeroise< bool >()
Definition: Math.h:207
long long zeroise< long long >()
Definition: Math.h:202
char zeroise< char >()
Definition: Math.h:194
constexpr T clamp(T x, T min, T max)
Keeps a value between a lower and an upper limit.
Definition: Math.h:120
float getAngle(const orxonox::Vector3 &myposition, const orxonox::Vector3 &mydirection, const orxonox::Vector3 &otherposition)
Gets the angle between my viewing direction and the direction to the position of the other object...
Definition: Math.cc:98
bool isObjectHigherThanShipOnMap(const orxonox::Vector3 &myposition, const orxonox::Vector3 &mydirection, const orxonox::Vector3 &myorthonormal, const orxonox::Vector3 &otherposition, const float mapangle)
Gets if a object is over the x/z - plain on map.
Definition: Math.cc:243
orxonox::Vector2 get2DViewCoordinates(const orxonox::Vector3 &myposition, const orxonox::Vector3 &mydirection, const orxonox::Vector3 &myorthonormal, const orxonox::Vector3 &otherposition)
Gets the 2D viewing direction (up/down, left/right) to the position of the other object, multiplied with the viewing distance to the object (0° = 0, 180° = 1).
Definition: Math.cc:163
constexpr T cube(T x)
Returns the cubed value (x^3).
Definition: Math.h:138
T interpolate(float time, const T &start, const T &end)
Interpolates between two values for a time between 0 and 1.
Definition: Math.h:242
void * zeroise< void * >()
Definition: Math.h:208
double zeroise< double >()
Definition: Math.h:205
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Shared library macros, enums, constants and forward declarations for the util library ...
std::istream & operator>>(std::istream &in, orxonox::Radian &radian)
Function for reading a Radian from a stream.
Definition: Math.cc:66
void rndseed(unsigned int seed)
Seeds the random number generator used for the functions below.
Definition: Math.h:271
std::ostream & operator<<(std::ostream &out, const std::set< const Identifier * > &list)
Lists the names of all Identifiers in a std::set<const Identifier*>.
Definition: Identifier.cc:466
int determineMap3DZOrder(const orxonox::Vector3 &myposition, const orxonox::Vector3 &mydirection, const orxonox::Vector3 &myorthonormal, const orxonox::Vector3 &otherposition, const float detectionlimit)
A value between 0 and 10, in order how other object is in front or in back.
Definition: Math.cc:273
long zeroise< long >()
Definition: Math.h:200
Definition: InputPrereqs.h:78
unsigned long zeroise< unsigned long >()
Definition: Math.h:201
float zeroise< float >()
Definition: Math.h:204
unsigned long long zeroise< unsigned long long >()
Definition: Math.h:203
constexpr float pi_4
PI / 4.
Definition: Math.h:80
std::enable_if<!std::is_enum< T >::value, T >::type zeroise()
Returns a "zero" value for the given type.
Definition: Math.h:182
unsigned int zeroise< unsigned int >()
Definition: Math.h:199
constexpr float sqrt2_2
sqrt(2) / 2
Definition: Math.h:83
constexpr float sqrt2
sqrt(2)
Definition: Math.h:82
orxonox::Vector3 getPredictedPosition(const orxonox::Vector3 &myposition, float projectilespeed, const orxonox::Vector3 &targetposition, const orxonox::Vector3 &targetvelocity)
Returns the predicted position I have to aim at, if I want to hit a moving target with a moving proje...
Definition: Math.cc:351
int zeroise< int >()
Definition: Math.h:198
orxonox::Vector2 get3DProjection(const orxonox::Vector3 &myposition, const orxonox::Vector3 &mydirection, const orxonox::Vector3 &myorthonormal, const orxonox::Vector3 &otherposition, const float mapangle, const float detectionlimit)
Gets the 2D project vector for the 3D Radar .
Definition: Math.cc:204
orxonox::Vector3 getTransformedVector(const orxonox::Vector3 &totransform, const orxonox::Vector3 &newx, const orxonox::Vector3 &newy, const orxonox::Vector3 &newz)
Gets the new vector after a coordinate transformation.
Definition: Math.cc:309
unsigned short zeroise< unsigned short >()
Definition: Math.h:197
constexpr float pi_2
PI / 2.
Definition: Math.h:79
int mod(T x, int max)
The modulo operation, enhanced to work properly with negative values.
Definition: Math.h:162
short zeroise< short >()
Definition: Math.h:196
constexpr float twoPi
PI * 2.
Definition: Math.h:77