GlPortal Class Reference  0.1.1
Source code documentation of the free and open 3D action puzzle game.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Math.hpp
Go to the documentation of this file.
1 #ifndef MATH_HPP
2 #define MATH_HPP
3 
4 namespace radix {
5 
6 class Vector3f;
7 class Quaternion;
8 
12 class Math {
13 public:
14  static constexpr float PI = 3.141592653589793238462643383279502884197169399375105820974944592307;
15  static constexpr float DEG_TO_RAD = PI / 180;
16  static constexpr float RAD_TO_DEG = 180 / PI;
17 
18  static Vector3f toDirection(const Quaternion &orientation);
19  static Vector3f toEuler(const Vector3f &direction);
20 
26  template <typename T>
27  static constexpr inline T clamp(T v, T low, T high) {
28  if (v < low) {
29  return low;
30  } else if (v > high) {
31  return high;
32  }
33  return v;
34  }
35 
42  template <typename T>
43  static constexpr inline T sign(T v) {
44  if (v > 0) {
45  return 1;
46  }
47  if (v < 0) {
48  return -1;
49  }
50  return 0;
51  }
52 };
53 
54 constexpr inline float deg(float rad) {
55  return rad * Math::RAD_TO_DEG;
56 }
57 
58 constexpr inline float rad(float deg) {
59  return deg * Math::DEG_TO_RAD;
60 }
61 
62 } /* namespace radix */
63 
64 #endif /* MATH_HPP */
Definition: GameController.hpp:7
constexpr float rad(float deg)
Definition: Math.hpp:58
static constexpr float RAD_TO_DEG
Definition: Math.hpp:16
Definition: Vector4f.hpp:117
Math helper class.
Definition: Math.hpp:12
constexpr float deg(float rad)
Definition: Math.hpp:54
static constexpr float PI
Definition: Math.hpp:14
static constexpr T sign(T v)
Returns the sign of value.
Definition: Math.hpp:43
static constexpr float DEG_TO_RAD
Definition: Math.hpp:15
static Vector3f toDirection(const Quaternion &orientation)
Definition: Math.cpp:10
static Vector3f toEuler(const Vector3f &direction)
Definition: Math.cpp:14
3-dimensional float-based vector/point storage and manipulation struct
Definition: Vector3f.hpp:27
static constexpr T clamp(T v, T low, T high)
Restricts a value to a range.
Definition: Math.hpp:27