Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
KatanaEngine::Math Class Reference

Provides commonly used floating point functions and constants. More...

#include <MathUtil.h>

Static Public Member Functions

static float Lerp (float start, float end, float value)
 Linearly interpolate between two values.
 
static int GetRandomInt (const int min=0, const int max=RAND_MAX)
 Get a random integer.
 
static float GetRandomFloat ()
 Get a random number between zero and one.
 
static float Min (const float value1, const float value2)
 Get the lessor of two numbers.
 
static float Max (const float value1, const float value2)
 Get the greator of two numbers.
 
static float Abs (const float value)
 Get the absolute value of a number.
 
static float ToRadians (const float degrees)
 Converts degrees to radians.
 
static float ToDegrees (const float radians)
 Converts radians to degrees.
 
template<typename T >
static T Clamp (const T min, const T max, const T value)
 Restricts a value to be within a specified range.
 
static float Clamp (const float min, const float max, const float value)
 Restricts a value to be within a specified range.
 
template<typename T >
static bool IsInRange (const T min, const T max, const T value)
 Determines if a value is within a specified range.
 
static bool IsInRange (const float min, const float max, const float value)
 Determines if a value is within a specified range.
 

Static Public Attributes

static const float PI = 3.14159265359f
 Represents the value of pi.
 
static const float PI_OVER2 = Math::PI / 2
 Represents the value of pi divided by two.
 
static const float PI_OVER4 = Math::PI / 4
 Represents the value of pi divided by four.
 
static const float INVERSE_PI = 1.0f / Math::PI
 Represents the value of one divided by pi.
 
static const float NORMALIZE_PI_OVER4 = 0.70710678119f
 Represents the value of each component in a pi/4 unit vector.
 
static const float INVERSE_180 = 1.0f / 180
 Represents the value of one divided by 180.
 

Detailed Description

Provides commonly used floating point functions and constants.

Definition at line 20 of file MathUtil.h.

Member Function Documentation

◆ Abs()

float KatanaEngine::Math::Abs ( const float value)
static

Get the absolute value of a number.

Parameters
valueThe positive or negative value.
Returns
Returns the absolute value.

Definition at line 51 of file MathUtil.cpp.

◆ Clamp() [1/2]

static float KatanaEngine::Math::Clamp ( const float min,
const float max,
const float value )
inlinestatic

Restricts a value to be within a specified range.

Parameters
minThe minimum value. If value is less than min, min will be returned.
maxThe maximum value. If value is greater than max, max will be returned.
valueThe value to clamp.
Returns
Returns the clamped value between min and max.

Definition at line 93 of file MathUtil.h.

◆ Clamp() [2/2]

template<typename T >
static T KatanaEngine::Math::Clamp ( const T min,
const T max,
const T value )
inlinestatic

Restricts a value to be within a specified range.

Parameters
minThe minimum value. If value is less than min, min will be returned.
maxThe maximum value. If value is greater than max, max will be returned.
valueThe value to clamp.
Returns
Returns the clamped value between min and max.

Definition at line 83 of file MathUtil.h.

◆ GetRandomFloat()

static float KatanaEngine::Math::GetRandomFloat ( )
inlinestatic

Get a random number between zero and one.

Returns
Returns a random floating point number between zero and one.

Definition at line 48 of file MathUtil.h.

◆ GetRandomInt()

int KatanaEngine::Math::GetRandomInt ( const int min = 0,
const int max = RAND_MAX )
static

Get a random integer.

Parameters
minThe inclusive minimum number.
maxThe inclusive maximum number.
Returns
Returns a random integer between min and max.

Definition at line 34 of file MathUtil.cpp.

◆ IsInRange() [1/2]

static bool KatanaEngine::Math::IsInRange ( const float min,
const float max,
const float value )
inlinestatic

Determines if a value is within a specified range.

Parameters
minThe minimum value.
maxThe maximum value.
valueThe value to check.
Returns
Returns true if the value is within the range.

Definition at line 114 of file MathUtil.h.

◆ IsInRange() [2/2]

template<typename T >
static bool KatanaEngine::Math::IsInRange ( const T min,
const T max,
const T value )
inlinestatic

Determines if a value is within a specified range.

Parameters
minThe minimum value.
maxThe maximum value.
valueThe value to check.
Returns
Returns true if the value is within the range.

Definition at line 104 of file MathUtil.h.

◆ Lerp()

float KatanaEngine::Math::Lerp ( float start,
float end,
float value )
static

Linearly interpolate between two values.

Parameters
startThe result when the value is zero.
endThe result when the value is one.
valueA value between 0 and 1 that will indicate the resulting weight between start and end.
Returns
Returns the interpolated value between start and end.

Definition at line 26 of file MathUtil.cpp.

◆ Max()

float KatanaEngine::Math::Max ( const float value1,
const float value2 )
static

Get the greator of two numbers.

Parameters
value1The first value.
value2The second value.
Returns
Returns the greator number between two values.

Definition at line 45 of file MathUtil.cpp.

◆ Min()

float KatanaEngine::Math::Min ( const float value1,
const float value2 )
static

Get the lessor of two numbers.

Parameters
value1The first value.
value2The second value.
Returns
Returns the lessor number between two values.

Definition at line 39 of file MathUtil.cpp.

◆ ToDegrees()

static float KatanaEngine::Math::ToDegrees ( const float radians)
inlinestatic

Converts radians to degrees.

Parameters
radiansThe angle in radians.
Returns
Returns the angle in degrees.

Definition at line 75 of file MathUtil.h.

◆ ToRadians()

static float KatanaEngine::Math::ToRadians ( const float degrees)
inlinestatic

Converts degrees to radians.

Parameters
degreesThe angle in degrees.
Returns
Returns the angle in radians.

Definition at line 70 of file MathUtil.h.

Member Data Documentation

◆ INVERSE_180

const float KatanaEngine::Math::INVERSE_180 = 1.0f / 180
static

Represents the value of one divided by 180.

Definition at line 30 of file MathUtil.h.

◆ INVERSE_PI

const float KatanaEngine::Math::INVERSE_PI = 1.0f / Math::PI
static

Represents the value of one divided by pi.

Definition at line 28 of file MathUtil.h.

◆ NORMALIZE_PI_OVER4

const float KatanaEngine::Math::NORMALIZE_PI_OVER4 = 0.70710678119f
static

Represents the value of each component in a pi/4 unit vector.

Definition at line 29 of file MathUtil.h.

◆ PI

const float KatanaEngine::Math::PI = 3.14159265359f
static

Represents the value of pi.

Definition at line 25 of file MathUtil.h.

◆ PI_OVER2

const float KatanaEngine::Math::PI_OVER2 = Math::PI / 2
static

Represents the value of pi divided by two.

Definition at line 26 of file MathUtil.h.

◆ PI_OVER4

const float KatanaEngine::Math::PI_OVER4 = Math::PI / 4
static

Represents the value of pi divided by four.

Definition at line 27 of file MathUtil.h.


The documentation for this class was generated from the following files: