DailyJS

Matter.js

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

html5 webgl physics

Matter.js

Posted by Alex R. Young on .
Featured

html5 webgl physics

Matter.js

Posted by Alex R. Young on .

The Matter.js Wrecking Ball demo.

Matter.js (GitHub: liabru / matter-js, License: MIT) by Liam Brummitt is a stable and flexible rigid body physics engine for browsers. The author describes it as an alpha project that came about as a result of learning game programming.

If you're interested in reading more about physics for game programming, Liam has collected some useful resources in Game physics for beginners.

Matter.js uses time-corrected Verlet integration, adaptive grid broad-phase detection, AABB mid-phase detection, SAT narrow-phase detection, and other algorithms for managing collisions and physical simulation. More well-known engines like Box2D support these features, but if you take a look at the some of the classes Liam has written then you'll see how clean and readable his version is.

I've been looking at the source to see how to use it, and the API seems friendly to me:

var Bodies = Matter.Bodies;  
var Engine = Matter.Engine;  
var engine = Engine.create(container, options);  
var World = Matter.World;

World.addBody(engine.world, Bodies.rectangle(300, 180, 700, 20, { isStatic: true, angle: Math.PI * 0.06 }));  
World.addBody(enigne.world, Bodies.rectangle(300, 70, 40, 40, { friction: 0.001 }));  

The demo is cool, so try it out if you want to experiment!