Skip to content

stdlib/physicsView source ↗

physics

29 items · generated by scribe fromstdlib/physics.fd· synced 2026-11-15

stdlib/physics29 items

Contents

AABB

pub struct AABB {

Fields:

NameType
xf64
yf64
widthf64
heightf64

Defined at line 17


physics_aabb_new

Create an AABB.

pub fn physics_aabb_new(x: f64, y: f64, width: f64, height: f64) -> AABB {

Parameters:

  • x: f64
  • y: f64
  • width: f64
  • height: f64

Returns: AABB

Defined at line 28


physics_aabb_collides

Check if two AABBs overlap.

pub fn physics_aabb_collides(a: AABB, b: AABB) -> bool {

Parameters:

  • a: AABB
  • b: AABB

Returns: bool

Defined at line 35


physics_aabb_contains_point

Check if a point is inside an AABB.

pub fn physics_aabb_contains_point(box: AABB, px: f64, py: f64) -> bool {

Parameters:

  • box: AABB
  • px: f64
  • py: f64

Returns: bool

Defined at line 52


physics_aabb_center

Get the center of an AABB.

pub fn physics_aabb_center(box: AABB) -> (f64, f64) {

Parameters:

  • box: AABB

Returns: (f64, f64)

Defined at line 57


physics_aabb_overlap

Get the overlap region of two overlapping AABBs. Returns (x, y, w, h). If they don’t overlap, returns (0, 0, 0, 0).

pub fn physics_aabb_overlap(a: AABB, b: AABB) -> (f64, f64, f64, f64) {

Parameters:

  • a: AABB
  • b: AABB

Returns: (f64, f64, f64, f64)

Defined at line 63


physics_aabb_mtv

Compute the minimum translation vector to separate two overlapping AABBs. Returns (dx, dy) — the direction to push a out of b.

pub fn physics_aabb_mtv(a: AABB, b: AABB) -> (f64, f64) {

Parameters:

  • a: AABB
  • b: AABB

Returns: (f64, f64)

Defined at line 89


Circle

pub struct Circle {

Fields:

NameType
cxf64
cyf64
radiusf64

Defined at line 133


physics_circle_new

Create a circle.

pub fn physics_circle_new(cx: f64, cy: f64, radius: f64) -> Circle {

Parameters:

  • cx: f64
  • cy: f64
  • radius: f64

Returns: Circle

Defined at line 142


physics_circle_collides

Check if two circles overlap.

pub fn physics_circle_collides(a: Circle, b: Circle) -> bool {

Parameters:

  • a: Circle
  • b: Circle

Returns: bool

Defined at line 149


physics_circle_contains

Check if a point is inside a circle.

pub fn physics_circle_contains(c: Circle, px: f64, py: f64) -> bool {

Parameters:

  • c: Circle
  • px: f64
  • py: f64

Returns: bool

Defined at line 157


physics_circle_distance

Get the distance between two circle centers.

pub fn physics_circle_distance(a: Circle, b: Circle) -> f64 {

Parameters:

  • a: Circle
  • b: Circle

Returns: f64

Defined at line 164


Ray

pub struct Ray {

Fields:

NameType
origin_xf64
origin_yf64
dir_xf64
dir_yf64
max_distf64

Defined at line 184


physics_ray_new

Create a ray from origin in a direction with max distance.

pub fn physics_ray_new(ox: f64, oy: f64, dx: f64, dy: f64, max_dist: f64) -> Ray {

Parameters:

  • ox: f64
  • oy: f64
  • dx: f64
  • dy: f64
  • max_dist: f64

Returns: Ray

Defined at line 194


physics_ray_vs_aabb

Ray vs AABB intersection. Returns the hit distance, or -1.0 if no hit. Uses the slab method.

pub fn physics_ray_vs_aabb(ray: Ray, box: AABB) -> f64 {

Parameters:

  • ray: Ray
  • box: AABB

Returns: f64

Defined at line 217


physics_ray_vs_circle

Ray vs circle intersection. Returns hit distance or -1.0.

pub fn physics_ray_vs_circle(ray: Ray, c: Circle) -> f64 {

Parameters:

  • ray: Ray
  • c: Circle

Returns: f64

Defined at line 270


Body

pub struct Body {

Fields:

NameType
xf64
yf64
vxf64
vyf64
axf64
ayf64
widthf64
heightf64
massf64
restitutionf64
groundedbool
activebool

Defined at line 313


physics_body_create

Create a new rigid body.

pub fn physics_body_create(x: f64, y: f64, width: f64, height: f64) -> Body {

Parameters:

  • x: f64
  • y: f64
  • width: f64
  • height: f64

Returns: Body

Defined at line 340


physics_body_set_velocity

Set the body’s velocity.

pub fn physics_body_set_velocity(body: & mut Body, vx: f64, vy: f64) -> void {

Parameters:

  • body: & mut Body
  • vx: f64
  • vy: f64

Returns: void

Defined at line 347


physics_body_set_acceleration

Set the body’s acceleration.

pub fn physics_body_set_acceleration(body: & mut Body, ax: f64, ay: f64) -> void {

Parameters:

  • body: & mut Body
  • ax: f64
  • ay: f64

Returns: void

Defined at line 353


physics_body_set_mass

Set the body’s mass.

pub fn physics_body_set_mass(body: & mut Body, mass: f64) -> void {

Parameters:

  • body: & mut Body
  • mass: f64

Returns: void

Defined at line 359


physics_body_set_restitution

Set the body’s restitution (bounciness).

pub fn physics_body_set_restitution(body: & mut Body, r: f64) -> void {

Parameters:

  • body: & mut Body
  • r: f64

Returns: void

Defined at line 364


physics_body_apply_force

Apply a force to the body (F = ma → a += F/m).

pub fn physics_body_apply_force(body: & mut Body, fx: f64, fy: f64) -> void {

Parameters:

  • body: & mut Body
  • fx: f64
  • fy: f64

Returns: void

Defined at line 369


physics_body_apply_impulse

Apply an impulse (instant velocity change).

pub fn physics_body_apply_impulse(body: & mut Body, ix: f64, iy: f64) -> void {

Parameters:

  • body: & mut Body
  • ix: f64
  • iy: f64

Returns: void

Defined at line 377


physics_body_update

Update the body’s physics: integrate velocity and acceleration. gravity = downward acceleration (px/s²), e.g., 980.0 for Earth-like.

pub fn physics_body_update(body: & mut Body, dt: f64, gravity: f64) -> void {

Parameters:

  • body: & mut Body
  • dt: f64
  • gravity: f64

Returns: void

Defined at line 386


physics_body_aabb

Get the body’s AABB.

pub fn physics_body_aabb(body: Body) -> AABB {

Parameters:

  • body: Body

Returns: AABB

Defined at line 411


physics_resolve_collision

Resolve collision between two bodies using their AABBs. Pushes body a out of body b and adjusts velocity.

pub fn physics_resolve_collision(a: & mut Body, b: Body) -> void {

Parameters:

  • a: & mut Body
  • b: Body

Returns: void

Defined at line 421


physics_resolve_vs_static

Resolve collision between a body and a static AABB (e.g., a tile). The body is pushed out and velocity is zeroed in the push direction.

pub fn physics_resolve_vs_static(body: & mut Body, tile: AABB) -> void {

Parameters:

  • body: & mut Body
  • tile: AABB

Returns: void

Defined at line 451


physics_elastic_collision

Elastic collision response between two dynamic bodies. Exchanges momentum based on mass and restitution.

pub fn physics_elastic_collision(a: & mut Body, b: & mut Body) -> void {

Parameters:

  • a: & mut Body
  • b: & mut Body

Returns: void

Defined at line 491


Generated by scribe, the Fides documentation generator