Pico Headers
Loading...
Searching...
No Matches
Classes | Macros | Functions
pico_hit.h File Reference
#include "pico_math.h"
Include dependency graph for pico_hit.h:

Go to the source code of this file.

Classes

struct  ph_circle_t
 A circle shape. More...
 
struct  ph_poly_t
 A polygon shape Must use CCW (counter-clockwise) winding. More...
 
struct  ph_ray_t
 A ray (directed line segment) More...
 
struct  ph_manifold_t
 A collision manifold Provides information about a collision. Normals always point from shape 1 to shape 2. More...
 
struct  ph_raycast_t
 Raycast information. More...
 

Macros

#define PICO_HIT_MAX_POLY_VERTS   16
 

Functions

ph_circle_t ph_make_circle (pv2 pos, pfloat radius)
 Initializes a circle.
 
ph_poly_t ph_make_poly (const pv2 vertices[], int vertex_count)
 Initializes a polygon.
 
ph_ray_t ph_make_ray (pv2 pos, pv2 dir, pfloat dist)
 Constructs a ray.
 
ph_poly_t ph_aabb_to_poly (const pb2 *aabb)
 Converts and axis-aligned bounding box (AABB) to a polygon.
 
bool ph_sat_poly_poly (const ph_poly_t *poly_a, const ph_poly_t *poly_b, ph_manifold_t *manifold)
 Tests to see if one polygon overlaps with another.
 
bool ph_sat_poly_circle (const ph_poly_t *poly, const ph_circle_t *circle, ph_manifold_t *manifold)
 Tests to see if a polygon overlaps a circle.
 
bool ph_sat_circle_poly (const ph_circle_t *circle, const ph_poly_t *poly, ph_manifold_t *manifold)
 Tests to see if a circle overlaps a polygon.
 
bool ph_sat_circle_circle (const ph_circle_t *circle_a, const ph_circle_t *circle_b, ph_manifold_t *manifold)
 Tests to see if two circles overlap.
 
bool ph_ray_line (const ph_ray_t *ray, pv2 s1, pv2 s2, ph_raycast_t *raycast)
 Tests if ray intersects a (directed) line segment.
 
bool ph_ray_poly (const ph_ray_t *ray, const ph_poly_t *poly, ph_raycast_t *raycast)
 Tests if ray intersects a polygon.
 
bool ph_ray_circle (const ph_ray_t *ray, const ph_circle_t *circle, ph_raycast_t *raycast)
 Tests if ray intersects a circle.
 
pv2 ph_ray_at (const ph_ray_t *ray, pfloat dist)
 Finds the point along the ray at the specified distance from the origin.
 
ph_poly_t ph_transform_poly (const pt2 *transform, const ph_poly_t *poly)
 Transforms a polygon using an affine transform.
 
ph_circle_t ph_transform_circle (const pt2 *transform, const ph_circle_t *circle)
 Transforms a circle using an affine transform.
 
pb2 ph_poly_to_aabb (const ph_poly_t *poly)
 Returns the bounding box for the given polygon.
 
pb2 ph_circle_to_aabb (const ph_circle_t *circle)
 Returns the bounding box for the given circle.
 

Macro Definition Documentation

◆ PICO_HIT_MAX_POLY_VERTS

#define PICO_HIT_MAX_POLY_VERTS   16

Function Documentation

◆ ph_make_circle()

ph_circle_t ph_make_circle ( pv2  pos,
pfloat  radius 
)

Initializes a circle.

Parameters
posCircle center
radiusCircle radius

◆ ph_make_poly()

ph_poly_t ph_make_poly ( const pv2  vertices[],
int  vertex_count 
)

Initializes a polygon.

Parameters
vertex_countThe number of vertices of the polygon
verticesThe vertices of the polygon (must use CCW winding)
Returns
The polygon with the given vertices

◆ ph_make_ray()

ph_ray_t ph_make_ray ( pv2  pos,
pv2  dir,
pfloat  dist 
)

Constructs a ray.

