ekelokorpi/panda.js-plugins — pull request #12 by nvaken (2014-12-18 20:24:39+00:00)
Title: Feature/p2js debug

Okay, I've been able to add a bit more debugdraw support for P2.js. This addresses ekelokorpi/panda.js-plugins#9

- Compound objects (now showing all shapes in bodies)
- Rotation support
- Offset support
- Complex convex shapes

I think there are probably more additions to be made, though in my eyes, these are the first crucial missing debugdraw functions.

Sample code:

```
game.module(
'game.main'
)
.require(
'plugins.p2'
)
.body(function() {

game.createScene('Main', {
backgroundColor: 0xb9bec7,

init: function() {
this.world = new game.World({gravity: [0, 100]});
this.world.ratio = 1;

this.world.solver.iterations = 20;
this.world.solver.tolerance = 0.001;

this.world.setGlobalStiffness(1e4);

// Surface
var body = new game.Body();
body.position[0] = game.system.width / 2;
body.position[1] = game.system.height;

var bodyShape = new game.Rectangle(game.system.width, 100);
body.addShape(bodyShape);
this.world.addBody(body);

// COMPOUND BODY WITH RECTANGLES AND CIRCLES
var body = new game.Body({mass: 1});
body.position[0] = game.system.width / 2;
body.position[1] = game.system.height / 2;
body.mass = 1;

// First rectangle shape
// Pretty standard rectangle, no rotation
var bodyShape = new game.Rectangle(50, 100);
body.addShape(bodyShape, [-200, 0]);

// Second rectangle shape
// Pretty standard rectangle, rotation
var bodyShape = new game.Rectangle(50, 100);
body.addShape(bodyShape, [200, 100], Math.PI / 4);

// Third shape, circle this time
// Offsetted
var bodyShape = new game.Circle(50);
body.addShape(bodyShape, [0, -200], Math.PI / 4);

this.world.addBody(body);

// POLYGON BODY
var body = new game.Body({mass: 1});
body.position[0] = game.system.width / 2;
body.position[1] = game.system.height / 2;
body.mass = 1;

var path = [[-200, 200],
[-100, 0],
[100, 0],
[100, 100],
[50, 50]];
body.fromPolygon(path);
this.world.addBody(body);
},
update: function () {
this._super();
}
});

});
```