12 个版本
0.3.2 | 2022年2月9日 |
---|---|
0.3.1 | 2022年2月7日 |
0.2.1 | 2022年2月5日 |
0.1.6 | 2022年2月5日 |
1721 在 数据结构 中
每月下载量 35
51KB
1.5K SLoC
bsp-pathfinding
提供使用二进制空间划分进行路径查找搜索空间生成和 A* 搜索算法。
可导航的空间由界定空间的 polygons 定义。将生成可导航节点和边的图。
该算法不对场景的大小或角度施加任何约束,这与基于网格或四叉树的方案不同。
用法
use bsp_pathfinding::*;
use glam::*;
// Define a simple scene
let square = Shape::rect(Vec2::new(50.0, 50.0), Vec2::new(0.0, 0.0));
let left = Shape::rect(Vec2::new(10.0, 200.0), Vec2::new(-200.0, 10.0));
let right = Shape::rect(Vec2::new(10.0, 200.0), Vec2::new(200.0, 10.0));
let bottom = Shape::rect(Vec2::new(200.0, 10.0), Vec2::new(10.0, -200.0));
let top = Shape::rect(Vec2::new(200.0, 10.0), Vec2::new(10.0, 200.0));
// Create navigational context from the scene
let nav = NavigationContext::new([square, left, right, top, bottom].iter().flatten());
// Find a path
let start = Vec2::new(-100.0, 0.0);
let end = Vec2::new(100.0, 30.0);
let path = nav
.find_path(start, end, heuristics::euclidiean, SearchInfo::default())
.expect("Failed to find a path");
依赖项
~4.5MB
~119K SLoC