125 lines
4.4 KiB
C
125 lines
4.4 KiB
C
/**
|
|
* Copyright (c) 2025 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "world/tile.h"
|
|
|
|
typedef struct {
|
|
bool_t hit;
|
|
float_t normalX, normalY;
|
|
float_t depth;
|
|
} collisionresult_t;
|
|
|
|
/**
|
|
* Check for collision between two circles.
|
|
*
|
|
* @param circle0x X coordinate of the first circle's center.
|
|
* @param circle0y Y coordinate of the first circle's center.
|
|
* @param circle0r Radius of the first circle.
|
|
* @param circle1x X coordinate of the second circle's center.
|
|
* @param circle1y Y coordinate of the second circle's center.
|
|
* @param circle1r Radius of the second circle.
|
|
* @return A collisionresult_t structure containing collision information.
|
|
*/
|
|
collisionresult_t physicsCheckCircleCircle(
|
|
float_t circle0x, float_t circle0y, float_t circle0r,
|
|
float_t circle1x, float_t circle1y, float_t circle1r
|
|
);
|
|
|
|
/**
|
|
* Check for collision between a circle and an axis-aligned bounding box (AABB).
|
|
*
|
|
* @param circleX X coordinate of the circle's center.
|
|
* @param circleY Y coordinate of the circle's center.
|
|
* @param circleR Radius of the circle.
|
|
* @param aabb X coordinate of the AABB's top-left corner.
|
|
* @param aabbY Y coordinate of the AABB's top-left corner.
|
|
* @param aabbWidth Width of the AABB.
|
|
* @param aabbHeight Height of the AABB.
|
|
* @return A collisionresult_t structure containing collision information.
|
|
*/
|
|
collisionresult_t physicsCheckCircleAABB(
|
|
float_t circleX, float_t circleY, float_t circleR,
|
|
float_t aabb, float_t aabbY,
|
|
float_t aabbWidth, float_t aabbHeight
|
|
);
|
|
|
|
/**
|
|
* Calculate the closest point on a line segment to a point.
|
|
*
|
|
* @param ax X coordinate of the first endpoint of the segment.
|
|
* @param ay Y coordinate of the first endpoint of the segment.
|
|
* @param bx X coordinate of the second endpoint of the segment.
|
|
* @param by Y coordinate of the second endpoint of the segment.
|
|
* @param px X coordinate of the point.
|
|
* @param py Y coordinate of the point.
|
|
* @param outX Pointer to store the X coordinate of the closest point.
|
|
* @param outY Pointer to store the Y coordinate of the closest point.
|
|
*/
|
|
void physicsClosestPointOnSegment(
|
|
float_t ax, float_t ay,
|
|
float_t bx, float_t by,
|
|
float_t px, float_t py,
|
|
float_t *outX, float_t *outY
|
|
);
|
|
|
|
/**
|
|
* Check if a point is inside a triangle defined by three vertices.
|
|
*
|
|
* @param px X coordinate of the point.
|
|
* @param py Y coordinate of the point.
|
|
* @param x0 X coordinate of the first vertex of the triangle.
|
|
* @param y0 Y coordinate of the first vertex of the triangle.
|
|
* @param x1 X coordinate of the second vertex of the triangle.
|
|
* @param y1 Y coordinate of the second vertex of the triangle.
|
|
* @param x2 X coordinate of the third vertex of the triangle.
|
|
* @param y2 Y coordinate of the third vertex of the triangle.
|
|
* @return true if the point is inside the triangle, false otherwise.
|
|
*/
|
|
bool_t physicsIsPointInTriangle(
|
|
float_t px, float_t py,
|
|
float_t x0, float_t y0,
|
|
float_t x1, float_t y1,
|
|
float_t x2, float_t y2
|
|
);
|
|
|
|
/**
|
|
* Check for collision between a circle and a triangle.
|
|
*
|
|
* @param circleX X coordinate of the circle's center.
|
|
* @param circleY Y coordinate of the circle's center.
|
|
* @param circleR Radius of the circle.
|
|
* @param triX0 X coordinate of the first vertex of the triangle.
|
|
* @param triY0 Y coordinate of the first vertex of the triangle.
|
|
* @param triX1 X coordinate of the second vertex of the triangle.
|
|
* @param triY1 Y coordinate of the second vertex of the triangle.
|
|
* @param triX2 X coordinate of the third vertex of the triangle.
|
|
* @param triY2 Y coordinate of the third vertex of the triangle.
|
|
* @return A collisionresult_t structure containing collision information.
|
|
*/
|
|
collisionresult_t physicsCheckCircleTriangle(
|
|
float_t circleX, float_t circleY, float_t circleR,
|
|
float_t triX0, float_t triY0,
|
|
float_t triX1, float_t triY1,
|
|
float_t triX2, float_t triY2
|
|
);
|
|
|
|
/**
|
|
* Check for collision between a circle and a tile.
|
|
*
|
|
* @param circleX X coordinate of the circle's center.
|
|
* @param circleY Y coordinate of the circle's center.
|
|
* @param circleR Radius of the circle.
|
|
* @param tileX X coordinate of the tile's top-left corner.
|
|
* @param tileY Y coordinate of the tile's top-left corner.
|
|
* @param tile The tile to check against.
|
|
* @return A collisionresult_t structure containing collision information.
|
|
*/
|
|
collisionresult_t physicsCheckCircleTile(
|
|
float_t circleX, float_t circleY, float_t circleR,
|
|
float_t tileX, float_t tileY, tile_t tile
|
|
); |