Parameters
posThe origin of the array
dirThe direction of the ray
distThe length of the ray

◆ ph_aabb_to_poly()

ph_poly_t ph_aabb_to_poly ( const pb2 aabb)

Converts and axis-aligned bounding box (AABB) to a polygon.

aabb The AABB

Returns
the AABB as a polygon

◆ ph_sat_poly_poly()

bool ph_sat_poly_poly ( const ph_poly_t poly_a,
const ph_poly_t poly_b,
ph_manifold_t manifold 
)

Tests to see if one polygon overlaps with another.

Parameters
poly_aThe colliding polygon
poly_bThe target polygon
manifoldThe collision manifold to populate (or NULL)
Returns
True if the polygons overlap and false otherwise

◆ ph_sat_poly_circle()

bool ph_sat_poly_circle ( const ph_poly_t poly,
const ph_circle_t circle,
ph_manifold_t manifold 
)

Tests to see if a polygon overlaps a circle.

Parameters
polyThe colliding polygon
circleThe target circle
manifoldThe collision manifold to populate (or NULL)
Returns
True if the polygon and circle overlap, and false otherwise

◆ ph_sat_circle_poly()

bool ph_sat_circle_poly ( const ph_circle_t circle,
const ph_poly_t poly,
ph_manifold_t manifold 
)

Tests to see if a circle overlaps a polygon.

Parameters
circleThe colliding circle
polyThe target polygon
manifoldThe collision manifold to populate (or NULL)
Returns
True if the circle overlaps the polygon, and false otherwise

◆ ph_sat_circle_circle()

bool ph_sat_circle_circle ( const ph_circle_t circle_a,
const ph_circle_t circle_b,
ph_manifold_t manifold 
)

Tests to see if two circles overlap.

Parameters
circle_aThe colliding circle
circle_bThe target circle
manifoldThe collision manifold to populate (or NULL)
Returns
True if the circle and the other circle, and false otherwise

◆ ph_ray_line()

bool ph_ray_line ( const ph_ray_t ray,
pv2  s1,
pv2  s2,
ph_raycast_t raycast 
)

Tests if ray intersects a (directed) line segment.

Parameters
rayRay to test
s1First endpoint of segment
s2Second endpoint of segment
raycastNormal and distance of impact (or NULL)
Returns
True if the ray collides with the line segment and false otherwise

◆ ph_ray_poly()

bool ph_ray_poly ( const ph_ray_t ray,
const ph_poly_t poly,
ph_raycast_t raycast 
)

Tests if ray intersects a polygon.

Parameters
rayRay to test
polyThe polygon
raycastNormal and distance of impact (or NULL). May terminate early if NULL
Returns
True if the ray collides with the polygon and false otherwise

◆ ph_ray_circle()

bool ph_ray_circle ( const ph_ray_t ray,
const ph_circle_t circle,
ph_raycast_t raycast 
)

Tests if ray intersects a circle.

Parameters
rayRay to test
circleThe circle
raycastNormal and distance of impact (if not NULL).
Returns
True if the ray collides with the circle and false otherwise

◆ ph_ray_at()

pv2 ph_ray_at ( const ph_ray_t ray,
pfloat  dist 
)

Finds the point along the ray at the specified distance from the origin.

◆ ph_transform_poly()

ph_poly_t ph_transform_poly ( const pt2 transform,
const ph_poly_t poly 
)

Transforms a polygon using an affine transform.

Parameters
transformThe transform
polyThe polygon to transform
Returns
A new polygon

◆ ph_transform_circle()

ph_circle_t ph_transform_circle ( const pt2 transform,
const ph_circle_t circle 
)

Transforms a circle using an affine transform.

Parameters
transformThe transform
polyThe circle to transform
Returns
A new circle

◆ ph_poly_to_aabb()

pb2 ph_poly_to_aabb ( const ph_poly_t poly)

Returns the bounding box for the given polygon.

◆ ph_circle_to_aabb()

pb2 ph_circle_to_aabb ( const ph_circle_t circle)

Returns the bounding box for the given circle.