Documentation for C++/SDL 2.0 Tile Engine
Making a simple tile based engine
 All Classes Namespaces Functions Variables Enumerations
Enumerations | Functions
Math Namespace Reference

A math utility function namespace. More...

Enumerations

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

Functions

float Distance (const Vector2f &a, const Vector2f &b)
float Clamp (const float x, const float min, const float max)
float Magnitude (const Vector2f &v)
Vector2f Normalize (const Vector2f &v)
Vector2f Lerp (const Vector2f &start, const Vector2f &end, float percent)
int RectNearRect (const Rectf &a, const Rectf &b, int tolerance=0)
bool CheckCollision (const Rectf &a, const Rectf &b)
bool CheckCollision (const Vector2f &p, const Rectf &r)
Vector2f ToSceneSpace (const Camera *cam, const Vector2f &v)
Rectf ToSceneSpace (const Camera *cam, const Rectf &r)
Vector2f FromSceneSpace (const Camera *cam, const Vector2f &v)
Rectf FromSceneSpace (const Camera *cam, const Rectf &r)

Detailed Description

A math utility function namespace.

A math utility function namespace

Function Documentation

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

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 
)

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 
)

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 
)

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

Parameters
aFirst point
bSecond point
Returns
The distance
Vector2f Math::FromSceneSpace ( const Camera cam,
const Vector2f v 
)

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 Camera cam,
const Rectf r 
)

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 
)

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)

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)

Normalize a Vector2

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

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 Camera cam,
const Vector2f v 
)

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 Camera cam,
const Rectf r 
)

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