SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
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
10
namespace
Sleak
{
11
namespace
Math {
12
13
/// Clamps value into [min, max].
14
/// Returns by value: min and max are parameters, so returning a reference
15
/// would hand back a dangling one whenever clamping engages.
16
template
<
typename
T>
17
constexpr
T
Clamp
(
const
T& value, T min, T max) {
18
return
(value < min) ? min : (value > max) ? max : value;
19
}
20
21
/// Clamps value into [range.x, range.y].
22
template
<
typename
T>
23
constexpr
T
Clamp
(
const
T& value,
Vector2D
range) {
24
return
(value < range.
GetX
()) ?
static_cast<
T
>
(range.
GetX
())
25
: (value > range.
GetY
()) ?
static_cast<
T
>
(range.
GetY
())
26
: value;
27
}
28
29
template
<
typename
T>
30
constexpr
const
T&
Min
(
const
T& value1,
const
T& value2) {
31
return
(value1 < value2) ? value1 : value2;
32
}
33
34
template
<
typename
T>
35
constexpr
const
T&
Max
(
const
T& value1,
const
T& value2) {
36
return
(value1 > value2) ? value1 : value2;
37
}
38
39
/// Linear interpolation from start to end; t is clamped to [0,1].
40
template
<
typename
T>
41
constexpr
T
Lerp
(
const
T& start,
const
T& end,
float
t) {
42
return
start + (end - start) *
Clamp
(t, 0.0f, 1.0f);
43
}
44
45
}
// namespace Math
46
}
// namespace Sleak
47
48
#endif
// _MATH_H_
Vector.hpp
Sleak::Math::Vector2D
Definition
Vector.hpp:210
Sleak::Math::Vector2D::GetY
constexpr float GetY() const
Definition
Vector.hpp:218
Sleak::Math::Vector2D::GetX
constexpr float GetX() const
Definition
Vector.hpp:217
Sleak::Math::Min
constexpr const T & Min(const T &value1, const T &value2)
Definition
Math.hpp:30
Sleak::Math::Max
constexpr const T & Max(const T &value1, const T &value2)
Definition
Math.hpp:35
Sleak::Math::Lerp
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:41
Sleak::Math::Clamp
constexpr T Clamp(const T &value, T min, T max)
Definition
Math.hpp:17
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
include
public
Math
Math.hpp
Generated on
for SleakEngine by
1.18.0