Skip to content

Commit e8508bb

Browse files
authored
feat(lambda-rs): Add 2d collision events (#201)
## Summary Add 2D collision queries, collision filtering, and collision start/end events to the `physics-2d` feature. ## Related Issues - Resolves #121 ## Changes - Add public 2D physics API scaffolding in `lambda-rs`: - `CollisionEventKind` - `CollisionEvent` - `CollisionFilter` - `RaycastHit` - `PhysicsWorld2D::collision_events()` - `PhysicsWorld2D::query_point()` - `PhysicsWorld2D::query_aabb()` - `PhysicsWorld2D::raycast()` - `Collider2DBuilder::with_collision_filter()` - Add backend support in `lambda-rs-platform` Rapier integration for: - collider collision group/mask filtering - point queries - AABB overlap queries - nearest-hit raycasts - body-pair `Started` collision events - body-pair `Ended` collision events - compound-body collider aggregation into one public body-pair event stream - Add public-to-backend handle mapping support so query and event results can be reconstructed as stable `RigidBody2D` handles - Add focused integration tests for: - collision filters - point, AABB, and ray queries - collision start events - collision end events - queue draining behavior - compound-body deduplication behavior - Add a new demo binary: - `demos/physics/src/bin/physics_collision_events_2d.rs` - shows floor/ball contact start and end events - logs event data and changes ball tint while contact is active - Add and update documentation: - new spec for 2D collision queries and events - spec index update - `docs/features.md` update for `physics-2d` - new tutorial for the collision events demo - tutorial index update ## Type of Change - [ ] Bug fix (non-breaking change that fixes an issue) - [x] Feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [x] Documentation (updates to docs, specs, tutorials, or comments) - [ ] Refactor (code change that neither fixes a bug nor adds a feature) - [ ] Performance (change that improves performance) - [x] Test (adding or updating tests) - [ ] Build/CI (changes to build process or CI configuration) ## Affected Crates - [x] `lambda-rs` - [x] `lambda-rs-platform` - [ ] `lambda-rs-args` - [ ] `lambda-rs-logging` - [x] Other: `demos/physics`, `docs/specs`, `docs/tutorials` ## Checklist - [x] Code follows the repository style guidelines (`cargo +nightly fmt --all`) - [x] Code passes clippy (`cargo clippy --workspace --all-targets -- -D warnings`) - [x] Tests pass (`cargo test --workspace`) - [x] New code includes appropriate documentation - [x] Public API changes are documented - [ ] Breaking changes are noted in this PR description ## Testing **Commands run:** ```bash cargo +nightly fmt --all cargo build -p lambda-rs --features physics-2d cargo test -p lambda-rs --features physics-2d -- --nocapture cargo test -p lambda-rs --features physics-2d collision_filters -- --nocapture cargo test -p lambda-rs --features physics-2d queries -- --nocapture cargo test -p lambda-rs --features physics-2d collision_events -- --nocapture cargo build -p lambda-demos-physics --bin physics_collision_events_2d cargo clippy --workspace --all-targets -- -D warnings cargo test --workspace ``` **Manual verification steps (if applicable):** 1. Run `cargo run -p lambda-demos-physics --bin physics_collision_events_2d`. 2. Observe the ball falling onto the floor and a `Started` event being logged. 3. Press `Space` while the ball is grounded to apply the launch impulse. 4. Observe the ball leaving the floor, a corresponding `Ended` event, and the ball tint returning to its non-contact state. ## Screenshots/Recordings Not included. The main visual change is the new `physics_collision_events_2d` demo. ## Platform Testing - [x] macOS - [ ] Windows - [ ] Linux ## Additional Notes - Queries intentionally scan the live collider set so they work before the first simulation step. - `collision_events()` is a post-step drain rather than a callback system, which keeps gameplay logic outside backend simulation execution.
2 parents 37e7304 + 6578f74 commit e8508bb

16 files changed

Lines changed: 3603 additions & 18 deletions

File tree

crates/lambda-rs-platform/src/physics/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ pub mod rapier2d;
88

99
pub use rapier2d::{
1010
Collider2DBackendError,
11+
CollisionEvent2DBackend,
12+
CollisionEventKind2DBackend,
1113
PhysicsBackend2D,
14+
RaycastHit2DBackend,
1215
RigidBody2DBackendError,
1316
RigidBodyType2D,
1417
};

0 commit comments

Comments
 (0)