stdlib/physicsView source ↗
physics
29 items · generated by scribe fromstdlib/physics.fd· synced 2026-11-15
Contents
- AABB (struct)
- physics_aabb_new (function)
- physics_aabb_collides (function)
- physics_aabb_contains_point (function)
- physics_aabb_center (function)
- physics_aabb_overlap (function)
- physics_aabb_mtv (function)
- Circle (struct)
- physics_circle_new (function)
- physics_circle_collides (function)
- physics_circle_contains (function)
- physics_circle_distance (function)
- Ray (struct)
- physics_ray_new (function)
- physics_ray_vs_aabb (function)
- physics_ray_vs_circle (function)
- Body (struct)
- physics_body_create (function)
- physics_body_set_velocity (function)
- physics_body_set_acceleration (function)
- physics_body_set_mass (function)
- physics_body_set_restitution (function)
- physics_body_apply_force (function)
- physics_body_apply_impulse (function)
- physics_body_update (function)
- physics_body_aabb (function)
- physics_resolve_collision (function)
- physics_resolve_vs_static (function)
- physics_elastic_collision (function)
AABB
pub struct AABB {Fields:
| Name | Type |
|---|---|
x | f64 |
y | f64 |
width | f64 |
height | f64 |
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:f64y:f64width:f64height: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:AABBb: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:AABBpx:f64py: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:AABBb: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:AABBb:AABB
Returns: (f64, f64)
Defined at line 89
Circle
pub struct Circle {Fields:
| Name | Type |
|---|---|
cx | f64 |
cy | f64 |
radius | f64 |
Defined at line 133
physics_circle_new
Create a circle.
pub fn physics_circle_new(cx: f64, cy: f64, radius: f64) -> Circle {Parameters:
cx:f64cy:f64radius: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:Circleb: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:Circlepx:f64py: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:Circleb:Circle
Returns: f64
Defined at line 164
Ray
pub struct Ray {Fields:
| Name | Type |
|---|---|
origin_x | f64 |
origin_y | f64 |
dir_x | f64 |
dir_y | f64 |
max_dist | f64 |
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:f64oy:f64dx:f64dy:f64max_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:Raybox: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:Rayc:Circle
Returns: f64
Defined at line 270
Body
pub struct Body {Fields:
| Name | Type |
|---|---|
x | f64 |
y | f64 |
vx | f64 |
vy | f64 |
ax | f64 |
ay | f64 |
width | f64 |
height | f64 |
mass | f64 |
restitution | f64 |
grounded | bool |
active | bool |
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:f64y:f64width:f64height: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 Bodyvx:f64vy: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 Bodyax:f64ay: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 Bodymass: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 Bodyr: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 Bodyfx:f64fy: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 Bodyix:f64iy: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 Bodydt:f64gravity: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 Bodyb: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 Bodytile: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 Bodyb:& mut Body
Returns: void
Defined at line 491
Generated by scribe, the Fides documentation generator