| Crates.io | impact-rs |
| lib.rs | impact-rs |
| version | 0.0.18 |
| created_at | 2024-02-26 08:59:49.084789+00 |
| updated_at | 2024-10-29 14:23:03.552916+00 |
| description | Collision query library for 2D games |
| homepage | |
| repository | https://github.com/piot/impact-rs |
| max_upload_size | |
| id | 1153220 |
| size | 155,409 |
This crate provides utilities for performing collision queries between rectangles and rays,
including swept checks for moving rectangles. It leverages fixed-point arithmetic provided by the fixed32 crate to
handle the computations.
Fp) from the fixed32 crate for precise calculations
without floating-point errors.To use this crate in your project, add it to your Cargo.toml:
[dependencies]
impact_rs = "0.0.17"
use fixed32::Fp;
use fixed32_math::{Rect, Vector};
use impact_rs::prelude::*;
fn main() {
let ray_origin = Vector::from((1, 2));
let ray_direction = Vector::from((3, 4));
let target_rect = Rect::from((5, 6, 7, 8));
let collision_result = ray_vs_rect(ray_origin, ray_direction, target_rect);
if let Some(result) = collision_result {
println!("Collision at: {:?}", result.contact_point);
println!("Normal at collision: {:?}", result.contact_normal);
println!("Closest collision time: {:?}", result.closest_time);
} else {
println!("No collision detected.");
}
}