Skip to content

Commit

Permalink
Exported cp.bb and updated build
Browse files Browse the repository at this point in the history
  • Loading branch information
josephg committed Feb 19, 2012
1 parent 9b167c5 commit d2d57c7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
24 changes: 12 additions & 12 deletions cp.js
Expand Up @@ -142,24 +142,22 @@ var momentForPoly = cp.momentForPoly = function(m, verts, offset)

var areaForPoly = cp.areaForPoly = function(verts)
{
throw new Error('Not updated for flat verts');
var area = 0;
for(var i=0, len=verts.length; i<len; i++){
area += vcross(verts[i], verts[(i+1)%len]);
for(var i=0, len=verts.length; i<len; i+=2){
area += vcross(new Vect(verts[i], verts[i+1]), new Vect(verts[(i+2)%len], verts[(i+3)%len]));
}

return -area/2;
};

var centroidForPoly = cp.centroidForPoly = function(verts)
{
throw new Error('Not updated for flat verts');
var sum = 0;
var vsum = [0,0];
var vsum = new Vect(0,0);

for(var i=0, len=verts.length; i<len; i++){
var v1 = verts[i];
var v2 = verts[(i+1)%len];
for(var i=0, len=verts.length; i<len; i+=2){
var v1 = new Vect(verts[i], verts[i+1]);
var v2 = new Vect(verts[(i+2)%len], verts[(i+3)%len]);
var cross = vcross(v1, v2);

sum += cross;
Expand All @@ -171,11 +169,11 @@ var centroidForPoly = cp.centroidForPoly = function(verts)

var recenterPoly = cp.recenterPoly = function(verts)
{
throw new Error('Not updated for flat verts');
var centroid = centroidForPoly(verts);

for(var i=0; i<verts.length; i++){
verts[i] = vsub(verts[i], centroid);
for(var i=0; i<verts.length; i+=2){
verts[i] -= centroid.x;
verts[i+1] -= centroid.y;
}
};

Expand Down Expand Up @@ -513,7 +511,7 @@ var vstr = cp.v.str = function(v)
var numBB = 0;

// Bounding boxes are JS objects with {l, b, r, t} = left, bottom, right, top, respectively.
var BB = function(l, b, r, t)
var BB = cp.BB = function(l, b, r, t)
{
this.l = l;
this.b = b;
Expand All @@ -523,6 +521,8 @@ var BB = function(l, b, r, t)
numBB++;
};

cp.bb = function(l, b, r, t) { return new BB(l, b, r, t); };

var bbNewForCircle = function(p, r)
{
return new BB(
Expand Down
4 changes: 2 additions & 2 deletions cp.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions demo/PyramidStack.js
Expand Up @@ -23,7 +23,7 @@ var PyramidStack = function() {
Demo.call(this);

var space = this.space;
space.iterations = 30;
//space.iterations = 30;
space.gravity = v(0, -100);
space.sleepTimeThreshold = 0.5;
space.collisionSlop = 0.5;
Expand Down Expand Up @@ -58,14 +58,15 @@ var PyramidStack = function() {

PyramidStack.prototype = Object.create(Demo.prototype);

/*
PyramidStack.prototype.update = function(dt)
{
var steps = 3;
dt /= steps;
for (var i = 0; i < 3; i++){
this.space.step(dt);
}
};
};*/

addDemo('PyramidStack', PyramidStack);

3 changes: 2 additions & 1 deletion demo/demo.js
Expand Up @@ -162,6 +162,7 @@ Demo.prototype.draw = function() {
});

// Draw collisions
/*
ctx.strokeStyle = "red";
ctx.lineWidth = 2;
Expand All @@ -181,7 +182,7 @@ Demo.prototype.draw = function() {
ctx.lineTo(p.x - 2, p.y + 2);
ctx.stroke();
}
}
}*/

if (this.mouseJoint) {
ctx.beginPath();
Expand Down
4 changes: 3 additions & 1 deletion lib/cpBB.js
Expand Up @@ -24,7 +24,7 @@
var numBB = 0;

// Bounding boxes are JS objects with {l, b, r, t} = left, bottom, right, top, respectively.
var BB = function(l, b, r, t)
var BB = cp.BB = function(l, b, r, t)
{
this.l = l;
this.b = b;
Expand All @@ -34,6 +34,8 @@ var BB = function(l, b, r, t)
numBB++;
};

cp.bb = function(l, b, r, t) { return new BB(l, b, r, t); };

var bbNewForCircle = function(p, r)
{
return new BB(
Expand Down

0 comments on commit d2d57c7

Please sign in to comment.