forked from phenomLi/Torque
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
node_modules/ | ||
test/ | ||
readme.md | ||
todolist.txt | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Torque | ||
|
||
2D 刚体高性能物理引擎,不包含渲染。 | ||
|
||
## usage | ||
初始化一个 torque 实例 | ||
```javascript | ||
const torque = new Torque(width, height); | ||
``` | ||
|
||
创建并添加一个矩形 | ||
```javascript | ||
const rect = Torque.body.Rect(100, 100, 100, 200); | ||
torque.append(rect); | ||
``` | ||
此时一个宽 100,高 200 的矩形被创建在物理世界中的(100,100)位置上。但是此时我们看不到任何画面。 | ||
|
||
Torque 仅包含物理计算,不包含渲染器,因此你需要选取一个渲染器进行图形绘制。以 [zrender](https://ecomfe.github.io/zrender-doc/public/) 为例,给这个矩形添加渲染器: | ||
```javascript | ||
const rectShape = new zrender.Rect({ | ||
origin: [w / 2, h / 2], | ||
position: [x, y], | ||
rotation: -rect.rotation || 0, | ||
shape: { | ||
x: 0, | ||
y: 0, | ||
width: w, | ||
height: h | ||
}, | ||
style: { | ||
fill: '#f38181', | ||
text: rect.id, | ||
transformText: true | ||
} | ||
}); | ||
|
||
rect.setRender(function(body) { | ||
rectShape.attr({ | ||
rotation: -body.rotation, | ||
position: [body.position.x - w / 2, body.position.y - h / 2] | ||
}); | ||
}); | ||
|
||
zr.add(rectShape); | ||
``` | ||
刷新浏览器,享受 torque 创建的物理事件把! | ||
|
||
|
||
## feature | ||
- **NFSP-SAT技术** | ||
- 休眠/唤醒技术 | ||
- Warm Start | ||
- Sequential Impulses | ||
- 碰撞缓存/复用技术 | ||
- 碰撞过滤 | ||
- 动态 dt | ||
- 凹多边形 | ||
- 固定的刚体 | ||
- 摩擦力,恢复系数 | ||
- 事件(collisionStart/collisionEnd/sleepStart/sleepEnd...) | ||
- ...... | ||
|
||
## demo | ||
[戳这里](https://phenomli.github.io/Torque/) | ||
|
||
## 关于NFSP-SAT | ||
NFSP-SAT技术是本人研究得到的针对SAT(分离轴测试算法)的一个优化算法,能大幅提高碰撞检测的效率。在给定7 * 17个正16边形的静止碰撞(rest collision)条件下,与未经过优化的常规SAT对比结果如下(关闭碰撞复用和休眠功能): | ||
 | ||
 | ||
|
||
NFSP-SAT主要针对SAT进行改进,但同时,NFSP-SAT也优化了碰撞复用和碰撞点求解的性能。 | ||
## A.D. | ||
想了解制作物理引擎相关技术细节,可以关注[我的博客](https://github.com/phenomLi/Blog)(不定时更新) |