Gama C Library
Gama C API Documentation
body.h File Reference
#include "mouse.h"
#include "position.h"
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  gmBody
 Structure representing a physics body with properties for collision and movement. More...

Macros

#define gnothing   NULL
 Macro representing a NULL pointer, for use where a generic null is needed.

Enumerations

enum  gmColliderType {
  GM_COLLIDER_CIRCLE ,
  GM_COLLIDER_RECT
}
 Enum to define the type of collider for a physics body. More...

Functions

gmBody gm_body_create (double mass, double x, double y, double w, double h, gmColliderType c)
 Creates a new physics body with specified properties.
void gm_max_speed (gmBody *body, double max_speed)
 Limits the maximum speed of a body.
void gm_min_speed (gmBody *body, double min_speed)
 Sets the minimum speed of a body.
void gm_speed (gmBody *body, double speed)
 Sets the speed of a body while preserving its current direction.
void gm_max_speed_anim (gmBody *body, double max_speed, void animator(double *value, double target, double dt, double t), double dt, double t)
 Limits the maximum speed of a body using an animation function.
void gm_min_speed_anim (gmBody *body, double min_speed, void animator(double *value, double target, double dt, double t), double dt, double t)
 Sets the minimum speed of a body using an animation function.
void gm_speed_anim (gmBody *body, double speed, void animator(double *value, double target, double dt, double t), double dt, double t)
 Sets the speed of a body using an animation function, preserving its direction.
gmBody gm_rectangle_body (double m, double x, double y, double w, double h)
 Creates a rectangular physics body.
gmBody gm_circle_body (double m, double x, double y, double r)
 Creates a circular physics body.
int gm_body_contains (gmBody *body, double x, double y)
 Checks if a point is contained within a body's collider.

Macro Definition Documentation

◆ gnothing

#define gnothing   NULL

Macro representing a NULL pointer, for use where a generic null is needed.

Enumeration Type Documentation

◆ gmColliderType

Enum to define the type of collider for a physics body.

Enumerator
GM_COLLIDER_CIRCLE 

Circular collider

GM_COLLIDER_RECT 

Rectangular collider

Function Documentation

◆ gm_body_contains()

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

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

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, 0 otherwise.

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_body_create()

gmBody gm_body_create ( double mass,
double x,
double y,
double w,
double h,
gmColliderType c )

Creates a new physics body with specified properties.

The radius for circular colliders is automatically set based on w (or h if smaller). For rectangular colliders, radius is set to w < h ? w : h.

Parameters
massThe mass of the body. Set to 0 for infinite mass.
xThe x-coordinate of the body's initial position.
yThe y-coordinate of the body's initial position.
wThe width of the body (or diameter for circles).
hThe height of the body (or diameter for circles).
cThe type of collider for the body (GM_COLLIDER_RECT or GM_COLLIDER_CIRCLE).
Returns
A new gmBody instance initialized with default active/non-static properties.

◆ gm_circle_body()

gmBody gm_circle_body ( double m,
double x,
double y,
double r )

Creates a circular physics body.

Parameters
mThe mass of the body.
xThe x-coordinate of the body's position.
yThe y-coordinate of the body's position.
rThe radius of the body.
Returns
A new circular gmBody instance.

◆ gm_max_speed()

void gm_max_speed ( gmBody * body,
double max_speed )

Limits the maximum speed of a body.

If the body's current speed exceeds max_speed, its velocity is scaled down to match max_speed while preserving its direction.

Parameters
bodyPointer to the body to modify.
max_speedThe maximum allowed speed.

◆ gm_max_speed_anim()

void gm_max_speed_anim ( gmBody * body,
double max_speed,
void animatordouble *value, double target, double dt, double t,
double dt,
double t )

Limits the maximum speed of a body using an animation function.

This function applies a smooth animation to the body's velocity components if its speed exceeds max_speed.

Parameters
bodyPointer to the body to modify.
max_speedThe maximum allowed speed.
animatorFunction pointer to animate the velocity change.
dtDelta time for animation.
tTime parameter for animation.

◆ gm_min_speed()

void gm_min_speed ( gmBody * body,
double min_speed )

Sets the minimum speed of a body.

If the body's current speed falls below min_speed (and is not zero), its velocity is scaled up to match min_speed while preserving its direction. If the body is stationary (speed is 0), its velocity remains 0.

Parameters
bodyPointer to the body to modify.
min_speedThe minimum allowed speed.

◆ gm_min_speed_anim()

void gm_min_speed_anim ( gmBody * body,
double min_speed,
void animatordouble *value, double target, double dt, double t,
double dt,
double t )

Sets the minimum speed of a body using an animation function.

This function applies a smooth animation to the body's velocity components if its speed falls below min_speed (and is not zero).

Parameters
bodyPointer to the body to modify.
min_speedThe minimum allowed speed.
animatorFunction pointer to animate the velocity change.
dtDelta time for animation.
tTime parameter for animation.

◆ gm_rectangle_body()

gmBody gm_rectangle_body ( double m,
double x,
double y,
double w,
double h )

Creates a rectangular physics body.

Parameters
mThe mass of the body.
xThe x-coordinate of the body's position.
yThe y-coordinate of the body's position.
wThe width of the body.
hThe height of the body.
Returns
A new rectangular gmBody instance.

◆ gm_speed()

void gm_speed ( gmBody * body,
double speed )

Sets the speed of a body while preserving its current direction.

If the body is stationary, it starts moving along the X-axis with the specified speed.

Parameters
bodyPointer to the body to modify.
speedThe target speed to set.

◆ gm_speed_anim()

void gm_speed_anim ( gmBody * body,
double speed,
void animatordouble *value, double target, double dt, double t,
double dt,
double t )

Sets the speed of a body using an animation function, preserving its direction.

This function applies a smooth animation to the body's velocity components to reach the speed. If the body is stationary, it starts moving along the X-axis.

Parameters
bodyPointer to the body to modify.
speedThe target speed to set.
animatorFunction pointer to animate the velocity change.
dtDelta time for animation.
tTime parameter for animation.