Skip to content

Latest commit

 

History

History
61 lines (39 loc) · 1.59 KB

README.md

File metadata and controls

61 lines (39 loc) · 1.59 KB

Build Status

box2d-native

Box2D v2.3.1 as native Node.js addon.

Details

Box2D compiled as static library, Node.js C++ addon produced by swig.

Install

Requires curl, make, cmake, g++. See also requirements for building swig and node-gyp

Install with NPM:

npm install node-gyp -g
npm install box2d-native

IMPORTANT: Installation tested only on Linux with Node.js >= 4.2.1 and gc++ 4.9.

Usage

import {World, Vec2, BodyDef, Body} from 'box2d-native';

let world = new World(gravity);
let body = world.CreateBody(new BodyDef());

world.Step(1 / 60, 3, 3);

Original "namespaced" Box2D classes (b2Vec2, b2World...) are also exposed.

Demo

IMPORTANT: Runs only with Node.js v4.2.1

npm install node-gyp -g
git checkout https://github.com/zuker/box2d-native.git
cd box2d-native/demo
npm install
npm start

Performance

Results from bench2d (i7 2.9GHZ, 4GB RAM, Ubuntu 15.04):

  • box2d.js: ms/frame: 3.5537109375 5th %ile: 3 95th %ile: 4

  • box2d-native: ms/frame: 1.689453125 5th %ile: 1 95th %ile: 2

TODO

  • Improve demo (implement all stuff from C++ Box2D testbed).
  • Refactor build, use more convenient tool.
  • Provide more benchmark results to compare with.
  • Tests.