Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
These utility functions are can be used for geometric math.
Much of this file was adapted from https://www.jeffreythompson.org/collision-detection/
No initialization or deinitialization is required. Each function will not modify the given shapes. See the functions below for what is provided and how to use them.
Go to the source code of this file.
Data Structures | |
struct | circle_t |
Signed integer representation of a circle. More... | |
struct | rectangle_t |
Signed integer representation of a rectangle. More... | |
struct | line_t |
Signed integer representation of a line segment. More... | |
struct | arrow_t |
Functions | |
bool | circleCircleIntersection (circle_t circle1, circle_t circle2, vec_t *collisionVec) |
Check if two circles intersect. | |
bool | circlePointIntersection (circle_t circle, vec_t point, vec_t *collisionVec) |
Check if a point and a circle intersect. | |
bool | circleRectIntersection (circle_t circle, rectangle_t rect, vec_t *collisionVec) |
Check if a circle and a rectangle intersect. | |
bool | circleLineIntersection (circle_t circle, line_t line, vec_t *collisionVec) |
Check if a circle and a line intersect. | |
bool | rectRectIntersection (rectangle_t rect1, rectangle_t rect2, vec_t *collisionVec) |
Check if two rectangles intersect. | |
bool | rectLineIntersection (rectangle_t rect, line_t line, vec_t *collisionVec) |
Check if a line intersects with a rectangle. | |
bool | lineLineIntersection (line_t line1, line_t line2) |
Check if two lines intersect. | |
arrow_t | initArrow (vec_t base, vec_t tip, int32_t wingLen) |
Initialize an arrow pointing from base to tip. | |
struct circle_t |
Data Fields | ||
---|---|---|
vec_t | pos | The position of the center of the circle. |
int32_t | radius | The radius of the circle. |
struct rectangle_t |
Data Fields | ||
---|---|---|
vec_t | pos | The position the top left corner of the rectangle. |
int32_t | width | The width of the rectangle. |
int32_t | height | The height of the rectangle. |
struct line_t |
struct arrow_t |
Check if two circles intersect.
circle1 | [IN] One circle to check for intersection |
circle2 | [IN] The other circle to check for intersection |
collisionVec | [OUT] A vector pointing from the second circle to the first in the direction of the collision. May be NULL. |
Check if a point and a circle intersect.
circle | [IN] A circle to check for intersection |
point | [IN] A point to check for intersection |
collisionVec | [OUT] A vector pointing from the point to the circle in the direction of the collision. May be NULL. |
bool circleRectIntersection | ( | circle_t | circle, |
rectangle_t | rect, | ||
vec_t * | collisionVec ) |
Check if a circle and a rectangle intersect.
Adapted from https://www.jeffreythompson.org/collision-detection/circle-rect.php
circle | [IN] The circle to check for intersection |
rect | [IN] The rectangle to check for intersection |
collisionVec | [OUT] A vector pointing from the rectangle to the circle in the direction of the collision. May be NULL. |
Check if a circle and a line intersect.
Adapted from https://www.jeffreythompson.org/collision-detection/line-circle.php
circle | [IN] A circle to test intersection |
line | [IN] A line to test intersection |
collisionVec | [OUT] A vector pointing from the line to the circle in the direction of the collision. This may be NULL. |
bool rectRectIntersection | ( | rectangle_t | rect1, |
rectangle_t | rect2, | ||
vec_t * | collisionVec ) |
Check if two rectangles intersect.
Adapted from https://www.jeffreythompson.org/collision-detection/rect-rect.php
rect1 | [IN] One rectangle to check for intersection |
rect2 | [IN] The other rectangle to check for intersection |
collisionVec | [OUT] A vector pointing from the second rectangle to the first in the direction of the collision. May be NULL. |
bool rectLineIntersection | ( | rectangle_t | rect, |
line_t | line, | ||
vec_t * | collisionVec ) |
Check if a line intersects with a rectangle.
Adapted from https://www.jeffreythompson.org/collision-detection/line-rect.php
rect | [IN] A rectangle to check for intersection |
line | [IN] A line to check for intersection |
collisionVec | [OUT] A vector pointing from the rectangle to the line in the direction of the collision. May be NULL. |
Check if two lines intersect.
Adapted from https://www.jeffreythompson.org/collision-detection/line-line.php
line1 | [IN] One line to check for intersection |
line2 | [IN] Another line to check for intersection |