SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Math.hpp
Go to the documentation of this file.
1#ifndef _MATH_H_
2#define _MATH_H_
3
4#include <cmath>
5#include <Math/Vector.hpp>
6
7#define PI 3.14159
8#define D2R PI / 180.0
9
10namespace Sleak {
11namespace Math {
12
13/// Clamps value into [min, max].
14template <typename T>
15constexpr const T& Clamp(const T& value, T min, T max) {
16 return (value < min) ? min : (value > max) ? max : value;
17}
18
19/// Clamps value into [range.x, range.y].
20template <typename T>
21constexpr const T& Clamp(const T& value, Vector2D range) {
22 return (value < range.GetX()) ? range.GetX() : (value > range.GetY()) ? range.GetY() : value;
23}
24
25template <typename T>
26constexpr const T& Min(const T& value1, const T& value2) {
27 return (value1 < value2) ? value1 : value2;
28}
29
30template <typename T>
31constexpr const T& Max(const T& value1, const T& value2) {
32 return (value1 > value2) ? value1 : value2;
33}
34
35/// Linear interpolation from start to end; t is clamped to [0,1].
36template <typename T>
37constexpr T Lerp(const T& start, const T& end, float t) {
38 return start + (end - start) * Clamp(t, 0.0f, 1.0f);
39}
40
41} // namespace Math
42} // namespace Sleak
43
44#endif // _MATH_H_
float GetX() const
Definition Vector.hpp:216
float GetY() const
Definition Vector.hpp:217
constexpr const T & Min(const T &value1, const T &value2)
Definition Math.hpp:26
constexpr const T & Max(const T &value1, const T &value2)
Definition Math.hpp:31
constexpr T Lerp(const T &start, const T &end, float t)
Linear interpolation from start to end; t is clamped to [0,1].
Definition Math.hpp:37
constexpr const T & Clamp(const T &value, T min, T max)
Clamps value into [min, max].
Definition Math.hpp:15
Root namespace for everything the engine exposes.
Definition Camera.hpp:10