LPCGame
A Simple 2d Game Engine
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Math Class Reference

A math utility function class. More...

#include <math.h>

Public Types

enum  { UP, DOWN, LEFT, RIGHT }
 Describes a direction.
 

Static Public Member Functions

static float Distance (const Vector2f &a, const Vector2f &b)
 
static float Clamp (const float x, const float min, const float max)
 
static float Magnitude (const Vector2f &v)
 
static Vector2f Normalize (const Vector2f &v)
 
static Vector2f Lerp (const Vector2f &start, const Vector2f &end, float percent)
 
static Vector2f ForwardVector (float degrees)
 
static int RectNearRect (const Rectf &a, const Rectf &b, int tolerance=0)
 
static bool CheckCollision (const Rectf &a, const Rectf &b)
 
static bool CheckCollision (const Vector2f &p, const Rectf &r)
 
static Vector2f ToSceneSpace (const std::weak_ptr< Camera > cam, const Vector2f &v)
 
static Rectf ToSceneSpace (const std::weak_ptr< Camera > cam, const Rectf &r)
 
static Vector2f FromSceneSpace (const std::weak_ptr< Camera > cam, const Vector2f &v)
 
static Rectf FromSceneSpace (const std::weak_ptr< Camera > cam, const Rectf &r)
 

Detailed Description

A math utility function class.

A math utility function class

Member Function Documentation

bool Math::CheckCollision ( const Rectf a,
const Rectf b 
)
static

Check collision between two rectangles

Parameters
aFirst Rect
bSecond Rect
Returns
T if collision, F otherwise
bool Math::CheckCollision ( const Vector2f p,
const Rectf r 
)
static

Check collision between a Vector and a rectangle ie. if the point is inside/on edge of the rectangle

Parameters
pThe Vector2 (point)
rThe Rect
Returns
T if point is in the rectangle
float Math::Clamp ( const float  x,
const float  min,
const float  max 
)
static

Clamp the value x between the range min and max

Parameters
xThe value to clamp
minThe minimum value x can be
maxThe max value x can be
Returns
x if it is in range, or max if x is above, min if x is below
float Math::Distance ( const Vector2f a,
const Vector2f b 
)
static

Takes two vectors (points) and returns the distance between them

Parameters
aFirst point
bSecond point
Returns
The distance
Vector2f Math::ForwardVector ( float  degrees)
static

Calculate the forward vector of some object with a given rotation

Parameters
degreesThe object's rotation in degrees
Returns
Vector2f of the object's forward direction
Vector2f Math::FromSceneSpace ( const std::weak_ptr< Camera cam,
const Vector2f v 
)
static

Transform a vector from scene space into window space

Parameters
camThe camera/scene space to convert the vector to
vThe Vector2 to convert to window space
Returns
The Vector2 transformed to window space
Rectf Math::FromSceneSpace ( const std::weak_ptr< Camera cam,
const Rectf r 
)
static

Transform a rect from scene space to window space

Parameters
camThe camera/scene space to convert the vector to
rThe Rect to convert to window space
Returns
The Rect with its pos value converted to window space
Vector2f Math::Lerp ( const Vector2f start,
const Vector2f end,
float  percent 
)
static

A standard Lerp function for Vector2 Get the Vector2 that is some percent between start and end

Parameters
startThe starting point
endThe ending point
percentThe percent distance to return between the points, 0 -> start, 1 -> end
float Math::Magnitude ( const Vector2f v)
static

Calculate the magnitude of a Vector2

Parameters
vThe Vector2 to calculate the magnitude of
Returns
The magnitude of the vector
Vector2f Math::Normalize ( const Vector2f v)
static

Normalize a Vector2

Parameters
vThe Vector2 to normalize
Returns
The normalized Vector2
int Math::RectNearRect ( const Rectf a,
const Rectf b,
int  tolerance = 0 
)
static

Check if two rectangles are near each other and return the side of a that's near b TODO: Implement an early out for this function if the rect's are too far

Parameters
aThe first Rect
bThe Rect to see if a is near
toleranceThe max distance the Rect's can be from each other, default is 0
Returns
The enumerator representing the side of Rect A that's within tolerance of B, if none return -1
Vector2f Math::ToSceneSpace ( const std::weak_ptr< Camera cam,
const Vector2f v 
)
static

Transform a vector from window space into scene space

Parameters
camThe camera/scene space to convert the vector to
vThe Vector2 to convert to scene space
Returns
The Vector2 transformed to scene space
Rectf Math::ToSceneSpace ( const std::weak_ptr< Camera cam,
const Rectf r 
)
static

Transform a rect into scene space from window space

Parameters
camThe camera/scene space to convert the vector to
rThe Rect to convert to scene space
Returns
The Rect with its pos value transformed to scene space

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