Colliding Shapes
Ian Parberry's "Introduction to Game Physics"
Macros | Functions
ShapeMath.h File Reference

Handy math functions for the collision module. More...

#include <d3d11_2.h>
#include <dxgi1_3.h>
#include <DirectXMath.h>
#include "SimpleMath.h"

Macros

#define FailIf(x)   if(x)return false;
 
#define sqr(x)   ((x)*(x))
 Handy squaring function. Compute the square of any number. More...
 

Functions

float NormalizeAngle (float)
 Normalize angle to [0, 2*pi). More...
 
Vector2 Normalize (Vector2)
 Normalize a vector, ie. make it unit length. More...
 
Vector2 perp (const Vector2 &)
 Perpendicular vector. More...
 
Vector2 AngleToVector (const float)
 Normal vector from orientation. More...
 
Vector2 RotatePt (Vector2, const Vector2 &, const float)
 Rotate point. More...
 
Vector2 ParallelComponent (const Vector2 &, const Vector2 &)
 Compute parallel component of vector. More...
 

Macro Definition Documentation

◆ FailIf

#define FailIf (   x)    if(x)return false;

Fail by returning false if a given condition is true.

Parameters
xCondition for failure.

◆ sqr

#define sqr (   x)    ((x)*(x))
Parameters
xA number.
Returns
x squared.

Function Documentation

◆ AngleToVector()

Vector2 AngleToVector ( const float  a)

Get a normalized vector at a given orientation.

Parameters
aOrientation angle.
Returns
Unit vector at orientation a.

◆ Normalize()

Vector2 Normalize ( Vector2  v)

The DirectXTK doesn't have a function that returns a normalized vector, so here it is.

Parameters
vA vector.
Returns
A unit vector that points in the direction of v.

◆ NormalizeAngle()

float NormalizeAngle ( float  a)

/brief Normalize angle to [0, 2PI).

Parameters
aAngle in radians.
Returns
Normalized angle, that is, in the range [0, 2PI).

◆ ParallelComponent()

Vector2 ParallelComponent ( const Vector2 &  v0,
const Vector2 &  v1 
)

Find the component of one vector parallel to another.

Parameters
v0Vector whose component we want.
v1Vector that the component must be parallel to.
Returns
Component of v0 that is parallel to v1.

◆ perp()

Vector2 perp ( const Vector2 &  v)

Compute the perpendicular to a given vector in a counterclockwise direction.

Parameters
vA vector.
Returns
The vector perpendicular to v in a counterclockwise direction.

◆ RotatePt()

Vector2 RotatePt ( Vector2  p,
const Vector2 &  q,
const float  a 
)

Rotate a point about an arbitrary center.

Parameters
pPoint to be rotated.
qCenter of rotation.
aAngle of rotation in radians.
Returns
Rotated point.