16个版本

新增 0.0.16 2024年8月18日
0.0.15 2024年8月4日
0.0.11 2024年7月30日
0.0.1 2024年2月26日

#116图形API

Download history 109/week @ 2024-06-28 374/week @ 2024-07-05 45/week @ 2024-07-12 3/week @ 2024-07-19 570/week @ 2024-07-26 275/week @ 2024-08-02 14/week @ 2024-08-09 114/week @ 2024-08-16

974 每月下载量

MIT 许可证

125KB
209

Impact-rs

此crate提供执行矩形与射线之间碰撞查询的实用程序,包括移动矩形的扫过检查。它利用fixed32 crate提供的定点数算术来处理计算。

功能

  • 射线与矩形碰撞检测:检测射线与矩形的碰撞,返回接触点、接触法线和最近碰撞时间。
  • 扫过矩形碰撞:检查一个矩形移动到另一个矩形附近时的潜在碰撞。可以使用2D向量增量,或者水平或垂直方向的标量扫过。
Swept Rectangle
  • 定点数精度:使用来自fixed32 crate的定点数(Fp)进行精确计算,避免浮点数错误。

使用方法

要将此crate添加到您的项目中,请将其添加到您的Cargo.toml文件中。

[dependencies]
impact_rs = "0.0.14"

示例

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.");
  }
}

依赖关系