Gama C Library
Gama C API Documentation
collision.h File Reference

Defines collision structures and provides functions for 2D collision detection. More...

#include "body.h"
#include "system.h"
#include <math.h>

Go to the source code of this file.

Data Structures

struct  gm_collision
 Structure to store detailed information about a collision between two bodies. More...

Typedefs

typedef struct gm_collision gmCollision
 Structure to store detailed information about a collision between two bodies.

Functions

gmCollisiongm_collision_detect (gmBody *a, gmBody *b)
 Detects a collision between two physics bodies based on their collider types.
int gm_body_contains (gmBody *body, double x, double y)
 Checks if a given point (x, y) is contained within a body's collider.
int gm_mouse_in_rect (const double x, const double y, const double w, const double h)
 Checks if the mouse cursor is currently within a given rectangular area.
int gm_mouse_in_circle (const double x, const double y, const double r)
 Checks if the mouse cursor is currently within a given circular area.

Detailed Description

Defines collision structures and provides functions for 2D collision detection.

This file contains the core logic for detecting collisions between different types of physics bodies (rectangles and circles) and structures to hold collision information.

Typedef Documentation

◆ gmCollision

typedef struct gm_collision gmCollision

Structure to store detailed information about a collision between two bodies.

Function Documentation

◆ gm_body_contains()

int gm_body_contains ( gmBody * body,
double x,
double y )

Checks if a given point (x, y) is contained within a body's collider.

Checks if a point is contained within a body's collider.

This function performs a point-in-rectangle test for GM_COLLIDER_RECT and a point-in-circle test for GM_COLLIDER_CIRCLE.

Parameters
bodyPointer to the body to check.
xThe x-coordinate of the point.
yThe y-coordinate of the point.
Returns
1 if the point is inside the body's collider, 0 otherwise.

◆ gm_collision_detect()

gmCollision * gm_collision_detect ( gmBody * a,
gmBody * b )

Detects a collision between two physics bodies based on their collider types.

Detects a collision between two physics bodies.

This function dispatches to specific collision tests (e.g., AABB vs AABB, Circle vs Circle, Circle vs AABB) based on the collider_type of the input bodies.

Parameters
aPointer to the first body.
bPointer to the second body.
Returns
A dynamically allocated gmCollision structure if a collision occurs, otherwise NULL. The caller is responsible for freeing the returned gmCollision object if it's not managed by a gmSystem.

◆ gm_mouse_in_circle()

int gm_mouse_in_circle ( const double x,
const double y,
const double r )

Checks if the mouse cursor is currently within a given circular area.

Parameters
xThe x-coordinate of the center of the circle.
yThe y-coordinate of the center of the circle.
rThe radius of the circle.
Returns
1 if the mouse is inside the circle, 0 otherwise.

◆ gm_mouse_in_rect()

int gm_mouse_in_rect ( const double x,
const double y,
const double w,
const double h )

Checks if the mouse cursor is currently within a given rectangular area.

Parameters
xThe x-coordinate of the center of the rectangle.
yThe y-coordinate of the center of the rectangle.
wThe width of the rectangle.
hThe height of the rectangle.
Returns
1 if the mouse is inside the rectangle, 0 otherwise.