erincatto/box2d
GitHub: erincatto/box2d
Box2D 是一款高性能的开源 2D 物理引擎,为游戏提供碰撞检测和刚体动力学模拟。
Stars: 9552 | Forks: 1741

# 构建状态
[](https://github.com/erincatto/box2d/actions)
# Box2D
Box2D 是一款用于游戏的 2D 物理引擎。
[](https://www.youtube.com/watch?v=dAoM-xjOWtA)
## 功能特性
### 碰撞
- 连续碰撞检测
- 接触事件
- 凸多边形、胶囊体、圆形、圆角多边形、线段和链状形状
- 每个刚体支持多种形状
- 碰撞过滤
- 射线投射、形状投射和重叠查询
- 传感器系统
### 物理
- 稳健的 *Soft Step* 刚体求解器
- 用于快速平移和旋转的连续物理
- 基于孤岛的休眠
- 旋转、平移、距离、鼠标、焊接和轮式关节
- 关节限制、马达、弹簧和摩擦
- 关节力和接触力
- 刚体移动事件和休眠通知
### 系统
- 面向数据的设计
- 使用可移植的 C17 编写
- 广泛的多线程和 SIMD 支持
- 针对大量刚体堆叠进行了优化
### 示例
- OpenGL 配合 GLFW 和 enkiTS
- 使用 imgui 的图形用户界面
- 许多用于演示功能和性能的示例
## Visual Studio 构建
- 安装 [CMake](https://cmake.org/)
- 确保 CMake 在用户的 `PATH` 中
- 运行 `create_sln.bat`
- 打开并构建 `build/box2d.sln`
## Linux 构建
- 从 bash shell 运行 `build.sh`
- 结果位于 build 子文件夹中
## Xcode 构建
- 安装 [CMake](https://cmake.org)
- 在 .zprofile 中将 Cmake 添加到路径(默认终端 shell 为 zsh)
- export PATH="/Applications/CMake.app/Contents/bin:$PATH"
- mkdir build
- cd build
- cmake -G Xcode ..
- 打开 `box2d.xcodeproj`
- 选择 samples scheme
- 构建并运行 samples
## 构建和安装
- mkdir build
- cd build
- cmake ..
- cmake --build . --config Release
- cmake --install . (可能需要 sudo)
## 兼容性
Box2D 库和示例可在 Windows、Linux 和 Mac 上构建和运行。
你需要一个支持 C17 的编译器来构建 Box2D 库。
你需要一个支持 C++20 的编译器来构建示例。
Box2D 使用 SSE2 和 Neon SIMD 数学来提高性能。可以通过定义 `BOX2D_DISABLE_SIMD` 来禁用此功能。
## 文档
- [手册](https://box2d.org/documentation/)
- [迁移指南](https://github.com/erincatto/box2d/blob/main/docs/migration.md)
# 提供反馈
请在 discord 上提交 issue 或开始聊天。你也可以使用 [GitHub Discussions](https://github.com/erincatto/box2d/discussions)。
## 许可证
Box2D 由 Erin Catto 开发,并使用 [MIT license](https://en.wikipedia.org/wiki/MIT_License)。
## 赞助
通过 [Github Sponsors](https://github.com/sponsors/erincatto) 支持 Box2D 的开发。
请考虑为该仓库点 Star 并订阅我的 [YouTube 频道](https://www.youtube.com/@erin_catto)。
## 外部移植、封装和绑定(不受支持)
- Beef bindings - https://github.com/EnokViking/Box2DBeef
- C++ bindings - https://github.com/HolyBlackCat/box2cpp
- WASM - https://github.com/Birch-san/box2d3-wasm
标签:2D物理引擎, Bash脚本, Box2D, C17, Mutation, OpenGL, SIMD优化, 仿真, 刚体动力学, 可视化, 实时物理, 客户端加密, 开源库, 搜索引擎爬虫, 游戏开发, 游戏引擎, 游戏物理, 游戏编程, 物理模拟, 碰撞检测, 计算机图形学