Skip to content

navegador5/Torque

This branch is 9 commits behind phenomLi/Torque:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b9f5cdf · Oct 26, 2020

History

45 Commits
Oct 26, 2020
Oct 26, 2020
Sep 13, 2020
Oct 25, 2020
Oct 26, 2020
Dec 26, 2019
Oct 12, 2020
Oct 23, 2020
Oct 25, 2020
Jun 11, 2020
Oct 23, 2020
Jun 11, 2020
Jun 14, 2020

Repository files navigation

Torque

2D 刚体高性能物理引擎,不包含渲染。

usage

初始化一个 torque 实例

const torque = new Torque(width, height);

创建并添加一个矩形

const rect = Torque.body.Rect(100, 100, 100, 200);      
torque.append(rect);

此时一个宽 100,高 200 的矩形被创建在物理世界中的(100,100)位置上。但是此时我们看不到任何画面。

Torque 仅包含物理计算,不包含渲染器,因此你需要选取一个渲染器进行图形绘制。以 PIXI 为例,给这个矩形添加渲染器:

const app = new PIXI.Application({
    width: 800, 
    height: 600,
    antialias: true,   
});

let rectangle = new PIXI.Graphics();

shape.lineStyle(0.8, 0x000000, 1);
shape.beginFill();
        
rectangle.position.x = 100 + 100 / 2;
rectangle.position.y = 100 + 100 / 2;
rectangle.drawRect(-100 / 2, -100 / 2, 100, 100);

rectangle.endFill();

rect.setRender(function(body) {
    rectangle.position.x = body.position.x;
    rectangle.position.y = body.position.y;
    rectangle.rotation = body.rotation;
});

app.stage.add(rectangle);

至此,由PIXI创建的矩形rectangle与Torque世界的矩形rect通过setRender函数绑定在了一起。刷新浏览器,可以看见一个黑色边框的,长宽都为100的矩形出现在(100, 100)的位置。

feature

  • SATBoost技术
  • 休眠 / 唤醒技术
  • Warm Start
  • Sequential Impulses
  • 基于SATBoost的快速碰撞缓存 / 复用技术
  • 碰撞过滤
  • 基于SATBoost的快速V-clip碰撞点求解方法
  • 动态 dt
  • 凹多边形
  • 复合刚体
  • 静态 / 运动 / 动态的刚体
  • 摩擦力,静摩擦力,空气摩擦,恢复系数
  • 事件(collisionStart/collisionEnd/sleepStart/sleepEnd...)

Demo

(最新的DEMO已将渲染器从zrender替换至PIXI,因PIXI是基于WebGL渲染,具有更好的性能) 戳这里

关于SATBoost

SATBoost技术是本人研究得到的针对SAT(分离轴测试算法)的一个优化算法,能大幅提高碰撞检测的效率。在给定7 * 17个正16边形的静止碰撞(rest collision)条件下,与未经过优化的常规SAT对比结果如下(关闭碰撞复用和休眠功能):

SATBoost主要针对SAT进行改进,但同时,SATBoost也优化了碰撞复用和碰撞点求解的性能。

A.D.

想了解制作物理引擎相关技术细节,可以关注我的博客(不定时更新)

About

2d 纯计算高性能刚体物理引擎

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 92.7%
  • JavaScript 5.3%
  • HTML 2.0%