Handy math functions for the collision module.
#include <d3d11_2.h>
#include <dxgi1_3.h>
#include <DirectXMath.h>
#include "SimpleMath.h"
◆ FailIf
Value:Fail by returning false if a given condition is true.
- Parameters
-
◆ AngleToVector()
| Vector2 Shapes::AngleToVector |
( |
const float | theta | ) |
|
Compute a unit vector at an angle measured in radians counterclockwise from the positive X-axis. If \(\vec{v} = [v_x, v_y]\) is a unit vector with tail at the Origin and \(\theta\) is the angle between \(\vec{v}\) and the positive X-axis, then \(\sin \theta = v_y\) and \(\cos \theta = v_x\). Hence, \(\vec{v} = [\cos \theta, \sin \theta]\), as shown below. Therefore, this function returns Vector2(cosf(theta), sinf(theta)).
- Parameters
-
- Returns
- Unit vector at angle theta counterclockwise from positive X.
◆ Normalize()
| Vector2 Shapes::Normalize |
( |
Vector2 | v | ) |
|
The DirectXTK doesn't have a function that returns a normalized vector, so here it is. We will now be able to use it in constant declarations, for example, const Vector2 u = v.Normalize().
- Parameters
-
- Returns
- A unit vector that points in the direction of v.
◆ NormalizeAngle()
| float Shapes::NormalizeAngle |
( |
float | a | ) |
|
Normalize angle to \([0, 2\pi)\).
- Parameters
-
- Returns
- Normalized angle, that is, in the range \([0, 2\pi)\).
◆ ParallelComponent()
| Vector2 Shapes::ParallelComponent |
( |
const Vector2 & | v0, |
|
|
const Vector2 & | v1 ) |
Find the component of one vector parallel to another. The component of \(\vec{v}_0\) parallel to \(\vec{v}_1\) is \((\vec{v}_0 \cdot \hat{v}_1)\hat{v}_1\).
- Parameters
-
| v0 | Vector whose component we want. |
| v1 | Vector that the component must be parallel to. |
- Returns
- Component of v0 that is parallel to v1.
◆ perp()
| Vector2 Shapes::perp |
( |
const Vector2 & | v | ) |
|
Compute the counterclockwise perpendicular of a vector, preserving length. If \(\vec{v} = [v_x, v_y]\), then both dot products \(\vec{v} \cdot [-v_y, v_x]\) and \(\vec{v} \cdot [v_y, -v_x]\) are equal to zero, and therefore both \([-v_y, v_x]\) and \([v_y, -v_x]\) are perpendicular to \(\vec{v}\). The former (drawn in green below) points counterclockwise from \(\vec{v}\) and the latter (drawn in purple below) points clockwise from \(\vec{v}\).
- Parameters
-
| v | A vector, not necessarily normalized. |
- Returns
- The counterclockwise perpendicular to v of the same length.
◆ RotatePt()
| Vector2 Shapes::RotatePt |
( |
Vector2 | u, |
|
|
const Vector2 & | v, |
|
|
const float | a ) |
Rotate a point about an arbitrary center.
- Parameters
-
| u | Point to be rotated. |
| v | Center of rotation. |
| a | Angle of rotation in radians counterclockwise. |
- Returns
- Rotated point.