Git Product home page Git Product logo

torque's Introduction

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.

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

torque's People

Contributors

phenomli avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.