Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
MathUtil.h
Go to the documentation of this file.
1
2/*
3 ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
4 ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
5 █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
6 ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
7 ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
8 ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
9 /vvvvvvvvvvvvvvvvvvv \=========================================,
10 `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
11 Katana Engine \/ © 2012 - Shuriken Studios LLC
12 http://www.shurikenstudios.com
13*/
14
15#pragma once
16
17namespace KatanaEngine
18{
20 class Math
21 {
22
23 public:
24
25 static const float PI;
26 static const float PI_OVER2;
27 static const float PI_OVER4;
28 static const float INVERSE_PI;
29 static const float NORMALIZE_PI_OVER4;
30 static const float INVERSE_180;
38 static float Lerp(float start, float end, float value);
39
44 static int GetRandomInt(const int min = 0, const int max = RAND_MAX);
45
48 static float GetRandomFloat() { return ((float)rand() / RAND_MAX); }
49
54 static float Min(const float value1, const float value2);
55
60 static float Max(const float value1, const float value2);
61
65 static float Abs(const float value);
66
70 static float ToRadians(const float degrees) { return degrees * PI * INVERSE_180; }
71
75 static float ToDegrees(const float radians) { return radians * 180 * INVERSE_PI; }
76
82 template <typename T>
83 static T Clamp(const T min, const T max, const T value)
84 {
85 return (value < min) ? min : (value > max) ? max : value;
86 }
87
93 static float Clamp(const float min, const float max, const float value)
94 {
95 return Clamp<float>(min, max, value);
96 }
97
103 template <typename T>
104 static bool IsInRange(const T min, const T max, const T value)
105 {
106 return (value >= min) && (value <= max);
107 }
108
114 static bool IsInRange(const float min, const float max, const float value)
115 {
116 return IsInRange<float>(min, max, value);
117 }
118 };
119}
Provides commonly used floating point functions and constants.
Definition MathUtil.h:21
static float Max(const float value1, const float value2)
Get the greator of two numbers.
Definition MathUtil.cpp:45
static const float PI_OVER4
Represents the value of pi divided by four.
Definition MathUtil.h:27
static float ToDegrees(const float radians)
Converts radians to degrees.
Definition MathUtil.h:75
static float ToRadians(const float degrees)
Converts degrees to radians.
Definition MathUtil.h:70
static bool IsInRange(const float min, const float max, const float value)
Determines if a value is within a specified range.
Definition MathUtil.h:114
static int GetRandomInt(const int min=0, const int max=RAND_MAX)
Get a random integer.
Definition MathUtil.cpp:34
static float GetRandomFloat()
Get a random number between zero and one.
Definition MathUtil.h:48
static const float INVERSE_180
Represents the value of one divided by 180.
Definition MathUtil.h:30
static const float PI
Represents the value of pi.
Definition MathUtil.h:25
static float Min(const float value1, const float value2)
Get the lessor of two numbers.
Definition MathUtil.cpp:39
static const float INVERSE_PI
Represents the value of one divided by pi.
Definition MathUtil.h:28
static float Lerp(float start, float end, float value)
Linearly interpolate between two values.
Definition MathUtil.cpp:26
static T Clamp(const T min, const T max, const T value)
Restricts a value to be within a specified range.
Definition MathUtil.h:83
static const float PI_OVER2
Represents the value of pi divided by two.
Definition MathUtil.h:26
static const float NORMALIZE_PI_OVER4
Represents the value of each component in a pi/4 unit vector.
Definition MathUtil.h:29
static bool IsInRange(const T min, const T max, const T value)
Determines if a value is within a specified range.
Definition MathUtil.h:104
static float Clamp(const float min, const float max, const float value)
Restricts a value to be within a specified range.
Definition MathUtil.h:93
static float Abs(const float value)
Get the absolute value of a number.
Definition MathUtil.cpp:51
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition Animation.cpp:18