Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Exported cp.bb and updated build

  • Loading branch information...
commit d2d57c7f346bda3439d74859c663b1db9e87c234 1 parent 9b167c5
Joseph Gentle josephg authored
24 cp.js
View
@@ -142,10 +142,9 @@ 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;
@@ -153,13 +152,12 @@ var areaForPoly = cp.areaForPoly = function(verts)
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;
@@ -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;
}
};
@@ -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;
@@ -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(
4 cp.min.js
View
2 additions, 2 deletions not shown
5 demo/PyramidStack.js
View
@@ -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;
@@ -58,6 +58,7 @@ var PyramidStack = function() {
PyramidStack.prototype = Object.create(Demo.prototype);
+/*
PyramidStack.prototype.update = function(dt)
{
var steps = 3;
@@ -65,7 +66,7 @@ PyramidStack.prototype.update = function(dt)
for (var i = 0; i < 3; i++){
this.space.step(dt);
}
-};
+};*/
addDemo('PyramidStack', PyramidStack);
3  demo/demo.js
View
@@ -162,6 +162,7 @@ Demo.prototype.draw = function() {
});
// Draw collisions
+ /*
ctx.strokeStyle = "red";
ctx.lineWidth = 2;
@@ -181,7 +182,7 @@ Demo.prototype.draw = function() {
ctx.lineTo(p.x - 2, p.y + 2);
ctx.stroke();
}
- }
+ }*/
if (this.mouseJoint) {
ctx.beginPath();
4 lib/cpBB.js
View
@@ -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;
@@ -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(
Please sign in to comment.
Something went wrong with that request. Please try again.