diff --git a/Phaser/Phaser.csproj b/Phaser/Phaser.csproj
index 2de59ef55..13fa33151 100644
--- a/Phaser/Phaser.csproj
+++ b/Phaser/Phaser.csproj
@@ -210,33 +210,33 @@
Manager.ts
-
-
-
- ShapeBox.ts
-
-
- ShapeCircle.ts
-
-
-
-
- ShapePoly.ts
-
-
- ShapeSegment.ts
-
-
+
+
+ Box.ts
+
+
+
+ Circle.ts
+
IShape.ts
+
+
+ Poly.ts
+
+
+
+ Segment.ts
+
Shape.ts
-
- ShapeTriangle.ts
+
+
+ Triangle.ts
diff --git a/Phaser/physics/advanced/Collision.ts b/Phaser/physics/advanced/Collision.ts
index 333fa65a5..419a7d292 100644
--- a/Phaser/physics/advanced/Collision.ts
+++ b/Phaser/physics/advanced/Collision.ts
@@ -1,11 +1,13 @@
///
///
///
+///
+///
+///
+///
///
///
-///
///
-///
/**
* Phaser - Advanced Physics - Collision Handlers
@@ -22,8 +24,6 @@ module Phaser.Physics.Advanced {
public collide(a, b, contacts: Contact[]) {
- //console.log('collide', a.type, b.type);
-
// Circle (a is the circle)
if (a.type == Manager.SHAPE_TYPE_CIRCLE)
{
@@ -114,13 +114,13 @@ module Phaser.Physics.Advanced {
}
- public circle2Circle(circ1, circ2, contactArr) {
- return this._circle2Circle(circ1.tc, circ1.r, circ2.tc, circ2.r, contactArr);
+ public circle2Circle(circ1: Phaser.Physics.Advanced.Shapes.Circle, circ2: Phaser.Physics.Advanced.Shapes.Circle, contactArr: Contact[]) {
+ return this._circle2Circle(circ1.tc, circ1.radius, circ2.tc, circ2.radius, contactArr);
}
- public circle2Segment(circ: ShapeCircle, seg, contactArr: Contact[]) {
+ public circle2Segment(circ: Phaser.Physics.Advanced.Shapes.Circle, seg: Phaser.Physics.Advanced.Shapes.Segment, contactArr: Contact[]) {
- var rsum = circ.radius + seg.r;
+ var rsum = circ.radius + seg.radius;
// Normal distance from segment
var dn = Phaser.Vec2Utils.dot(circ.tc, seg.tn) - Phaser.Vec2Utils.dot(seg.ta, seg.tn);
@@ -142,19 +142,20 @@ module Phaser.Physics.Advanced {
return 0;
}
- return this._circle2Circle(circ.tc, circ.radius, seg.ta, seg.r, contactArr);
+ return this._circle2Circle(circ.tc, circ.radius, seg.ta, seg.radius, contactArr);
}
else if (dt > dtMax)
- {
+ {
if (dt > dtMax + rsum)
{
return 0;
}
- return this._circle2Circle(circ.tc, circ.radius, seg.tb, seg.r, contactArr);
+ return this._circle2Circle(circ.tc, circ.radius, seg.tb, seg.radius, contactArr);
}
var n: Phaser.Vec2 = new Phaser.Vec2;
+
if (dn > 0)
{
n.copyFrom(seg.tn);
@@ -178,7 +179,7 @@ module Phaser.Physics.Advanced {
}
- public circle2Poly(circ: ShapeCircle, poly, contactArr: Contact[]) {
+ public circle2Poly(circ: Phaser.Physics.Advanced.Shapes.Circle, poly: Phaser.Physics.Advanced.Shapes.Poly, contactArr: Contact[]) {
var minDist = -999999;
var minIdx = -1;
@@ -229,7 +230,7 @@ module Phaser.Physics.Advanced {
}
- public segmentPointDistanceSq(seg, p) {
+ public segmentPointDistanceSq(seg: Phaser.Physics.Advanced.Shapes.Segment, p) {
var w: Phaser.Vec2 = new Phaser.Vec2;
var d: Phaser.Vec2 = new Phaser.Vec2;
@@ -258,7 +259,7 @@ module Phaser.Physics.Advanced {
}
// FIXME and optimise me lots!!!
- public segment2Segment(seg1, seg2, contactArr) {
+ public segment2Segment(seg1: Phaser.Physics.Advanced.Shapes.Segment, seg2: Phaser.Physics.Advanced.Shapes.Segment, contactArr: Contact[]) {
var d = [];
d[0] = this.segmentPointDistanceSq(seg1, seg2.ta);
@@ -301,12 +302,12 @@ module Phaser.Physics.Advanced {
var minp1 = Phaser.Vec2Utils.multiplyAdd(seg1.ta, u, s);
var minp2 = Phaser.Vec2Utils.multiplyAdd(seg2.ta, v, t);
- return this._circle2Circle(minp1, seg1.r, minp2, seg2.r, contactArr);
+ return this._circle2Circle(minp1, seg1.radius, minp2, seg2.radius, contactArr);
}
// Identify vertexes that have penetrated the segment.
- public findPointsBehindSeg(contactArr, seg, poly, dist, coef) {
+ public findPointsBehindSeg(contactArr: Contact[], seg: Phaser.Physics.Advanced.Shapes.Segment, poly: Phaser.Physics.Advanced.Shapes.Poly, dist: number, coef: number) {
var dta = Phaser.Vec2Utils.cross(seg.tn, seg.ta);
var dtb = Phaser.Vec2Utils.cross(seg.tn, seg.tb);
@@ -319,7 +320,7 @@ module Phaser.Physics.Advanced {
{
var v = poly.tverts[i];
- if (Phaser.Vec2Utils.dot(v, n) < Phaser.Vec2Utils.dot(seg.tn, seg.ta) * coef + seg.r)
+ if (Phaser.Vec2Utils.dot(v, n) < Phaser.Vec2Utils.dot(seg.tn, seg.ta) * coef + seg.radius)
{
var dt = Phaser.Vec2Utils.cross(seg.tn, v);
@@ -331,9 +332,11 @@ module Phaser.Physics.Advanced {
}
}
- public segment2Poly(seg, poly, contactArr) {
+ public segment2Poly(seg: Phaser.Physics.Advanced.Shapes.Segment, poly: Phaser.Physics.Advanced.Shapes.Poly, contactArr: Contact[]) {
+
var seg_td = Phaser.Vec2Utils.dot(seg.tn, seg.ta);
- var seg_d1 = poly.distanceOnPlane(seg.tn, seg_td) - seg.r;
+ var seg_d1 = poly.distanceOnPlane(seg.tn, seg_td) - seg.radius;
+
if (seg_d1 > 0)
{
return 0;
@@ -341,7 +344,7 @@ module Phaser.Physics.Advanced {
var n: Phaser.Vec2 = new Phaser.Vec2;
Phaser.Vec2Utils.negative(seg.tn, n);
- var seg_d2 = poly.distanceOnPlane(n, -seg_td) - seg.r;
+ var seg_d2 = poly.distanceOnPlane(n, -seg_td) - seg.radius;
//var seg_d2 = poly.distanceOnPlane(vec2.neg(seg.tn), -seg_td) - seg.r;
if (seg_d2 > 0)
@@ -374,11 +377,11 @@ module Phaser.Physics.Advanced {
//var poly_n = vec2.neg(poly.tplanes[poly_i].n);
var va: Phaser.Vec2 = new Phaser.Vec2;
- Phaser.Vec2Utils.multiplyAdd(seg.ta, poly_n, seg.r, va);
+ Phaser.Vec2Utils.multiplyAdd(seg.ta, poly_n, seg.radius, va);
//var va = vec2.mad(seg.ta, poly_n, seg.r);
var vb: Phaser.Vec2 = new Phaser.Vec2;
- Phaser.Vec2Utils.multiplyAdd(seg.tb, poly_n, seg.r, vb);
+ Phaser.Vec2Utils.multiplyAdd(seg.tb, poly_n, seg.radius, vb);
//var vb = vec2.mad(seg.tb, poly_n, seg.r);
if (poly.containPoint(va))
@@ -412,22 +415,22 @@ module Phaser.Physics.Advanced {
var poly_a = poly.tverts[poly_i];
var poly_b = poly.tverts[(poly_i + 1) % poly.verts.length];
- if (this._circle2Circle(seg.ta, seg.r, poly_a, 0, contactArr))
+ if (this._circle2Circle(seg.ta, seg.radius, poly_a, 0, contactArr))
{
return 1;
}
- if (this._circle2Circle(seg.tb, seg.r, poly_a, 0, contactArr))
+ if (this._circle2Circle(seg.tb, seg.radius, poly_a, 0, contactArr))
{
return 1;
}
- if (this._circle2Circle(seg.ta, seg.r, poly_b, 0, contactArr))
+ if (this._circle2Circle(seg.ta, seg.radius, poly_b, 0, contactArr))
{
return 1;
}
- if (this._circle2Circle(seg.tb, seg.r, poly_b, 0, contactArr))
+ if (this._circle2Circle(seg.tb, seg.radius, poly_b, 0, contactArr))
{
return 1;
}
@@ -438,7 +441,7 @@ module Phaser.Physics.Advanced {
}
// Find the minimum separating axis for the given poly and plane list.
- public findMSA(poly, planes, num) {
+ public findMSA(poly: Phaser.Physics.Advanced.Shapes.Poly, planes, num: number) {
var min_dist = -999999;
var min_index = -1;
@@ -446,8 +449,10 @@ module Phaser.Physics.Advanced {
for (var i = 0; i < num; i++)
{
var dist = poly.distanceOnPlane(planes[i].n, planes[i].d);
+
if (dist > 0)
- { // no collision
+ {
+ // no collision
return { dist: 0, index: -1 };
}
else if (dist > min_dist)
@@ -462,7 +467,7 @@ module Phaser.Physics.Advanced {
}
- public findVertsFallback(contactArr, poly1, poly2, n, dist) {
+ public findVertsFallback(contactArr: Contact[], poly1: Phaser.Physics.Advanced.Shapes.Poly, poly2: Phaser.Physics.Advanced.Shapes.Poly, n, dist: number) {
var num = 0;
@@ -493,7 +498,7 @@ module Phaser.Physics.Advanced {
}
// Find the overlapped vertices.
- public findVerts(contactArr, poly1, poly2, n, dist) {
+ public findVerts(contactArr: Contact[], poly1: Phaser.Physics.Advanced.Shapes.Poly, poly2: Phaser.Physics.Advanced.Shapes.Poly, n, dist: number) {
var num = 0;
@@ -523,7 +528,7 @@ module Phaser.Physics.Advanced {
}
- public poly2Poly(poly1, poly2, contactArr) {
+ public poly2Poly(poly1: Phaser.Physics.Advanced.Shapes.Poly, poly2: Phaser.Physics.Advanced.Shapes.Poly, contactArr: Contact[]) {
var msa1 = this.findMSA(poly2, poly1.tplanes, poly1.verts.length);
diff --git a/Phaser/physics/advanced/Contact.ts b/Phaser/physics/advanced/Contact.ts
index bf3855316..d927764bf 100644
--- a/Phaser/physics/advanced/Contact.ts
+++ b/Phaser/physics/advanced/Contact.ts
@@ -1,5 +1,4 @@
///
-///
///
///
///
@@ -33,29 +32,29 @@ module Phaser.Physics.Advanced {
public hash;
- // Linear velocities at contact point
+ // Linear velocities at contact point
public r1: Phaser.Vec2;
public r2: Phaser.Vec2;
public r1_local: Phaser.Vec2;
public r2_local: Phaser.Vec2;
- // Bounce velocity
- public bounce;
- public emn;
- public emt;
+ // Bounce velocity
+ public bounce: number;
+ public emn: number;
+ public emt: number;
- // Contact point
+ // Contact point
public point;
// Contact normal (toward shape2)
public normal: Phaser.Vec2;
- // Penetration depth (d < 0)
+ // Penetration depth (d < 0)
public depth;
- // Accumulated normal constraint impulse
+ // Accumulated normal constraint impulse
public lambdaNormal;
- // Accumulated tangential constraint impulse
+ // Accumulated tangential constraint impulse
public lambdaTangential;
}
diff --git a/Phaser/physics/advanced/ShapeBox.ts b/Phaser/physics/advanced/ShapeBox.ts
deleted file mode 100644
index 6121b1f05..000000000
--- a/Phaser/physics/advanced/ShapeBox.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-///
-///
-///
-///
-///
-///
-///
-
-/**
-* Phaser - Advanced Physics - ShapeBox
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-
-module Phaser.Physics.Advanced {
-
- export class ShapeBox extends Phaser.Physics.Advanced.ShapePoly {
-
- // Give in pixels
- constructor(x, y, width, height) {
-
- console.log('creating box', x, y, width, height);
-
- x = Manager.pixelsToMeters(x);
- y = Manager.pixelsToMeters(y);
- width = Manager.pixelsToMeters(width);
- height = Manager.pixelsToMeters(height);
-
- var hw = width * 0.5;
- var hh = height * 0.5;
-
- super([
- new Phaser.Vec2(-hw + x, +hh + y),
- new Phaser.Vec2(-hw + x, -hh + y),
- new Phaser.Vec2(+hw + x, -hh + y),
- new Phaser.Vec2(+hw + x, +hh + y)
- ]);
-
- }
-
- }
-
-}
diff --git a/Phaser/physics/advanced/ShapeCircle.ts b/Phaser/physics/advanced/ShapeCircle.ts
deleted file mode 100644
index e9a8a25b2..000000000
--- a/Phaser/physics/advanced/ShapeCircle.ts
+++ /dev/null
@@ -1,102 +0,0 @@
-///
-///
-///
-///
-///
-///
-
-/**
-* Phaser - Advanced Physics - Shape
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-
-module Phaser.Physics.Advanced {
-
- export class ShapeCircle extends Phaser.Physics.Advanced.Shape implements IShape {
-
- constructor(radius: number, x?: number = 0, y?: number = 0) {
-
- super(Manager.SHAPE_TYPE_CIRCLE);
-
- this.center = new Phaser.Vec2(x, y);
- this.radius = radius;
- this.tc = new Phaser.Vec2;
-
- this.finishVerts();
-
- }
-
- public radius: number;
- public center: Phaser.Vec2;
- public tc: Phaser.Vec2;
-
- public finishVerts() {
- this.radius = Math.abs(this.radius);
- }
-
- public duplicate() {
- return new ShapeCircle(this.center.x, this.center.y, this.radius);
- }
-
- public recenter(c:Phaser.Vec2) {
- this.center.subtract(c);
- }
-
- public transform(xf: Transform) {
-
- Phaser.TransformUtils.transform(xf, this.center, this.center);
- //this.center = xf.transform(this.center);
- }
-
- public untransform(xf: Transform) {
- Phaser.TransformUtils.untransform(xf, this.center, this.center);
- //this.center = xf.untransform(this.center);
- }
-
- public area(): number {
- return Manager.areaForCircle(this.radius, 0);
- }
-
- public centroid(): Phaser.Vec2 {
- return Phaser.Vec2Utils.clone(this.center);
- }
-
- public inertia(mass: number): number {
- return Manager.inertiaForCircle(mass, this.center, this.radius, 0);
- }
-
- public cacheData(xf: Transform) {
-
- Phaser.TransformUtils.transform(xf, this.center, this.tc);
- //this.tc = xf.transform(this.center);
-
- this.bounds.mins.setTo(this.tc.x - this.radius, this.tc.y - this.radius);
- this.bounds.maxs.setTo(this.tc.x + this.radius, this.tc.y + this.radius);
-
- }
-
- public pointQuery(p:Phaser.Vec2): bool {
- //return vec2.distsq(this.tc, p) < (this.r * this.r);
- return Phaser.Vec2Utils.distanceSq(this.tc, p) < (this.radius * this.radius);
- }
-
- public findVertexByPoint(p:Phaser.Vec2, minDist: number): number {
-
- var dsq = minDist * minDist;
-
- if (Phaser.Vec2Utils.distanceSq(this.tc, p) < dsq)
- {
- return 0;
- }
-
- return -1;
- }
-
- public distanceOnPlane(n, d) {
- Phaser.Vec2Utils.dot(n, this.tc) - this.radius - d;
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/Phaser/physics/advanced/ShapePoly.ts b/Phaser/physics/advanced/ShapePoly.ts
deleted file mode 100644
index c77d12963..000000000
--- a/Phaser/physics/advanced/ShapePoly.ts
+++ /dev/null
@@ -1,303 +0,0 @@
-///
-///
-///
-///
-///
-///
-
-/**
-* Phaser - Advanced Physics - ShapePoly (convex only)
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-
-module Phaser.Physics.Advanced {
-
- export class ShapePoly extends Phaser.Physics.Advanced.Shape implements IShape {
-
- constructor(verts?:Phaser.Vec2[]) {
-
- console.log('ShapePoly created', verts);
-
- super(Manager.SHAPE_TYPE_POLY);
-
- this.verts = [];
- this.planes = [];
-
- this.tverts = [];
- this.tplanes = [];
-
- if (verts)
- {
- for (var i = 0; i < verts.length; i++)
- {
- //console.log('cloning vert', i);
- this.verts[i] = Phaser.Vec2Utils.clone(verts[i]);
- this.tverts[i] = this.verts[i];
-
- this.tplanes[i] = {};
- this.tplanes[i].n = new Phaser.Vec2;
- this.tplanes[i].d = 0;
- }
- }
-
- //console.log('ShapePoly finished', this.verts);
-
- this.finishVerts();
-
- //console.log('ShapePoly finished 2', this.verts);
-
- }
-
- public verts: Phaser.Vec2[];
- public planes;
-
- public tverts;
- public tplanes;
-
- public convexity: bool;
-
- public finishVerts() {
-
- if (this.verts.length < 2)
- {
- this.convexity = false;
- this.planes = [];
- return;
- }
-
- this.convexity = true;
- this.tverts = [];
- this.tplanes = [];
-
- // Must be counter-clockwise verts
- for (var i = 0; i < this.verts.length; i++)
- {
- var a = this.verts[i];
- var b = this.verts[(i + 1) % this.verts.length];
- var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
-
- this.planes[i] = {};
- this.planes[i].n = n;
- this.planes[i].d = Phaser.Vec2Utils.dot(n, a);
-
- this.tverts[i] = this.verts[i];
-
- this.tplanes[i] = {};
- this.tplanes[i].n = new Phaser.Vec2;
- this.tplanes[i].d = 0;
- }
-
- for (var i = 0; i < this.verts.length; i++)
- {
- var b = this.verts[(i + 2) % this.verts.length];
- var n = this.planes[i].n;
- var d = this.planes[i].d;
-
- if (Phaser.Vec2Utils.dot(n, b) - d > 0)
- {
- this.convexity = false;
- }
- }
- }
-
- public duplicate() {
- return new ShapePoly(this.verts);
- }
-
- public recenter(c) {
-
- for (var i = 0; i < this.verts.length; i++)
- {
- this.verts[i].subtract(c);
- }
-
- }
-
- public transform(xf) {
- for (var i = 0; i < this.verts.length; i++)
- {
- this.verts[i] = xf.transform(this.verts[i]);
- }
- }
-
- public untransform(xf) {
- for (var i = 0; i < this.verts.length; i++)
- {
- this.verts[i] = xf.untransform(this.verts[i]);
- }
- }
-
- public area(): number {
- return Manager.areaForPoly(this.verts);
- }
-
- public centroid(): Phaser.Vec2 {
- return Manager.centroidForPoly(this.verts);
- }
-
- public inertia(mass: number): number {
- return Manager.inertiaForPoly(mass, this.verts, new Phaser.Vec2);
- }
-
- public cacheData(xf:Transform) {
-
- this.bounds.clear();
-
- var numVerts = this.verts.length;
-
- //console.log('shapePoly cacheData', numVerts);
-
- if (numVerts == 0)
- {
- return;
- }
-
- for (var i = 0; i < numVerts; i++)
- {
- Phaser.TransformUtils.transform(xf, this.tverts[i], this.tverts[i]);
- //this.tverts[i] = xf.transform(this.verts[i]);
- }
-
- if (numVerts < 2)
- {
- this.bounds.addPoint(this.tverts[0]);
- return;
- }
-
- for (var i = 0; i < numVerts; i++)
- {
- var a = this.tverts[i];
- var b = this.tverts[(i + 1) % numVerts];
-
- var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
-
- this.tplanes[i].n = n;
- this.tplanes[i].d = Phaser.Vec2Utils.dot(n, a);
-
- this.bounds.addPoint(a);
- }
-
- }
-
- public pointQuery(p: Phaser.Vec2): bool {
-
- if (!this.bounds.containPoint(p))
- {
- return false;
- }
-
- return this.containPoint(p);
- }
-
- public findVertexByPoint(p:Phaser.Vec2, minDist: number): number {
-
- var dsq = minDist * minDist;
-
- for (var i = 0; i < this.tverts.length; i++)
- {
- if (Phaser.Vec2Utils.distanceSq(this.tverts[i], p) < dsq)
- {
- return i;
- }
- }
-
- return -1;
- }
-
- public findEdgeByPoint(p: Phaser.Vec2, minDist: number): number {
-
- var dsq = minDist * minDist;
- var numVerts = this.tverts.length;
-
- for (var i = 0; i < this.tverts.length; i++)
- {
- var v1 = this.tverts[i];
- var v2 = this.tverts[(i + 1) % numVerts];
- var n = this.tplanes[i].n;
-
- var dtv1 = Phaser.Vec2Utils.cross(v1, n);
- var dtv2 = Phaser.Vec2Utils.cross(v2, n);
- var dt = Phaser.Vec2Utils.cross(p, n);
-
- if (dt > dtv1)
- {
- if (Phaser.Vec2Utils.distanceSq(v1, p) < dsq)
- {
- return i;
- }
- }
- else if (dt < dtv2)
- {
- if (Phaser.Vec2Utils.distanceSq(v2, p) < dsq)
- {
- return i;
- }
- }
- else
- {
- var dist = Phaser.Vec2Utils.dot(n, p) - Phaser.Vec2Utils.dot(n, v1);
-
- if (dist * dist < dsq)
- {
- return i;
- }
- }
- }
-
- return -1;
-
- }
-
- public distanceOnPlane(n, d) {
-
- var min = 999999;
-
- for (var i = 0; i < this.verts.length; i++)
- {
- min = Math.min(min, Phaser.Vec2Utils.dot(n, this.tverts[i]));
- }
-
- return min - d;
-
- }
-
- public containPoint(p) {
-
- for (var i = 0; i < this.verts.length; i++)
- {
- var plane = this.tplanes[i];
-
- if (Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0)
- {
- return false;
- }
- }
-
- return true;
-
- }
-
- public containPointPartial(p, n) {
-
- for (var i = 0; i < this.verts.length; i++)
- {
- var plane = this.tplanes[i];
-
- if (Phaser.Vec2Utils.dot(plane.n, n) < 0.0001)
- {
- continue;
- }
-
- if (Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0)
- {
- return false;
- }
- }
-
- return true;
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/Phaser/physics/advanced/ShapeSegment.ts b/Phaser/physics/advanced/ShapeSegment.ts
deleted file mode 100644
index 02adde372..000000000
--- a/Phaser/physics/advanced/ShapeSegment.ts
+++ /dev/null
@@ -1,206 +0,0 @@
-///
-///
-///
-///
-///
-///
-
-/**
-* Phaser - Advanced Physics - Shape
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-
-module Phaser.Physics.Advanced {
-
- export class ShapeSegment extends Phaser.Physics.Advanced.Shape implements IShape {
-
- constructor(a, b, radius: number) {
-
- super(Manager.SHAPE_TYPE_SEGMENT);
-
- // What types are A and B??!
- this.a = a.duplicate();
- this.b = b.duplicate();
- this.radius = radius;
-
- this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(b, a));
- this.normal.normalize();
-
- this.ta = new Phaser.Vec2;
- this.tb = new Phaser.Vec2;
- this.tn = new Phaser.Vec2;
-
- this.finishVerts();
-
- }
-
- public a: Phaser.Vec2;
- public b: Phaser.Vec2;
- public radius: number;
-
- public normal: Phaser.Vec2;
- public ta: Phaser.Vec2;
- public tb: Phaser.Vec2;
- public tn: Phaser.Vec2;
-
- public finishVerts() {
-
- this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.b, this.a));
- this.normal.normalize();
-
- this.radius = Math.abs(this.radius);
-
- }
-
- public duplicate() {
- return new ShapeSegment(this.a, this.b, this.radius);
- }
-
- public recenter(c) {
- this.a.subtract(c);
- this.b.subtract(c);
- }
-
- public transform(xf:Transform) {
-
- Phaser.TransformUtils.transform(xf, this.a, this.a);
- Phaser.TransformUtils.transform(xf, this.b, this.b);
-
- //this.a = xf.transform(this.a);
- //this.b = xf.transform(this.b);
-
- }
-
- public untransform(xf:Transform) {
-
- Phaser.TransformUtils.untransform(xf, this.a, this.a);
- Phaser.TransformUtils.untransform(xf, this.b, this.b);
-
- //this.a = xf.untransform(this.a);
- //this.b = xf.untransform(this.b);
-
- }
-
- public area(): number {
- return Manager.areaForSegment(this.a, this.b, this.radius);
- }
-
- public centroid(): Phaser.Vec2 {
- return Manager.centroidForSegment(this.a, this.b);
- }
-
- public inertia(mass: number): number {
- return Manager.inertiaForSegment(mass, this.a, this.b);
- }
-
- public cacheData(xf:Transform) {
-
- Phaser.TransformUtils.transform(xf, this.a, this.ta);
- Phaser.TransformUtils.transform(xf, this.b, this.tb);
-
- //this.ta = xf.transform(this.a);
- //this.tb = xf.transform(this.b);
-
- this.tn = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.tb, this.ta)).normalize();
-
- var l;
- var r;
- var t;
- var b;
-
- if (this.ta.x < this.tb.x)
- {
- l = this.ta.x;
- r = this.tb.x;
- }
- else
- {
- l = this.tb.x;
- r = this.ta.x;
- }
-
- if (this.ta.y < this.tb.y)
- {
- b = this.ta.y;
- t = this.tb.y;
- } else
- {
- b = this.tb.y;
- t = this.ta.y;
- }
-
- this.bounds.mins.setTo(l - this.radius, b - this.radius);
- this.bounds.maxs.setTo(r + this.radius, t + this.radius);
-
- }
-
- public pointQuery(p: Phaser.Vec2): bool {
-
- if (!this.bounds.containPoint(p))
- {
- return false;
- }
-
- var dn = Phaser.Vec2Utils.dot(this.tn, p) - Phaser.Vec2Utils.dot(this.ta, this.tn);
- var dist = Math.abs(dn);
-
- if (dist > this.radius)
- {
- return false;
- }
-
- var dt = Phaser.Vec2Utils.cross(p, this.tn);
- var dta = Phaser.Vec2Utils.cross(this.ta, this.tn);
- var dtb = Phaser.Vec2Utils.cross(this.tb, this.tn);
-
- if (dt <= dta)
- {
- if (dt < dta - this.radius)
- {
- return false;
- }
-
- return Phaser.Vec2Utils.distanceSq(this.ta, p) < (this.radius * this.radius);
- }
- else if (dt > dtb)
- {
- if (dt > dtb + this.radius)
- {
- return false;
- }
-
- return Phaser.Vec2Utils.distanceSq(this.tb, p) < (this.radius * this.radius);
- }
-
- return true;
- }
-
- public findVertexByPoint(p:Phaser.Vec2, minDist: number): number {
-
- var dsq = minDist * minDist;
-
- if (Phaser.Vec2Utils.distanceSq(this.ta, p) < dsq)
- {
- return 0;
- }
-
- if (Phaser.Vec2Utils.distanceSq(this.tb, p) < dsq)
- {
- return 1;
- }
-
- return -1;
- }
-
- public distanceOnPlane(n, d) {
-
- var a = Phaser.Vec2Utils.dot(n, this.ta) - this.radius;
- var b = Phaser.Vec2Utils.dot(n, this.tb) - this.radius;
-
- return Math.min(a, b) - d;
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/Phaser/physics/advanced/ShapeTriangle.ts b/Phaser/physics/advanced/ShapeTriangle.ts
deleted file mode 100644
index 769c40849..000000000
--- a/Phaser/physics/advanced/ShapeTriangle.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-///
-///
-///
-///
-///
-///
-///
-
-/**
-* Phaser - Advanced Physics - ShapeTriangle
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-
-module Phaser.Physics.Advanced {
-
- export class ShapeTriangle extends Phaser.Physics.Advanced.ShapePoly {
-
- constructor(p1, p2, p3) {
-
- super( [ new Phaser.Vec2(p1.x, p1.y), new Phaser.Vec2(p2.x, p2.y), new Phaser.Vec2(p3.x, p3.y) ] );
-
- }
-
- }
-
-}
diff --git a/Phaser/physics/advanced/Space.ts b/Phaser/physics/advanced/Space.ts
index cafd97982..52e09a5c1 100644
--- a/Phaser/physics/advanced/Space.ts
+++ b/Phaser/physics/advanced/Space.ts
@@ -1,5 +1,4 @@
///
-///
///
///
///
diff --git a/Phaser/physics/advanced/shapes/Box.ts b/Phaser/physics/advanced/shapes/Box.ts
index c9ade9b1f..3159e3173 100644
--- a/Phaser/physics/advanced/shapes/Box.ts
+++ b/Phaser/physics/advanced/shapes/Box.ts
@@ -2,7 +2,7 @@
///
///
///
-///
+///
/**
* Phaser - Advanced Physics - Shapes - Box
@@ -12,7 +12,7 @@
module Phaser.Physics.Advanced.Shapes {
- export class Box extends Phaser.Physics.Advanced.ShapePoly {
+ export class Box extends Phaser.Physics.Advanced.Shapes.Poly {
// Give in pixels
constructor(x, y, width, height) {
diff --git a/Phaser/physics/advanced/shapes/Circle.ts b/Phaser/physics/advanced/shapes/Circle.ts
index 408c60b1a..6911f1186 100644
--- a/Phaser/physics/advanced/shapes/Circle.ts
+++ b/Phaser/physics/advanced/shapes/Circle.ts
@@ -34,8 +34,8 @@ module Phaser.Physics.Advanced.Shapes {
this.radius = Math.abs(this.radius);
}
- public duplicate() {
- return new ShapeCircle(this.center.x, this.center.y, this.radius);
+ public duplicate(): Circle {
+ return new Circle(this.center.x, this.center.y, this.radius);
}
public recenter(c:Phaser.Vec2) {
diff --git a/Phaser/physics/advanced/shapes/Poly.ts b/Phaser/physics/advanced/shapes/Poly.ts
index fb40b49fe..f4d506994 100644
--- a/Phaser/physics/advanced/shapes/Poly.ts
+++ b/Phaser/physics/advanced/shapes/Poly.ts
@@ -94,7 +94,7 @@ module Phaser.Physics.Advanced.Shapes {
}
public duplicate() {
- return new ShapePoly(this.verts);
+ return new Phaser.Physics.Advanced.Shapes.Poly(this.verts);
}
public recenter(c) {
diff --git a/Phaser/physics/advanced/shapes/Segment.ts b/Phaser/physics/advanced/shapes/Segment.ts
index 82922742b..51ebc4701 100644
--- a/Phaser/physics/advanced/shapes/Segment.ts
+++ b/Phaser/physics/advanced/shapes/Segment.ts
@@ -18,7 +18,6 @@ module Phaser.Physics.Advanced.Shapes {
super(Manager.SHAPE_TYPE_SEGMENT);
- // What types are A and B??!
this.a = a.duplicate();
this.b = b.duplicate();
this.radius = radius;
@@ -53,7 +52,7 @@ module Phaser.Physics.Advanced.Shapes {
}
public duplicate() {
- return new ShapeSegment(this.a, this.b, this.radius);
+ return new Phaser.Physics.Advanced.Shapes.Segment(this.a, this.b, this.radius);
}
public recenter(c) {
diff --git a/Phaser/physics/advanced/shapes/Shape.ts b/Phaser/physics/advanced/shapes/Shape.ts
index 7f2e60a1b..e1260c885 100644
--- a/Phaser/physics/advanced/shapes/Shape.ts
+++ b/Phaser/physics/advanced/shapes/Shape.ts
@@ -1,5 +1,4 @@
///
-///
///
///
///
diff --git a/Phaser/physics/advanced/shapes/Triangle.ts b/Phaser/physics/advanced/shapes/Triangle.ts
index 0ee3c16f6..90147ca85 100644
--- a/Phaser/physics/advanced/shapes/Triangle.ts
+++ b/Phaser/physics/advanced/shapes/Triangle.ts
@@ -1,4 +1,4 @@
-///
+///
///
///
///
@@ -10,9 +10,9 @@
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
-module Phaser.Physics.Advanced {
+module Phaser.Physics.Advanced.Shapes {
- export class ShapeTriangle extends Phaser.Physics.Advanced.Shapes.Poly {
+ export class Triangle extends Phaser.Physics.Advanced.Shapes.Poly {
constructor(p1, p2, p3) {
diff --git a/README.md b/README.md
index fdda3a1d4..6d5fe091b 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,8 @@ TODO:
* Move all of the renderDebugInfo methods to the DebugUtils class
* Check bounds/edge points when sprite is only 1x1 sized :)
+* See what I can move out of Body and into a BodyUtils class.
+* See about optimising Advanced Physics a lot more, so it doesn't create lots of Vec2s everywhere.
V1.0.0
@@ -114,7 +116,7 @@ V1.0.0
* Added SpriteUtils.overlapsXY and overlapsPoint to check if a point is within a sprite, taking scale and rotation into account.
* Added Cache.getImageKeys (and similar) to return an array of all the keys for all currently cached objects.
* Added Group.bringToTop feature. Will sort the Group, move the given sprites z-index to the top and shift the rest down by one.
-
+* Brand new Advanced Physics system added and working! Woohoo :)
diff --git a/Tests/phaser.js b/Tests/phaser.js
index 0378d4db3..0f9b2dab0 100644
--- a/Tests/phaser.js
+++ b/Tests/phaser.js
@@ -19075,11 +19075,11 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (Physics) {
- ///
- ///
- ///
- ///
- ///
+ ///
+ ///
+ ///
+ ///
+ ///
/**
* Phaser - Advanced Physics - Joint
*
@@ -19121,7 +19121,7 @@ var Phaser;
(function (Physics) {
///
///
- ///
+ ///
/**
* Phaser - Advanced Physics Manager
*
@@ -19503,12 +19503,11 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
+ ///
+ ///
+ ///
+ ///
+ ///
///
/**
* Phaser - Advanced Physics - Shape
@@ -19541,11 +19540,10 @@ var Phaser;
(function (Phaser) {
(function (Physics) {
///
- ///
///
///
///
- ///
+ ///
/**
* Phaser - Advanced Physics - Contact
*
@@ -19581,7 +19579,7 @@ var Phaser;
///
///
///
- ///
+ ///
///
/**
* Phaser - Advanced Physics - ContactSolver
@@ -19829,78 +19827,418 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - Shape
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
(function (Advanced) {
- var ShapeCircle = (function (_super) {
- __extends(ShapeCircle, _super);
- function ShapeCircle(radius, x, y) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- _super.call(this, Advanced.Manager.SHAPE_TYPE_CIRCLE);
- this.center = new Phaser.Vec2(x, y);
- this.radius = radius;
- this.tc = new Phaser.Vec2();
- this.finishVerts();
- }
- ShapeCircle.prototype.finishVerts = function () {
- this.radius = Math.abs(this.radius);
- };
- ShapeCircle.prototype.duplicate = function () {
- return new ShapeCircle(this.center.x, this.center.y, this.radius);
- };
- ShapeCircle.prototype.recenter = function (c) {
- this.center.subtract(c);
- };
- ShapeCircle.prototype.transform = function (xf) {
- Phaser.TransformUtils.transform(xf, this.center, this.center);
- //this.center = xf.transform(this.center);
- };
- ShapeCircle.prototype.untransform = function (xf) {
- Phaser.TransformUtils.untransform(xf, this.center, this.center);
- //this.center = xf.untransform(this.center);
- };
- ShapeCircle.prototype.area = function () {
- return Advanced.Manager.areaForCircle(this.radius, 0);
- };
- ShapeCircle.prototype.centroid = function () {
- return Phaser.Vec2Utils.clone(this.center);
- };
- ShapeCircle.prototype.inertia = function (mass) {
- return Advanced.Manager.inertiaForCircle(mass, this.center, this.radius, 0);
- };
- ShapeCircle.prototype.cacheData = function (xf) {
- Phaser.TransformUtils.transform(xf, this.center, this.tc);
- //this.tc = xf.transform(this.center);
- this.bounds.mins.setTo(this.tc.x - this.radius, this.tc.y - this.radius);
- this.bounds.maxs.setTo(this.tc.x + this.radius, this.tc.y + this.radius);
- };
- ShapeCircle.prototype.pointQuery = function (p) {
- //return vec2.distsq(this.tc, p) < (this.r * this.r);
- return Phaser.Vec2Utils.distanceSq(this.tc, p) < (this.radius * this.radius);
- };
- ShapeCircle.prototype.findVertexByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- if(Phaser.Vec2Utils.distanceSq(this.tc, p) < dsq) {
- return 0;
+ ///
+ ///
+ ///
+ ///
+ ///
+ /**
+ * Phaser - Advanced Physics - Shape - Circle
+ *
+ * Based on the work Ju Hyung Lee started in JS PhyRus.
+ */
+ (function (Shapes) {
+ var Circle = (function (_super) {
+ __extends(Circle, _super);
+ function Circle(radius, x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ _super.call(this, Advanced.Manager.SHAPE_TYPE_CIRCLE);
+ this.center = new Phaser.Vec2(x, y);
+ this.radius = radius;
+ this.tc = new Phaser.Vec2();
+ this.finishVerts();
}
- return -1;
- };
- ShapeCircle.prototype.distanceOnPlane = function (n, d) {
- Phaser.Vec2Utils.dot(n, this.tc) - this.radius - d;
- };
- return ShapeCircle;
- })(Phaser.Physics.Advanced.Shape);
- Advanced.ShapeCircle = ShapeCircle;
+ Circle.prototype.finishVerts = function () {
+ this.radius = Math.abs(this.radius);
+ };
+ Circle.prototype.duplicate = function () {
+ return new Circle(this.center.x, this.center.y, this.radius);
+ };
+ Circle.prototype.recenter = function (c) {
+ this.center.subtract(c);
+ };
+ Circle.prototype.transform = function (xf) {
+ Phaser.TransformUtils.transform(xf, this.center, this.center);
+ //this.center = xf.transform(this.center);
+ };
+ Circle.prototype.untransform = function (xf) {
+ Phaser.TransformUtils.untransform(xf, this.center, this.center);
+ //this.center = xf.untransform(this.center);
+ };
+ Circle.prototype.area = function () {
+ return Advanced.Manager.areaForCircle(this.radius, 0);
+ };
+ Circle.prototype.centroid = function () {
+ return Phaser.Vec2Utils.clone(this.center);
+ };
+ Circle.prototype.inertia = function (mass) {
+ return Advanced.Manager.inertiaForCircle(mass, this.center, this.radius, 0);
+ };
+ Circle.prototype.cacheData = function (xf) {
+ Phaser.TransformUtils.transform(xf, this.center, this.tc);
+ //this.tc = xf.transform(this.center);
+ this.bounds.mins.setTo(this.tc.x - this.radius, this.tc.y - this.radius);
+ this.bounds.maxs.setTo(this.tc.x + this.radius, this.tc.y + this.radius);
+ };
+ Circle.prototype.pointQuery = function (p) {
+ //return vec2.distsq(this.tc, p) < (this.r * this.r);
+ return Phaser.Vec2Utils.distanceSq(this.tc, p) < (this.radius * this.radius);
+ };
+ Circle.prototype.findVertexByPoint = function (p, minDist) {
+ var dsq = minDist * minDist;
+ if(Phaser.Vec2Utils.distanceSq(this.tc, p) < dsq) {
+ return 0;
+ }
+ return -1;
+ };
+ Circle.prototype.distanceOnPlane = function (n, d) {
+ Phaser.Vec2Utils.dot(n, this.tc) - this.radius - d;
+ };
+ return Circle;
+ })(Phaser.Physics.Advanced.Shape);
+ Shapes.Circle = Circle;
+ })(Advanced.Shapes || (Advanced.Shapes = {}));
+ var Shapes = Advanced.Shapes;
+ })(Physics.Advanced || (Physics.Advanced = {}));
+ var Advanced = Physics.Advanced;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Advanced) {
+ ///
+ ///
+ ///
+ ///
+ ///
+ /**
+ * Phaser - Advanced Physics - Shapes - Convex Polygon
+ *
+ * Based on the work Ju Hyung Lee started in JS PhyRus.
+ */
+ (function (Shapes) {
+ var Poly = (function (_super) {
+ __extends(Poly, _super);
+ function Poly(verts) {
+ _super.call(this, Advanced.Manager.SHAPE_TYPE_POLY);
+ this.verts = [];
+ this.planes = [];
+ this.tverts = [];
+ this.tplanes = [];
+ if(verts) {
+ for(var i = 0; i < verts.length; i++) {
+ this.verts[i] = Phaser.Vec2Utils.clone(verts[i]);
+ this.tverts[i] = this.verts[i];
+ this.tplanes[i] = {
+ };
+ this.tplanes[i].n = new Phaser.Vec2();
+ this.tplanes[i].d = 0;
+ }
+ }
+ this.finishVerts();
+ }
+ Poly.prototype.finishVerts = function () {
+ if(this.verts.length < 2) {
+ this.convexity = false;
+ this.planes = [];
+ return;
+ }
+ this.convexity = true;
+ this.tverts = [];
+ this.tplanes = [];
+ // Must be counter-clockwise verts
+ for(var i = 0; i < this.verts.length; i++) {
+ var a = this.verts[i];
+ var b = this.verts[(i + 1) % this.verts.length];
+ var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
+ this.planes[i] = {
+ };
+ this.planes[i].n = n;
+ this.planes[i].d = Phaser.Vec2Utils.dot(n, a);
+ this.tverts[i] = this.verts[i];
+ this.tplanes[i] = {
+ };
+ this.tplanes[i].n = new Phaser.Vec2();
+ this.tplanes[i].d = 0;
+ }
+ for(var i = 0; i < this.verts.length; i++) {
+ var b = this.verts[(i + 2) % this.verts.length];
+ var n = this.planes[i].n;
+ var d = this.planes[i].d;
+ if(Phaser.Vec2Utils.dot(n, b) - d > 0) {
+ this.convexity = false;
+ }
+ }
+ };
+ Poly.prototype.duplicate = function () {
+ return new Phaser.Physics.Advanced.Shapes.Poly(this.verts);
+ };
+ Poly.prototype.recenter = function (c) {
+ for(var i = 0; i < this.verts.length; i++) {
+ this.verts[i].subtract(c);
+ }
+ };
+ Poly.prototype.transform = function (xf) {
+ for(var i = 0; i < this.verts.length; i++) {
+ this.verts[i] = xf.transform(this.verts[i]);
+ }
+ };
+ Poly.prototype.untransform = function (xf) {
+ for(var i = 0; i < this.verts.length; i++) {
+ this.verts[i] = xf.untransform(this.verts[i]);
+ }
+ };
+ Poly.prototype.area = function () {
+ return Advanced.Manager.areaForPoly(this.verts);
+ };
+ Poly.prototype.centroid = function () {
+ return Advanced.Manager.centroidForPoly(this.verts);
+ };
+ Poly.prototype.inertia = function (mass) {
+ return Advanced.Manager.inertiaForPoly(mass, this.verts, new Phaser.Vec2());
+ };
+ Poly.prototype.cacheData = function (xf) {
+ this.bounds.clear();
+ var numVerts = this.verts.length;
+ //console.log('shapePoly cacheData', numVerts);
+ if(numVerts == 0) {
+ return;
+ }
+ for(var i = 0; i < numVerts; i++) {
+ Phaser.TransformUtils.transform(xf, this.tverts[i], this.tverts[i]);
+ //this.tverts[i] = xf.transform(this.verts[i]);
+ }
+ if(numVerts < 2) {
+ this.bounds.addPoint(this.tverts[0]);
+ return;
+ }
+ for(var i = 0; i < numVerts; i++) {
+ var a = this.tverts[i];
+ var b = this.tverts[(i + 1) % numVerts];
+ var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
+ this.tplanes[i].n = n;
+ this.tplanes[i].d = Phaser.Vec2Utils.dot(n, a);
+ this.bounds.addPoint(a);
+ }
+ };
+ Poly.prototype.pointQuery = function (p) {
+ if(!this.bounds.containPoint(p)) {
+ return false;
+ }
+ return this.containPoint(p);
+ };
+ Poly.prototype.findVertexByPoint = function (p, minDist) {
+ var dsq = minDist * minDist;
+ for(var i = 0; i < this.tverts.length; i++) {
+ if(Phaser.Vec2Utils.distanceSq(this.tverts[i], p) < dsq) {
+ return i;
+ }
+ }
+ return -1;
+ };
+ Poly.prototype.findEdgeByPoint = function (p, minDist) {
+ var dsq = minDist * minDist;
+ var numVerts = this.tverts.length;
+ for(var i = 0; i < this.tverts.length; i++) {
+ var v1 = this.tverts[i];
+ var v2 = this.tverts[(i + 1) % numVerts];
+ var n = this.tplanes[i].n;
+ var dtv1 = Phaser.Vec2Utils.cross(v1, n);
+ var dtv2 = Phaser.Vec2Utils.cross(v2, n);
+ var dt = Phaser.Vec2Utils.cross(p, n);
+ if(dt > dtv1) {
+ if(Phaser.Vec2Utils.distanceSq(v1, p) < dsq) {
+ return i;
+ }
+ } else if(dt < dtv2) {
+ if(Phaser.Vec2Utils.distanceSq(v2, p) < dsq) {
+ return i;
+ }
+ } else {
+ var dist = Phaser.Vec2Utils.dot(n, p) - Phaser.Vec2Utils.dot(n, v1);
+ if(dist * dist < dsq) {
+ return i;
+ }
+ }
+ }
+ return -1;
+ };
+ Poly.prototype.distanceOnPlane = function (n, d) {
+ var min = 999999;
+ for(var i = 0; i < this.verts.length; i++) {
+ min = Math.min(min, Phaser.Vec2Utils.dot(n, this.tverts[i]));
+ }
+ return min - d;
+ };
+ Poly.prototype.containPoint = function (p) {
+ for(var i = 0; i < this.verts.length; i++) {
+ var plane = this.tplanes[i];
+ if(Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0) {
+ return false;
+ }
+ }
+ return true;
+ };
+ Poly.prototype.containPointPartial = function (p, n) {
+ for(var i = 0; i < this.verts.length; i++) {
+ var plane = this.tplanes[i];
+ if(Phaser.Vec2Utils.dot(plane.n, n) < 0.0001) {
+ continue;
+ }
+ if(Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0) {
+ return false;
+ }
+ }
+ return true;
+ };
+ return Poly;
+ })(Phaser.Physics.Advanced.Shape);
+ Shapes.Poly = Poly;
+ })(Advanced.Shapes || (Advanced.Shapes = {}));
+ var Shapes = Advanced.Shapes;
+ })(Physics.Advanced || (Physics.Advanced = {}));
+ var Advanced = Physics.Advanced;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Advanced) {
+ ///
+ ///
+ ///
+ ///
+ ///
+ /**
+ * Phaser - Advanced Physics - Shapes - Segment
+ *
+ * Based on the work Ju Hyung Lee started in JS PhyRus.
+ */
+ (function (Shapes) {
+ var Segment = (function (_super) {
+ __extends(Segment, _super);
+ function Segment(a, b, radius) {
+ _super.call(this, Advanced.Manager.SHAPE_TYPE_SEGMENT);
+ this.a = a.duplicate();
+ this.b = b.duplicate();
+ this.radius = radius;
+ this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(b, a));
+ this.normal.normalize();
+ this.ta = new Phaser.Vec2();
+ this.tb = new Phaser.Vec2();
+ this.tn = new Phaser.Vec2();
+ this.finishVerts();
+ }
+ Segment.prototype.finishVerts = function () {
+ this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.b, this.a));
+ this.normal.normalize();
+ this.radius = Math.abs(this.radius);
+ };
+ Segment.prototype.duplicate = function () {
+ return new Phaser.Physics.Advanced.Shapes.Segment(this.a, this.b, this.radius);
+ };
+ Segment.prototype.recenter = function (c) {
+ this.a.subtract(c);
+ this.b.subtract(c);
+ };
+ Segment.prototype.transform = function (xf) {
+ Phaser.TransformUtils.transform(xf, this.a, this.a);
+ Phaser.TransformUtils.transform(xf, this.b, this.b);
+ //this.a = xf.transform(this.a);
+ //this.b = xf.transform(this.b);
+ };
+ Segment.prototype.untransform = function (xf) {
+ Phaser.TransformUtils.untransform(xf, this.a, this.a);
+ Phaser.TransformUtils.untransform(xf, this.b, this.b);
+ //this.a = xf.untransform(this.a);
+ //this.b = xf.untransform(this.b);
+ };
+ Segment.prototype.area = function () {
+ return Advanced.Manager.areaForSegment(this.a, this.b, this.radius);
+ };
+ Segment.prototype.centroid = function () {
+ return Advanced.Manager.centroidForSegment(this.a, this.b);
+ };
+ Segment.prototype.inertia = function (mass) {
+ return Advanced.Manager.inertiaForSegment(mass, this.a, this.b);
+ };
+ Segment.prototype.cacheData = function (xf) {
+ Phaser.TransformUtils.transform(xf, this.a, this.ta);
+ Phaser.TransformUtils.transform(xf, this.b, this.tb);
+ //this.ta = xf.transform(this.a);
+ //this.tb = xf.transform(this.b);
+ this.tn = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.tb, this.ta)).normalize();
+ var l;
+ var r;
+ var t;
+ var b;
+ if(this.ta.x < this.tb.x) {
+ l = this.ta.x;
+ r = this.tb.x;
+ } else {
+ l = this.tb.x;
+ r = this.ta.x;
+ }
+ if(this.ta.y < this.tb.y) {
+ b = this.ta.y;
+ t = this.tb.y;
+ } else {
+ b = this.tb.y;
+ t = this.ta.y;
+ }
+ this.bounds.mins.setTo(l - this.radius, b - this.radius);
+ this.bounds.maxs.setTo(r + this.radius, t + this.radius);
+ };
+ Segment.prototype.pointQuery = function (p) {
+ if(!this.bounds.containPoint(p)) {
+ return false;
+ }
+ var dn = Phaser.Vec2Utils.dot(this.tn, p) - Phaser.Vec2Utils.dot(this.ta, this.tn);
+ var dist = Math.abs(dn);
+ if(dist > this.radius) {
+ return false;
+ }
+ var dt = Phaser.Vec2Utils.cross(p, this.tn);
+ var dta = Phaser.Vec2Utils.cross(this.ta, this.tn);
+ var dtb = Phaser.Vec2Utils.cross(this.tb, this.tn);
+ if(dt <= dta) {
+ if(dt < dta - this.radius) {
+ return false;
+ }
+ return Phaser.Vec2Utils.distanceSq(this.ta, p) < (this.radius * this.radius);
+ } else if(dt > dtb) {
+ if(dt > dtb + this.radius) {
+ return false;
+ }
+ return Phaser.Vec2Utils.distanceSq(this.tb, p) < (this.radius * this.radius);
+ }
+ return true;
+ };
+ Segment.prototype.findVertexByPoint = function (p, minDist) {
+ var dsq = minDist * minDist;
+ if(Phaser.Vec2Utils.distanceSq(this.ta, p) < dsq) {
+ return 0;
+ }
+ if(Phaser.Vec2Utils.distanceSq(this.tb, p) < dsq) {
+ return 1;
+ }
+ return -1;
+ };
+ Segment.prototype.distanceOnPlane = function (n, d) {
+ var a = Phaser.Vec2Utils.dot(n, this.ta) - this.radius;
+ var b = Phaser.Vec2Utils.dot(n, this.tb) - this.radius;
+ return Math.min(a, b) - d;
+ };
+ return Segment;
+ })(Phaser.Physics.Advanced.Shape);
+ Shapes.Segment = Segment;
+ })(Advanced.Shapes || (Advanced.Shapes = {}));
+ var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
@@ -19912,11 +20250,13 @@ var Phaser;
///
///
///
+ ///
+ ///
+ ///
+ ///
///
///
- ///
///
- ///
/**
* Phaser - Advanced Physics - Collision Handlers
*
@@ -19927,7 +20267,6 @@ var Phaser;
function Collision() {
}
Collision.prototype.collide = function (a, b, contacts) {
- //console.log('collide', a.type, b.type);
// Circle (a is the circle)
if(a.type == Advanced.Manager.SHAPE_TYPE_CIRCLE) {
if(b.type == Advanced.Manager.SHAPE_TYPE_CIRCLE) {
@@ -19982,10 +20321,10 @@ var Phaser;
return 1;
};
Collision.prototype.circle2Circle = function (circ1, circ2, contactArr) {
- return this._circle2Circle(circ1.tc, circ1.r, circ2.tc, circ2.r, contactArr);
+ return this._circle2Circle(circ1.tc, circ1.radius, circ2.tc, circ2.radius, contactArr);
};
Collision.prototype.circle2Segment = function (circ, seg, contactArr) {
- var rsum = circ.radius + seg.r;
+ var rsum = circ.radius + seg.radius;
// Normal distance from segment
var dn = Phaser.Vec2Utils.dot(circ.tc, seg.tn) - Phaser.Vec2Utils.dot(seg.ta, seg.tn);
var dist = (dn < 0 ? dn * -1 : dn) - rsum;
@@ -20000,12 +20339,12 @@ var Phaser;
if(dt < dtMin - rsum) {
return 0;
}
- return this._circle2Circle(circ.tc, circ.radius, seg.ta, seg.r, contactArr);
+ return this._circle2Circle(circ.tc, circ.radius, seg.ta, seg.radius, contactArr);
} else if(dt > dtMax) {
if(dt > dtMax + rsum) {
return 0;
}
- return this._circle2Circle(circ.tc, circ.radius, seg.tb, seg.r, contactArr);
+ return this._circle2Circle(circ.tc, circ.radius, seg.tb, seg.radius, contactArr);
}
var n = new Phaser.Vec2();
if(dn > 0) {
@@ -20108,7 +20447,7 @@ var Phaser;
}
var minp1 = Phaser.Vec2Utils.multiplyAdd(seg1.ta, u, s);
var minp2 = Phaser.Vec2Utils.multiplyAdd(seg2.ta, v, t);
- return this._circle2Circle(minp1, seg1.r, minp2, seg2.r, contactArr);
+ return this._circle2Circle(minp1, seg1.radius, minp2, seg2.radius, contactArr);
};
Collision.prototype.findPointsBehindSeg = // Identify vertexes that have penetrated the segment.
function (contactArr, seg, poly, dist, coef) {
@@ -20119,7 +20458,7 @@ var Phaser;
//var n = vec2.scale(seg.tn, coef);
for(var i = 0; i < poly.verts.length; i++) {
var v = poly.tverts[i];
- if(Phaser.Vec2Utils.dot(v, n) < Phaser.Vec2Utils.dot(seg.tn, seg.ta) * coef + seg.r) {
+ if(Phaser.Vec2Utils.dot(v, n) < Phaser.Vec2Utils.dot(seg.tn, seg.ta) * coef + seg.radius) {
var dt = Phaser.Vec2Utils.cross(seg.tn, v);
if(dta >= dt && dt >= dtb) {
contactArr.push(new Advanced.Contact(v, n, dist, (poly.id << 16) | i));
@@ -20129,13 +20468,13 @@ var Phaser;
};
Collision.prototype.segment2Poly = function (seg, poly, contactArr) {
var seg_td = Phaser.Vec2Utils.dot(seg.tn, seg.ta);
- var seg_d1 = poly.distanceOnPlane(seg.tn, seg_td) - seg.r;
+ var seg_d1 = poly.distanceOnPlane(seg.tn, seg_td) - seg.radius;
if(seg_d1 > 0) {
return 0;
}
var n = new Phaser.Vec2();
Phaser.Vec2Utils.negative(seg.tn, n);
- var seg_d2 = poly.distanceOnPlane(n, -seg_td) - seg.r;
+ var seg_d2 = poly.distanceOnPlane(n, -seg_td) - seg.radius;
//var seg_d2 = poly.distanceOnPlane(vec2.neg(seg.tn), -seg_td) - seg.r;
if(seg_d2 > 0) {
return 0;
@@ -20157,10 +20496,10 @@ var Phaser;
Phaser.Vec2Utils.negative(poly.tplanes[poly_i].n, poly_n);
//var poly_n = vec2.neg(poly.tplanes[poly_i].n);
var va = new Phaser.Vec2();
- Phaser.Vec2Utils.multiplyAdd(seg.ta, poly_n, seg.r, va);
+ Phaser.Vec2Utils.multiplyAdd(seg.ta, poly_n, seg.radius, va);
//var va = vec2.mad(seg.ta, poly_n, seg.r);
var vb = new Phaser.Vec2();
- Phaser.Vec2Utils.multiplyAdd(seg.tb, poly_n, seg.r, vb);
+ Phaser.Vec2Utils.multiplyAdd(seg.tb, poly_n, seg.radius, vb);
//var vb = vec2.mad(seg.tb, poly_n, seg.r);
if(poly.containPoint(va)) {
contactArr.push(new Advanced.Contact(va, poly_n, poly_d, (seg.id << 16) | 0));
@@ -20182,16 +20521,16 @@ var Phaser;
if(contactArr.length == 0) {
var poly_a = poly.tverts[poly_i];
var poly_b = poly.tverts[(poly_i + 1) % poly.verts.length];
- if(this._circle2Circle(seg.ta, seg.r, poly_a, 0, contactArr)) {
+ if(this._circle2Circle(seg.ta, seg.radius, poly_a, 0, contactArr)) {
return 1;
}
- if(this._circle2Circle(seg.tb, seg.r, poly_a, 0, contactArr)) {
+ if(this._circle2Circle(seg.tb, seg.radius, poly_a, 0, contactArr)) {
return 1;
}
- if(this._circle2Circle(seg.ta, seg.r, poly_b, 0, contactArr)) {
+ if(this._circle2Circle(seg.ta, seg.radius, poly_b, 0, contactArr)) {
return 1;
}
- if(this._circle2Circle(seg.tb, seg.r, poly_b, 0, contactArr)) {
+ if(this._circle2Circle(seg.tb, seg.radius, poly_b, 0, contactArr)) {
return 1;
}
}
@@ -20290,11 +20629,10 @@ var Phaser;
(function (Phaser) {
(function (Physics) {
///
- ///
///
///
///
- ///
+ ///
///
///
///
@@ -20826,10 +21164,10 @@ var Phaser;
///
///
///
- ///
+ ///
///
///
- ///
+ ///
/**
* Phaser - Advanced Physics - Body
*
@@ -21189,199 +21527,40 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - ShapePoly (convex only)
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
(function (Advanced) {
- var ShapePoly = (function (_super) {
- __extends(ShapePoly, _super);
- function ShapePoly(verts) {
- console.log('ShapePoly created', verts);
- _super.call(this, Advanced.Manager.SHAPE_TYPE_POLY);
- this.verts = [];
- this.planes = [];
- this.tverts = [];
- this.tplanes = [];
- if(verts) {
- for(var i = 0; i < verts.length; i++) {
- //console.log('cloning vert', i);
- this.verts[i] = Phaser.Vec2Utils.clone(verts[i]);
- this.tverts[i] = this.verts[i];
- this.tplanes[i] = {
- };
- this.tplanes[i].n = new Phaser.Vec2();
- this.tplanes[i].d = 0;
- }
+ ///
+ ///
+ ///
+ ///
+ ///
+ /**
+ * Phaser - Advanced Physics - Shapes - Box
+ *
+ * Based on the work Ju Hyung Lee started in JS PhyRus.
+ */
+ (function (Shapes) {
+ var Box = (function (_super) {
+ __extends(Box, _super);
+ // Give in pixels
+ function Box(x, y, width, height) {
+ x = Advanced.Manager.pixelsToMeters(x);
+ y = Advanced.Manager.pixelsToMeters(y);
+ width = Advanced.Manager.pixelsToMeters(width);
+ height = Advanced.Manager.pixelsToMeters(height);
+ var hw = width * 0.5;
+ var hh = height * 0.5;
+ _super.call(this, [
+ new Phaser.Vec2(-hw + x, +hh + y),
+ new Phaser.Vec2(-hw + x, -hh + y),
+ new Phaser.Vec2(+hw + x, -hh + y),
+ new Phaser.Vec2(+hw + x, +hh + y)
+ ]);
}
- //console.log('ShapePoly finished', this.verts);
- this.finishVerts();
- //console.log('ShapePoly finished 2', this.verts);
- }
- ShapePoly.prototype.finishVerts = function () {
- if(this.verts.length < 2) {
- this.convexity = false;
- this.planes = [];
- return;
- }
- this.convexity = true;
- this.tverts = [];
- this.tplanes = [];
- // Must be counter-clockwise verts
- for(var i = 0; i < this.verts.length; i++) {
- var a = this.verts[i];
- var b = this.verts[(i + 1) % this.verts.length];
- var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
- this.planes[i] = {
- };
- this.planes[i].n = n;
- this.planes[i].d = Phaser.Vec2Utils.dot(n, a);
- this.tverts[i] = this.verts[i];
- this.tplanes[i] = {
- };
- this.tplanes[i].n = new Phaser.Vec2();
- this.tplanes[i].d = 0;
- }
- for(var i = 0; i < this.verts.length; i++) {
- var b = this.verts[(i + 2) % this.verts.length];
- var n = this.planes[i].n;
- var d = this.planes[i].d;
- if(Phaser.Vec2Utils.dot(n, b) - d > 0) {
- this.convexity = false;
- }
- }
- };
- ShapePoly.prototype.duplicate = function () {
- return new ShapePoly(this.verts);
- };
- ShapePoly.prototype.recenter = function (c) {
- for(var i = 0; i < this.verts.length; i++) {
- this.verts[i].subtract(c);
- }
- };
- ShapePoly.prototype.transform = function (xf) {
- for(var i = 0; i < this.verts.length; i++) {
- this.verts[i] = xf.transform(this.verts[i]);
- }
- };
- ShapePoly.prototype.untransform = function (xf) {
- for(var i = 0; i < this.verts.length; i++) {
- this.verts[i] = xf.untransform(this.verts[i]);
- }
- };
- ShapePoly.prototype.area = function () {
- return Advanced.Manager.areaForPoly(this.verts);
- };
- ShapePoly.prototype.centroid = function () {
- return Advanced.Manager.centroidForPoly(this.verts);
- };
- ShapePoly.prototype.inertia = function (mass) {
- return Advanced.Manager.inertiaForPoly(mass, this.verts, new Phaser.Vec2());
- };
- ShapePoly.prototype.cacheData = function (xf) {
- this.bounds.clear();
- var numVerts = this.verts.length;
- //console.log('shapePoly cacheData', numVerts);
- if(numVerts == 0) {
- return;
- }
- for(var i = 0; i < numVerts; i++) {
- Phaser.TransformUtils.transform(xf, this.tverts[i], this.tverts[i]);
- //this.tverts[i] = xf.transform(this.verts[i]);
- }
- if(numVerts < 2) {
- this.bounds.addPoint(this.tverts[0]);
- return;
- }
- for(var i = 0; i < numVerts; i++) {
- var a = this.tverts[i];
- var b = this.tverts[(i + 1) % numVerts];
- var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
- this.tplanes[i].n = n;
- this.tplanes[i].d = Phaser.Vec2Utils.dot(n, a);
- this.bounds.addPoint(a);
- }
- };
- ShapePoly.prototype.pointQuery = function (p) {
- if(!this.bounds.containPoint(p)) {
- return false;
- }
- return this.containPoint(p);
- };
- ShapePoly.prototype.findVertexByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- for(var i = 0; i < this.tverts.length; i++) {
- if(Phaser.Vec2Utils.distanceSq(this.tverts[i], p) < dsq) {
- return i;
- }
- }
- return -1;
- };
- ShapePoly.prototype.findEdgeByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- var numVerts = this.tverts.length;
- for(var i = 0; i < this.tverts.length; i++) {
- var v1 = this.tverts[i];
- var v2 = this.tverts[(i + 1) % numVerts];
- var n = this.tplanes[i].n;
- var dtv1 = Phaser.Vec2Utils.cross(v1, n);
- var dtv2 = Phaser.Vec2Utils.cross(v2, n);
- var dt = Phaser.Vec2Utils.cross(p, n);
- if(dt > dtv1) {
- if(Phaser.Vec2Utils.distanceSq(v1, p) < dsq) {
- return i;
- }
- } else if(dt < dtv2) {
- if(Phaser.Vec2Utils.distanceSq(v2, p) < dsq) {
- return i;
- }
- } else {
- var dist = Phaser.Vec2Utils.dot(n, p) - Phaser.Vec2Utils.dot(n, v1);
- if(dist * dist < dsq) {
- return i;
- }
- }
- }
- return -1;
- };
- ShapePoly.prototype.distanceOnPlane = function (n, d) {
- var min = 999999;
- for(var i = 0; i < this.verts.length; i++) {
- min = Math.min(min, Phaser.Vec2Utils.dot(n, this.tverts[i]));
- }
- return min - d;
- };
- ShapePoly.prototype.containPoint = function (p) {
- for(var i = 0; i < this.verts.length; i++) {
- var plane = this.tplanes[i];
- if(Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0) {
- return false;
- }
- }
- return true;
- };
- ShapePoly.prototype.containPointPartial = function (p, n) {
- for(var i = 0; i < this.verts.length; i++) {
- var plane = this.tplanes[i];
- if(Phaser.Vec2Utils.dot(plane.n, n) < 0.0001) {
- continue;
- }
- if(Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0) {
- return false;
- }
- }
- return true;
- };
- return ShapePoly;
- })(Phaser.Physics.Advanced.Shape);
- Advanced.ShapePoly = ShapePoly;
+ return Box;
+ })(Phaser.Physics.Advanced.Shapes.Poly);
+ Shapes.Box = Box;
+ })(Advanced.Shapes || (Advanced.Shapes = {}));
+ var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
@@ -21390,211 +21569,32 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - ShapeBox
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
(function (Advanced) {
- var ShapeBox = (function (_super) {
- __extends(ShapeBox, _super);
- // Give in pixels
- function ShapeBox(x, y, width, height) {
- console.log('creating box', x, y, width, height);
- x = Advanced.Manager.pixelsToMeters(x);
- y = Advanced.Manager.pixelsToMeters(y);
- width = Advanced.Manager.pixelsToMeters(width);
- height = Advanced.Manager.pixelsToMeters(height);
- var hw = width * 0.5;
- var hh = height * 0.5;
- _super.call(this, [
- new Phaser.Vec2(-hw + x, +hh + y),
- new Phaser.Vec2(-hw + x, -hh + y),
- new Phaser.Vec2(+hw + x, -hh + y),
- new Phaser.Vec2(+hw + x, +hh + y)
- ]);
- }
- return ShapeBox;
- })(Phaser.Physics.Advanced.ShapePoly);
- Advanced.ShapeBox = ShapeBox;
- })(Physics.Advanced || (Physics.Advanced = {}));
- var Advanced = Physics.Advanced;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - Shape
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
- (function (Advanced) {
- var ShapeSegment = (function (_super) {
- __extends(ShapeSegment, _super);
- function ShapeSegment(a, b, radius) {
- _super.call(this, Advanced.Manager.SHAPE_TYPE_SEGMENT);
- // What types are A and B??!
- this.a = a.duplicate();
- this.b = b.duplicate();
- this.radius = radius;
- this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(b, a));
- this.normal.normalize();
- this.ta = new Phaser.Vec2();
- this.tb = new Phaser.Vec2();
- this.tn = new Phaser.Vec2();
- this.finishVerts();
- }
- ShapeSegment.prototype.finishVerts = function () {
- this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.b, this.a));
- this.normal.normalize();
- this.radius = Math.abs(this.radius);
- };
- ShapeSegment.prototype.duplicate = function () {
- return new ShapeSegment(this.a, this.b, this.radius);
- };
- ShapeSegment.prototype.recenter = function (c) {
- this.a.subtract(c);
- this.b.subtract(c);
- };
- ShapeSegment.prototype.transform = function (xf) {
- Phaser.TransformUtils.transform(xf, this.a, this.a);
- Phaser.TransformUtils.transform(xf, this.b, this.b);
- //this.a = xf.transform(this.a);
- //this.b = xf.transform(this.b);
- };
- ShapeSegment.prototype.untransform = function (xf) {
- Phaser.TransformUtils.untransform(xf, this.a, this.a);
- Phaser.TransformUtils.untransform(xf, this.b, this.b);
- //this.a = xf.untransform(this.a);
- //this.b = xf.untransform(this.b);
- };
- ShapeSegment.prototype.area = function () {
- return Advanced.Manager.areaForSegment(this.a, this.b, this.radius);
- };
- ShapeSegment.prototype.centroid = function () {
- return Advanced.Manager.centroidForSegment(this.a, this.b);
- };
- ShapeSegment.prototype.inertia = function (mass) {
- return Advanced.Manager.inertiaForSegment(mass, this.a, this.b);
- };
- ShapeSegment.prototype.cacheData = function (xf) {
- Phaser.TransformUtils.transform(xf, this.a, this.ta);
- Phaser.TransformUtils.transform(xf, this.b, this.tb);
- //this.ta = xf.transform(this.a);
- //this.tb = xf.transform(this.b);
- this.tn = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.tb, this.ta)).normalize();
- var l;
- var r;
- var t;
- var b;
- if(this.ta.x < this.tb.x) {
- l = this.ta.x;
- r = this.tb.x;
- } else {
- l = this.tb.x;
- r = this.ta.x;
+ ///
+ ///
+ ///
+ ///
+ ///
+ /**
+ * Phaser - Advanced Physics - Shapes - Triangle
+ *
+ * Based on the work Ju Hyung Lee started in JS PhyRus.
+ */
+ (function (Shapes) {
+ var Triangle = (function (_super) {
+ __extends(Triangle, _super);
+ function Triangle(p1, p2, p3) {
+ _super.call(this, [
+ new Phaser.Vec2(p1.x, p1.y),
+ new Phaser.Vec2(p2.x, p2.y),
+ new Phaser.Vec2(p3.x, p3.y)
+ ]);
}
- if(this.ta.y < this.tb.y) {
- b = this.ta.y;
- t = this.tb.y;
- } else {
- b = this.tb.y;
- t = this.ta.y;
- }
- this.bounds.mins.setTo(l - this.radius, b - this.radius);
- this.bounds.maxs.setTo(r + this.radius, t + this.radius);
- };
- ShapeSegment.prototype.pointQuery = function (p) {
- if(!this.bounds.containPoint(p)) {
- return false;
- }
- var dn = Phaser.Vec2Utils.dot(this.tn, p) - Phaser.Vec2Utils.dot(this.ta, this.tn);
- var dist = Math.abs(dn);
- if(dist > this.radius) {
- return false;
- }
- var dt = Phaser.Vec2Utils.cross(p, this.tn);
- var dta = Phaser.Vec2Utils.cross(this.ta, this.tn);
- var dtb = Phaser.Vec2Utils.cross(this.tb, this.tn);
- if(dt <= dta) {
- if(dt < dta - this.radius) {
- return false;
- }
- return Phaser.Vec2Utils.distanceSq(this.ta, p) < (this.radius * this.radius);
- } else if(dt > dtb) {
- if(dt > dtb + this.radius) {
- return false;
- }
- return Phaser.Vec2Utils.distanceSq(this.tb, p) < (this.radius * this.radius);
- }
- return true;
- };
- ShapeSegment.prototype.findVertexByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- if(Phaser.Vec2Utils.distanceSq(this.ta, p) < dsq) {
- return 0;
- }
- if(Phaser.Vec2Utils.distanceSq(this.tb, p) < dsq) {
- return 1;
- }
- return -1;
- };
- ShapeSegment.prototype.distanceOnPlane = function (n, d) {
- var a = Phaser.Vec2Utils.dot(n, this.ta) - this.radius;
- var b = Phaser.Vec2Utils.dot(n, this.tb) - this.radius;
- return Math.min(a, b) - d;
- };
- return ShapeSegment;
- })(Phaser.Physics.Advanced.Shape);
- Advanced.ShapeSegment = ShapeSegment;
- })(Physics.Advanced || (Physics.Advanced = {}));
- var Advanced = Physics.Advanced;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - ShapeTriangle
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
- (function (Advanced) {
- var ShapeTriangle = (function (_super) {
- __extends(ShapeTriangle, _super);
- function ShapeTriangle(p1, p2, p3) {
- _super.call(this, [
- new Phaser.Vec2(p1.x, p1.y),
- new Phaser.Vec2(p2.x, p2.y),
- new Phaser.Vec2(p3.x, p3.y)
- ]);
- }
- return ShapeTriangle;
- })(Phaser.Physics.Advanced.ShapePoly);
- Advanced.ShapeTriangle = ShapeTriangle;
+ return Triangle;
+ })(Phaser.Physics.Advanced.Shapes.Poly);
+ Shapes.Triangle = Triangle;
+ })(Advanced.Shapes || (Advanced.Shapes = {}));
+ var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
diff --git a/Tests/physics/body1.js b/Tests/physics/body1.js
index 0ad893bdc..f8f99706d 100644
--- a/Tests/physics/body1.js
+++ b/Tests/physics/body1.js
@@ -1,7 +1,7 @@
///
///
-///
-///
+///
+///
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
@@ -24,8 +24,7 @@
walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC);
walls.game = game;
// position is in relation to the containing body! don't forget this
- ground = walls.addShape(new Phaser.Physics.Advanced.ShapeBox(400, 500, 500, 20));
- ground.friction = 10;
+ ground = walls.addShape(new Phaser.Physics.Advanced.Shapes.Box(400, 500, 500, 20));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 0.2, 20.48, 0.4));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 15.16, 20.48, 0.4));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(-10.04, 7.68, 0.4, 14.56));
@@ -35,9 +34,9 @@
// Add a circle
circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, physics.pixelsToMeters(300), physics.pixelsToMeters(200));
circle.game = game;
- var shape = new Phaser.Physics.Advanced.ShapeCircle(0.4, 0, 0);
+ var shape = new Phaser.Physics.Advanced.Shapes.Circle(0.4, 0, 0);
shape.elasticity = 0.8;
- shape.friction = 10.0;
+ shape.friction = 1;
shape.density = 1;
circle.addShape(shape);
circle.resetMassData();
diff --git a/Tests/physics/body1.ts b/Tests/physics/body1.ts
index ee39c9ef4..2ab496370 100644
--- a/Tests/physics/body1.ts
+++ b/Tests/physics/body1.ts
@@ -1,7 +1,7 @@
///
///
-///
-///
+///
+///
(function () {
@@ -22,7 +22,7 @@
var circle: Phaser.Physics.Advanced.Body;
var walls: Phaser.Physics.Advanced.Body;
- var ground: Phaser.Physics.Advanced.ShapeBox;
+ var ground: Phaser.Physics.Advanced.Shapes.Box;
function create() {
@@ -36,8 +36,7 @@
walls.game = game;
// position is in relation to the containing body! don't forget this
- ground = walls.addShape(new Phaser.Physics.Advanced.ShapeBox(400, 500, 500, 20));
- ground.friction = 10;
+ ground = walls.addShape(new Phaser.Physics.Advanced.Shapes.Box(400, 500, 500, 20));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 0.2, 20.48, 0.4));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 15.16, 20.48, 0.4));
@@ -52,9 +51,9 @@
circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, physics.pixelsToMeters(300), physics.pixelsToMeters(200));
circle.game = game;
- var shape = new Phaser.Physics.Advanced.ShapeCircle(0.4, 0, 0);
+ var shape = new Phaser.Physics.Advanced.Shapes.Circle(0.4, 0, 0);
shape.elasticity = 0.8;
- shape.friction = 10.0;
+ shape.friction = 1;
shape.density = 1;
circle.addShape(shape);
circle.resetMassData();
diff --git a/build/phaser.d.ts b/build/phaser.d.ts
index 2e09d52ec..7a30e48ae 100644
--- a/build/phaser.d.ts
+++ b/build/phaser.d.ts
@@ -9734,9 +9734,9 @@ module Phaser.Physics.Advanced {
public r2: Vec2;
public r1_local: Vec2;
public r2_local: Vec2;
- public bounce;
- public emn;
- public emt;
+ public bounce: number;
+ public emn: number;
+ public emt: number;
public point;
public normal: Vec2;
public depth;
@@ -9761,18 +9761,18 @@ module Phaser.Physics.Advanced {
}
}
/**
-* Phaser - Advanced Physics - Shape
+* Phaser - Advanced Physics - Shape - Circle
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
-module Phaser.Physics.Advanced {
- class ShapeCircle extends Shape implements IShape {
+module Phaser.Physics.Advanced.Shapes {
+ class Circle extends Shape implements IShape {
constructor(radius: number, x?: number, y?: number);
public radius: number;
public center: Vec2;
public tc: Vec2;
public finishVerts(): void;
- public duplicate(): ShapeCircle;
+ public duplicate(): Circle;
public recenter(c: Vec2): void;
public transform(xf: Transform): void;
public untransform(xf: Transform): void;
@@ -9786,6 +9786,65 @@ module Phaser.Physics.Advanced {
}
}
/**
+* Phaser - Advanced Physics - Shapes - Convex Polygon
+*
+* Based on the work Ju Hyung Lee started in JS PhyRus.
+*/
+module Phaser.Physics.Advanced.Shapes {
+ class Poly extends Shape implements IShape {
+ constructor(verts?: Vec2[]);
+ public verts: Vec2[];
+ public planes;
+ public tverts;
+ public tplanes;
+ public convexity: bool;
+ public finishVerts(): void;
+ public duplicate(): Poly;
+ public recenter(c): void;
+ public transform(xf): void;
+ public untransform(xf): void;
+ public area(): number;
+ public centroid(): Vec2;
+ public inertia(mass: number): number;
+ public cacheData(xf: Transform): void;
+ public pointQuery(p: Vec2): bool;
+ public findVertexByPoint(p: Vec2, minDist: number): number;
+ public findEdgeByPoint(p: Vec2, minDist: number): number;
+ public distanceOnPlane(n, d): number;
+ public containPoint(p): bool;
+ public containPointPartial(p, n): bool;
+ }
+}
+/**
+* Phaser - Advanced Physics - Shapes - Segment
+*
+* Based on the work Ju Hyung Lee started in JS PhyRus.
+*/
+module Phaser.Physics.Advanced.Shapes {
+ class Segment extends Shape implements IShape {
+ constructor(a, b, radius: number);
+ public a: Vec2;
+ public b: Vec2;
+ public radius: number;
+ public normal: Vec2;
+ public ta: Vec2;
+ public tb: Vec2;
+ public tn: Vec2;
+ public finishVerts(): void;
+ public duplicate(): Segment;
+ public recenter(c): void;
+ public transform(xf: Transform): void;
+ public untransform(xf: Transform): void;
+ public area(): number;
+ public centroid(): Vec2;
+ public inertia(mass: number): number;
+ public cacheData(xf: Transform): void;
+ public pointQuery(p: Vec2): bool;
+ public findVertexByPoint(p: Vec2, minDist: number): number;
+ public distanceOnPlane(n, d): number;
+ }
+}
+/**
* Phaser - Advanced Physics - Collision Handlers
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
@@ -9793,22 +9852,22 @@ module Phaser.Physics.Advanced {
module Phaser.Physics.Advanced {
class Collision {
constructor();
- public collide(a, b, contacts: Contact[]);
+ public collide(a, b, contacts: Contact[]): number;
private _circle2Circle(c1, r1, c2, r2, contactArr);
- public circle2Circle(circ1, circ2, contactArr): number;
- public circle2Segment(circ: ShapeCircle, seg, contactArr: Contact[]): number;
- public circle2Poly(circ: ShapeCircle, poly, contactArr: Contact[]): number;
- public segmentPointDistanceSq(seg, p): number;
- public segment2Segment(seg1, seg2, contactArr): number;
- public findPointsBehindSeg(contactArr, seg, poly, dist, coef): void;
- public segment2Poly(seg, poly, contactArr);
- public findMSA(poly, planes, num): {
+ public circle2Circle(circ1: Shapes.Circle, circ2: Shapes.Circle, contactArr: Contact[]): number;
+ public circle2Segment(circ: Shapes.Circle, seg: Shapes.Segment, contactArr: Contact[]): number;
+ public circle2Poly(circ: Shapes.Circle, poly: Shapes.Poly, contactArr: Contact[]): number;
+ public segmentPointDistanceSq(seg: Shapes.Segment, p): number;
+ public segment2Segment(seg1: Shapes.Segment, seg2: Shapes.Segment, contactArr: Contact[]): number;
+ public findPointsBehindSeg(contactArr: Contact[], seg: Shapes.Segment, poly: Shapes.Poly, dist: number, coef: number): void;
+ public segment2Poly(seg: Shapes.Segment, poly: Shapes.Poly, contactArr: Contact[]): number;
+ public findMSA(poly: Shapes.Poly, planes, num: number): {
dist: number;
index: number;
};
- public findVertsFallback(contactArr, poly1, poly2, n, dist): number;
- public findVerts(contactArr, poly1, poly2, n, dist): number;
- public poly2Poly(poly1, poly2, contactArr): number;
+ public findVertsFallback(contactArr: Contact[], poly1: Shapes.Poly, poly2: Shapes.Poly, n, dist: number): number;
+ public findVerts(contactArr: Contact[], poly1: Shapes.Poly, poly2: Shapes.Poly, n, dist: number): number;
+ public poly2Poly(poly1: Shapes.Poly, poly2: Shapes.Poly, contactArr: Contact[]): number;
}
}
/**
@@ -9972,193 +10031,26 @@ module Phaser.Physics.Advanced {
}
}
/**
-* Phaser - Advanced Physics - ShapePoly (convex only)
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-module Phaser.Physics.Advanced {
- class ShapePoly extends Shape implements IShape {
- constructor(verts?: Vec2[]);
- public verts: Vec2[];
- public planes;
- public tverts;
- public tplanes;
- public convexity: bool;
- public finishVerts(): void;
- public duplicate(): ShapePoly;
- public recenter(c): void;
- public transform(xf): void;
- public untransform(xf): void;
- public area(): number;
- public centroid(): Vec2;
- public inertia(mass: number): number;
- public cacheData(xf: Transform): void;
- public pointQuery(p: Vec2): bool;
- public findVertexByPoint(p: Vec2, minDist: number): number;
- public findEdgeByPoint(p: Vec2, minDist: number): number;
- public distanceOnPlane(n, d): number;
- public containPoint(p): bool;
- public containPointPartial(p, n): bool;
- }
-}
-/**
-* Phaser - Advanced Physics - ShapeBox
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-module Phaser.Physics.Advanced {
- class ShapeBox extends ShapePoly {
- constructor(x, y, width, height);
- }
-}
-/**
-* Phaser - Advanced Physics - Shape
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-module Phaser.Physics.Advanced {
- class ShapeSegment extends Shape implements IShape {
- constructor(a, b, radius: number);
- public a: Vec2;
- public b: Vec2;
- public radius: number;
- public normal: Vec2;
- public ta: Vec2;
- public tb: Vec2;
- public tn: Vec2;
- public finishVerts(): void;
- public duplicate(): ShapeSegment;
- public recenter(c): void;
- public transform(xf: Transform): void;
- public untransform(xf: Transform): void;
- public area(): number;
- public centroid(): Vec2;
- public inertia(mass: number): number;
- public cacheData(xf: Transform): void;
- public pointQuery(p: Vec2): bool;
- public findVertexByPoint(p: Vec2, minDist: number): number;
- public distanceOnPlane(n, d): number;
- }
-}
-/**
-* Phaser - Advanced Physics - ShapeTriangle
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-module Phaser.Physics.Advanced {
- class ShapeTriangle extends ShapePoly {
- constructor(p1, p2, p3);
- }
-}
-/**
* Phaser - Advanced Physics - Shapes - Box
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
module Phaser.Physics.Advanced.Shapes {
- class Box extends ShapePoly {
+ class Box extends Poly {
constructor(x, y, width, height);
}
}
/**
-* Phaser - Advanced Physics - Shape - Circle
+* Phaser - Advanced Physics - Shapes - Triangle
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
module Phaser.Physics.Advanced.Shapes {
- class Circle extends Shape implements IShape {
- constructor(radius: number, x?: number, y?: number);
- public radius: number;
- public center: Vec2;
- public tc: Vec2;
- public finishVerts(): void;
- public duplicate(): ShapeCircle;
- public recenter(c: Vec2): void;
- public transform(xf: Transform): void;
- public untransform(xf: Transform): void;
- public area(): number;
- public centroid(): Vec2;
- public inertia(mass: number): number;
- public cacheData(xf: Transform): void;
- public pointQuery(p: Vec2): bool;
- public findVertexByPoint(p: Vec2, minDist: number): number;
- public distanceOnPlane(n, d): void;
+ class Triangle extends Poly {
+ constructor(p1, p2, p3);
}
}
/**
-* Phaser - Advanced Physics - Shapes - Convex Polygon
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-module Phaser.Physics.Advanced.Shapes {
- class Poly extends Shape implements IShape {
- constructor(verts?: Vec2[]);
- public verts: Vec2[];
- public planes;
- public tverts;
- public tplanes;
- public convexity: bool;
- public finishVerts(): void;
- public duplicate(): ShapePoly;
- public recenter(c): void;
- public transform(xf): void;
- public untransform(xf): void;
- public area(): number;
- public centroid(): Vec2;
- public inertia(mass: number): number;
- public cacheData(xf: Transform): void;
- public pointQuery(p: Vec2): bool;
- public findVertexByPoint(p: Vec2, minDist: number): number;
- public findEdgeByPoint(p: Vec2, minDist: number): number;
- public distanceOnPlane(n, d): number;
- public containPoint(p): bool;
- public containPointPartial(p, n): bool;
- }
-}
-/**
-* Phaser - Advanced Physics - Shapes - Segment
-*
-* Based on the work Ju Hyung Lee started in JS PhyRus.
-*/
-module Phaser.Physics.Advanced.Shapes {
- class Segment extends Shape implements IShape {
- constructor(a, b, radius: number);
- public a: Vec2;
- public b: Vec2;
- public radius: number;
- public normal: Vec2;
- public ta: Vec2;
- public tb: Vec2;
- public tn: Vec2;
- public finishVerts(): void;
- public duplicate(): ShapeSegment;
- public recenter(c): void;
- public transform(xf: Transform): void;
- public untransform(xf: Transform): void;
- public area(): number;
- public centroid(): Vec2;
- public inertia(mass: number): number;
- public cacheData(xf: Transform): void;
- public pointQuery(p: Vec2): bool;
- public findVertexByPoint(p: Vec2, minDist: number): number;
- public distanceOnPlane(n, d): number;
- }
-}
-interface IPoint {
- getDist(): number;
-}
-module Shapes {
- class Point implements IPoint {
- public x: number;
- public y: number;
- constructor(x: number, y: number);
- public getDist(): number;
- static origin: Point;
- }
-}
-var p: IPoint;
-var dist: number;
-/**
* Phaser - PixelUtils
*
* A collection of methods useful for manipulating pixels.
diff --git a/build/phaser.js b/build/phaser.js
index 3af0bbd29..0f9b2dab0 100644
--- a/build/phaser.js
+++ b/build/phaser.js
@@ -19504,7 +19504,6 @@ var Phaser;
(function (Phaser) {
(function (Physics) {
///
- ///
///
///
///
@@ -19541,7 +19540,6 @@ var Phaser;
(function (Phaser) {
(function (Physics) {
///
- ///
///
///
///
@@ -19829,78 +19827,418 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - Shape
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
(function (Advanced) {
- var ShapeCircle = (function (_super) {
- __extends(ShapeCircle, _super);
- function ShapeCircle(radius, x, y) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- _super.call(this, Advanced.Manager.SHAPE_TYPE_CIRCLE);
- this.center = new Phaser.Vec2(x, y);
- this.radius = radius;
- this.tc = new Phaser.Vec2();
- this.finishVerts();
- }
- ShapeCircle.prototype.finishVerts = function () {
- this.radius = Math.abs(this.radius);
- };
- ShapeCircle.prototype.duplicate = function () {
- return new ShapeCircle(this.center.x, this.center.y, this.radius);
- };
- ShapeCircle.prototype.recenter = function (c) {
- this.center.subtract(c);
- };
- ShapeCircle.prototype.transform = function (xf) {
- Phaser.TransformUtils.transform(xf, this.center, this.center);
- //this.center = xf.transform(this.center);
- };
- ShapeCircle.prototype.untransform = function (xf) {
- Phaser.TransformUtils.untransform(xf, this.center, this.center);
- //this.center = xf.untransform(this.center);
- };
- ShapeCircle.prototype.area = function () {
- return Advanced.Manager.areaForCircle(this.radius, 0);
- };
- ShapeCircle.prototype.centroid = function () {
- return Phaser.Vec2Utils.clone(this.center);
- };
- ShapeCircle.prototype.inertia = function (mass) {
- return Advanced.Manager.inertiaForCircle(mass, this.center, this.radius, 0);
- };
- ShapeCircle.prototype.cacheData = function (xf) {
- Phaser.TransformUtils.transform(xf, this.center, this.tc);
- //this.tc = xf.transform(this.center);
- this.bounds.mins.setTo(this.tc.x - this.radius, this.tc.y - this.radius);
- this.bounds.maxs.setTo(this.tc.x + this.radius, this.tc.y + this.radius);
- };
- ShapeCircle.prototype.pointQuery = function (p) {
- //return vec2.distsq(this.tc, p) < (this.r * this.r);
- return Phaser.Vec2Utils.distanceSq(this.tc, p) < (this.radius * this.radius);
- };
- ShapeCircle.prototype.findVertexByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- if(Phaser.Vec2Utils.distanceSq(this.tc, p) < dsq) {
- return 0;
+ ///
+ ///
+ ///
+ ///
+ ///
+ /**
+ * Phaser - Advanced Physics - Shape - Circle
+ *
+ * Based on the work Ju Hyung Lee started in JS PhyRus.
+ */
+ (function (Shapes) {
+ var Circle = (function (_super) {
+ __extends(Circle, _super);
+ function Circle(radius, x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ _super.call(this, Advanced.Manager.SHAPE_TYPE_CIRCLE);
+ this.center = new Phaser.Vec2(x, y);
+ this.radius = radius;
+ this.tc = new Phaser.Vec2();
+ this.finishVerts();
}
- return -1;
- };
- ShapeCircle.prototype.distanceOnPlane = function (n, d) {
- Phaser.Vec2Utils.dot(n, this.tc) - this.radius - d;
- };
- return ShapeCircle;
- })(Phaser.Physics.Advanced.Shape);
- Advanced.ShapeCircle = ShapeCircle;
+ Circle.prototype.finishVerts = function () {
+ this.radius = Math.abs(this.radius);
+ };
+ Circle.prototype.duplicate = function () {
+ return new Circle(this.center.x, this.center.y, this.radius);
+ };
+ Circle.prototype.recenter = function (c) {
+ this.center.subtract(c);
+ };
+ Circle.prototype.transform = function (xf) {
+ Phaser.TransformUtils.transform(xf, this.center, this.center);
+ //this.center = xf.transform(this.center);
+ };
+ Circle.prototype.untransform = function (xf) {
+ Phaser.TransformUtils.untransform(xf, this.center, this.center);
+ //this.center = xf.untransform(this.center);
+ };
+ Circle.prototype.area = function () {
+ return Advanced.Manager.areaForCircle(this.radius, 0);
+ };
+ Circle.prototype.centroid = function () {
+ return Phaser.Vec2Utils.clone(this.center);
+ };
+ Circle.prototype.inertia = function (mass) {
+ return Advanced.Manager.inertiaForCircle(mass, this.center, this.radius, 0);
+ };
+ Circle.prototype.cacheData = function (xf) {
+ Phaser.TransformUtils.transform(xf, this.center, this.tc);
+ //this.tc = xf.transform(this.center);
+ this.bounds.mins.setTo(this.tc.x - this.radius, this.tc.y - this.radius);
+ this.bounds.maxs.setTo(this.tc.x + this.radius, this.tc.y + this.radius);
+ };
+ Circle.prototype.pointQuery = function (p) {
+ //return vec2.distsq(this.tc, p) < (this.r * this.r);
+ return Phaser.Vec2Utils.distanceSq(this.tc, p) < (this.radius * this.radius);
+ };
+ Circle.prototype.findVertexByPoint = function (p, minDist) {
+ var dsq = minDist * minDist;
+ if(Phaser.Vec2Utils.distanceSq(this.tc, p) < dsq) {
+ return 0;
+ }
+ return -1;
+ };
+ Circle.prototype.distanceOnPlane = function (n, d) {
+ Phaser.Vec2Utils.dot(n, this.tc) - this.radius - d;
+ };
+ return Circle;
+ })(Phaser.Physics.Advanced.Shape);
+ Shapes.Circle = Circle;
+ })(Advanced.Shapes || (Advanced.Shapes = {}));
+ var Shapes = Advanced.Shapes;
+ })(Physics.Advanced || (Physics.Advanced = {}));
+ var Advanced = Physics.Advanced;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Advanced) {
+ ///
+ ///
+ ///
+ ///
+ ///
+ /**
+ * Phaser - Advanced Physics - Shapes - Convex Polygon
+ *
+ * Based on the work Ju Hyung Lee started in JS PhyRus.
+ */
+ (function (Shapes) {
+ var Poly = (function (_super) {
+ __extends(Poly, _super);
+ function Poly(verts) {
+ _super.call(this, Advanced.Manager.SHAPE_TYPE_POLY);
+ this.verts = [];
+ this.planes = [];
+ this.tverts = [];
+ this.tplanes = [];
+ if(verts) {
+ for(var i = 0; i < verts.length; i++) {
+ this.verts[i] = Phaser.Vec2Utils.clone(verts[i]);
+ this.tverts[i] = this.verts[i];
+ this.tplanes[i] = {
+ };
+ this.tplanes[i].n = new Phaser.Vec2();
+ this.tplanes[i].d = 0;
+ }
+ }
+ this.finishVerts();
+ }
+ Poly.prototype.finishVerts = function () {
+ if(this.verts.length < 2) {
+ this.convexity = false;
+ this.planes = [];
+ return;
+ }
+ this.convexity = true;
+ this.tverts = [];
+ this.tplanes = [];
+ // Must be counter-clockwise verts
+ for(var i = 0; i < this.verts.length; i++) {
+ var a = this.verts[i];
+ var b = this.verts[(i + 1) % this.verts.length];
+ var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
+ this.planes[i] = {
+ };
+ this.planes[i].n = n;
+ this.planes[i].d = Phaser.Vec2Utils.dot(n, a);
+ this.tverts[i] = this.verts[i];
+ this.tplanes[i] = {
+ };
+ this.tplanes[i].n = new Phaser.Vec2();
+ this.tplanes[i].d = 0;
+ }
+ for(var i = 0; i < this.verts.length; i++) {
+ var b = this.verts[(i + 2) % this.verts.length];
+ var n = this.planes[i].n;
+ var d = this.planes[i].d;
+ if(Phaser.Vec2Utils.dot(n, b) - d > 0) {
+ this.convexity = false;
+ }
+ }
+ };
+ Poly.prototype.duplicate = function () {
+ return new Phaser.Physics.Advanced.Shapes.Poly(this.verts);
+ };
+ Poly.prototype.recenter = function (c) {
+ for(var i = 0; i < this.verts.length; i++) {
+ this.verts[i].subtract(c);
+ }
+ };
+ Poly.prototype.transform = function (xf) {
+ for(var i = 0; i < this.verts.length; i++) {
+ this.verts[i] = xf.transform(this.verts[i]);
+ }
+ };
+ Poly.prototype.untransform = function (xf) {
+ for(var i = 0; i < this.verts.length; i++) {
+ this.verts[i] = xf.untransform(this.verts[i]);
+ }
+ };
+ Poly.prototype.area = function () {
+ return Advanced.Manager.areaForPoly(this.verts);
+ };
+ Poly.prototype.centroid = function () {
+ return Advanced.Manager.centroidForPoly(this.verts);
+ };
+ Poly.prototype.inertia = function (mass) {
+ return Advanced.Manager.inertiaForPoly(mass, this.verts, new Phaser.Vec2());
+ };
+ Poly.prototype.cacheData = function (xf) {
+ this.bounds.clear();
+ var numVerts = this.verts.length;
+ //console.log('shapePoly cacheData', numVerts);
+ if(numVerts == 0) {
+ return;
+ }
+ for(var i = 0; i < numVerts; i++) {
+ Phaser.TransformUtils.transform(xf, this.tverts[i], this.tverts[i]);
+ //this.tverts[i] = xf.transform(this.verts[i]);
+ }
+ if(numVerts < 2) {
+ this.bounds.addPoint(this.tverts[0]);
+ return;
+ }
+ for(var i = 0; i < numVerts; i++) {
+ var a = this.tverts[i];
+ var b = this.tverts[(i + 1) % numVerts];
+ var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
+ this.tplanes[i].n = n;
+ this.tplanes[i].d = Phaser.Vec2Utils.dot(n, a);
+ this.bounds.addPoint(a);
+ }
+ };
+ Poly.prototype.pointQuery = function (p) {
+ if(!this.bounds.containPoint(p)) {
+ return false;
+ }
+ return this.containPoint(p);
+ };
+ Poly.prototype.findVertexByPoint = function (p, minDist) {
+ var dsq = minDist * minDist;
+ for(var i = 0; i < this.tverts.length; i++) {
+ if(Phaser.Vec2Utils.distanceSq(this.tverts[i], p) < dsq) {
+ return i;
+ }
+ }
+ return -1;
+ };
+ Poly.prototype.findEdgeByPoint = function (p, minDist) {
+ var dsq = minDist * minDist;
+ var numVerts = this.tverts.length;
+ for(var i = 0; i < this.tverts.length; i++) {
+ var v1 = this.tverts[i];
+ var v2 = this.tverts[(i + 1) % numVerts];
+ var n = this.tplanes[i].n;
+ var dtv1 = Phaser.Vec2Utils.cross(v1, n);
+ var dtv2 = Phaser.Vec2Utils.cross(v2, n);
+ var dt = Phaser.Vec2Utils.cross(p, n);
+ if(dt > dtv1) {
+ if(Phaser.Vec2Utils.distanceSq(v1, p) < dsq) {
+ return i;
+ }
+ } else if(dt < dtv2) {
+ if(Phaser.Vec2Utils.distanceSq(v2, p) < dsq) {
+ return i;
+ }
+ } else {
+ var dist = Phaser.Vec2Utils.dot(n, p) - Phaser.Vec2Utils.dot(n, v1);
+ if(dist * dist < dsq) {
+ return i;
+ }
+ }
+ }
+ return -1;
+ };
+ Poly.prototype.distanceOnPlane = function (n, d) {
+ var min = 999999;
+ for(var i = 0; i < this.verts.length; i++) {
+ min = Math.min(min, Phaser.Vec2Utils.dot(n, this.tverts[i]));
+ }
+ return min - d;
+ };
+ Poly.prototype.containPoint = function (p) {
+ for(var i = 0; i < this.verts.length; i++) {
+ var plane = this.tplanes[i];
+ if(Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0) {
+ return false;
+ }
+ }
+ return true;
+ };
+ Poly.prototype.containPointPartial = function (p, n) {
+ for(var i = 0; i < this.verts.length; i++) {
+ var plane = this.tplanes[i];
+ if(Phaser.Vec2Utils.dot(plane.n, n) < 0.0001) {
+ continue;
+ }
+ if(Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0) {
+ return false;
+ }
+ }
+ return true;
+ };
+ return Poly;
+ })(Phaser.Physics.Advanced.Shape);
+ Shapes.Poly = Poly;
+ })(Advanced.Shapes || (Advanced.Shapes = {}));
+ var Shapes = Advanced.Shapes;
+ })(Physics.Advanced || (Physics.Advanced = {}));
+ var Advanced = Physics.Advanced;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Advanced) {
+ ///
+ ///
+ ///
+ ///
+ ///
+ /**
+ * Phaser - Advanced Physics - Shapes - Segment
+ *
+ * Based on the work Ju Hyung Lee started in JS PhyRus.
+ */
+ (function (Shapes) {
+ var Segment = (function (_super) {
+ __extends(Segment, _super);
+ function Segment(a, b, radius) {
+ _super.call(this, Advanced.Manager.SHAPE_TYPE_SEGMENT);
+ this.a = a.duplicate();
+ this.b = b.duplicate();
+ this.radius = radius;
+ this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(b, a));
+ this.normal.normalize();
+ this.ta = new Phaser.Vec2();
+ this.tb = new Phaser.Vec2();
+ this.tn = new Phaser.Vec2();
+ this.finishVerts();
+ }
+ Segment.prototype.finishVerts = function () {
+ this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.b, this.a));
+ this.normal.normalize();
+ this.radius = Math.abs(this.radius);
+ };
+ Segment.prototype.duplicate = function () {
+ return new Phaser.Physics.Advanced.Shapes.Segment(this.a, this.b, this.radius);
+ };
+ Segment.prototype.recenter = function (c) {
+ this.a.subtract(c);
+ this.b.subtract(c);
+ };
+ Segment.prototype.transform = function (xf) {
+ Phaser.TransformUtils.transform(xf, this.a, this.a);
+ Phaser.TransformUtils.transform(xf, this.b, this.b);
+ //this.a = xf.transform(this.a);
+ //this.b = xf.transform(this.b);
+ };
+ Segment.prototype.untransform = function (xf) {
+ Phaser.TransformUtils.untransform(xf, this.a, this.a);
+ Phaser.TransformUtils.untransform(xf, this.b, this.b);
+ //this.a = xf.untransform(this.a);
+ //this.b = xf.untransform(this.b);
+ };
+ Segment.prototype.area = function () {
+ return Advanced.Manager.areaForSegment(this.a, this.b, this.radius);
+ };
+ Segment.prototype.centroid = function () {
+ return Advanced.Manager.centroidForSegment(this.a, this.b);
+ };
+ Segment.prototype.inertia = function (mass) {
+ return Advanced.Manager.inertiaForSegment(mass, this.a, this.b);
+ };
+ Segment.prototype.cacheData = function (xf) {
+ Phaser.TransformUtils.transform(xf, this.a, this.ta);
+ Phaser.TransformUtils.transform(xf, this.b, this.tb);
+ //this.ta = xf.transform(this.a);
+ //this.tb = xf.transform(this.b);
+ this.tn = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.tb, this.ta)).normalize();
+ var l;
+ var r;
+ var t;
+ var b;
+ if(this.ta.x < this.tb.x) {
+ l = this.ta.x;
+ r = this.tb.x;
+ } else {
+ l = this.tb.x;
+ r = this.ta.x;
+ }
+ if(this.ta.y < this.tb.y) {
+ b = this.ta.y;
+ t = this.tb.y;
+ } else {
+ b = this.tb.y;
+ t = this.ta.y;
+ }
+ this.bounds.mins.setTo(l - this.radius, b - this.radius);
+ this.bounds.maxs.setTo(r + this.radius, t + this.radius);
+ };
+ Segment.prototype.pointQuery = function (p) {
+ if(!this.bounds.containPoint(p)) {
+ return false;
+ }
+ var dn = Phaser.Vec2Utils.dot(this.tn, p) - Phaser.Vec2Utils.dot(this.ta, this.tn);
+ var dist = Math.abs(dn);
+ if(dist > this.radius) {
+ return false;
+ }
+ var dt = Phaser.Vec2Utils.cross(p, this.tn);
+ var dta = Phaser.Vec2Utils.cross(this.ta, this.tn);
+ var dtb = Phaser.Vec2Utils.cross(this.tb, this.tn);
+ if(dt <= dta) {
+ if(dt < dta - this.radius) {
+ return false;
+ }
+ return Phaser.Vec2Utils.distanceSq(this.ta, p) < (this.radius * this.radius);
+ } else if(dt > dtb) {
+ if(dt > dtb + this.radius) {
+ return false;
+ }
+ return Phaser.Vec2Utils.distanceSq(this.tb, p) < (this.radius * this.radius);
+ }
+ return true;
+ };
+ Segment.prototype.findVertexByPoint = function (p, minDist) {
+ var dsq = minDist * minDist;
+ if(Phaser.Vec2Utils.distanceSq(this.ta, p) < dsq) {
+ return 0;
+ }
+ if(Phaser.Vec2Utils.distanceSq(this.tb, p) < dsq) {
+ return 1;
+ }
+ return -1;
+ };
+ Segment.prototype.distanceOnPlane = function (n, d) {
+ var a = Phaser.Vec2Utils.dot(n, this.ta) - this.radius;
+ var b = Phaser.Vec2Utils.dot(n, this.tb) - this.radius;
+ return Math.min(a, b) - d;
+ };
+ return Segment;
+ })(Phaser.Physics.Advanced.Shape);
+ Shapes.Segment = Segment;
+ })(Advanced.Shapes || (Advanced.Shapes = {}));
+ var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
@@ -19912,11 +20250,13 @@ var Phaser;
///
///
///
+ ///
+ ///
+ ///
+ ///
///
///
- ///
///
- ///
/**
* Phaser - Advanced Physics - Collision Handlers
*
@@ -19927,7 +20267,6 @@ var Phaser;
function Collision() {
}
Collision.prototype.collide = function (a, b, contacts) {
- //console.log('collide', a.type, b.type);
// Circle (a is the circle)
if(a.type == Advanced.Manager.SHAPE_TYPE_CIRCLE) {
if(b.type == Advanced.Manager.SHAPE_TYPE_CIRCLE) {
@@ -19982,10 +20321,10 @@ var Phaser;
return 1;
};
Collision.prototype.circle2Circle = function (circ1, circ2, contactArr) {
- return this._circle2Circle(circ1.tc, circ1.r, circ2.tc, circ2.r, contactArr);
+ return this._circle2Circle(circ1.tc, circ1.radius, circ2.tc, circ2.radius, contactArr);
};
Collision.prototype.circle2Segment = function (circ, seg, contactArr) {
- var rsum = circ.radius + seg.r;
+ var rsum = circ.radius + seg.radius;
// Normal distance from segment
var dn = Phaser.Vec2Utils.dot(circ.tc, seg.tn) - Phaser.Vec2Utils.dot(seg.ta, seg.tn);
var dist = (dn < 0 ? dn * -1 : dn) - rsum;
@@ -20000,12 +20339,12 @@ var Phaser;
if(dt < dtMin - rsum) {
return 0;
}
- return this._circle2Circle(circ.tc, circ.radius, seg.ta, seg.r, contactArr);
+ return this._circle2Circle(circ.tc, circ.radius, seg.ta, seg.radius, contactArr);
} else if(dt > dtMax) {
if(dt > dtMax + rsum) {
return 0;
}
- return this._circle2Circle(circ.tc, circ.radius, seg.tb, seg.r, contactArr);
+ return this._circle2Circle(circ.tc, circ.radius, seg.tb, seg.radius, contactArr);
}
var n = new Phaser.Vec2();
if(dn > 0) {
@@ -20108,7 +20447,7 @@ var Phaser;
}
var minp1 = Phaser.Vec2Utils.multiplyAdd(seg1.ta, u, s);
var minp2 = Phaser.Vec2Utils.multiplyAdd(seg2.ta, v, t);
- return this._circle2Circle(minp1, seg1.r, minp2, seg2.r, contactArr);
+ return this._circle2Circle(minp1, seg1.radius, minp2, seg2.radius, contactArr);
};
Collision.prototype.findPointsBehindSeg = // Identify vertexes that have penetrated the segment.
function (contactArr, seg, poly, dist, coef) {
@@ -20119,7 +20458,7 @@ var Phaser;
//var n = vec2.scale(seg.tn, coef);
for(var i = 0; i < poly.verts.length; i++) {
var v = poly.tverts[i];
- if(Phaser.Vec2Utils.dot(v, n) < Phaser.Vec2Utils.dot(seg.tn, seg.ta) * coef + seg.r) {
+ if(Phaser.Vec2Utils.dot(v, n) < Phaser.Vec2Utils.dot(seg.tn, seg.ta) * coef + seg.radius) {
var dt = Phaser.Vec2Utils.cross(seg.tn, v);
if(dta >= dt && dt >= dtb) {
contactArr.push(new Advanced.Contact(v, n, dist, (poly.id << 16) | i));
@@ -20129,13 +20468,13 @@ var Phaser;
};
Collision.prototype.segment2Poly = function (seg, poly, contactArr) {
var seg_td = Phaser.Vec2Utils.dot(seg.tn, seg.ta);
- var seg_d1 = poly.distanceOnPlane(seg.tn, seg_td) - seg.r;
+ var seg_d1 = poly.distanceOnPlane(seg.tn, seg_td) - seg.radius;
if(seg_d1 > 0) {
return 0;
}
var n = new Phaser.Vec2();
Phaser.Vec2Utils.negative(seg.tn, n);
- var seg_d2 = poly.distanceOnPlane(n, -seg_td) - seg.r;
+ var seg_d2 = poly.distanceOnPlane(n, -seg_td) - seg.radius;
//var seg_d2 = poly.distanceOnPlane(vec2.neg(seg.tn), -seg_td) - seg.r;
if(seg_d2 > 0) {
return 0;
@@ -20157,10 +20496,10 @@ var Phaser;
Phaser.Vec2Utils.negative(poly.tplanes[poly_i].n, poly_n);
//var poly_n = vec2.neg(poly.tplanes[poly_i].n);
var va = new Phaser.Vec2();
- Phaser.Vec2Utils.multiplyAdd(seg.ta, poly_n, seg.r, va);
+ Phaser.Vec2Utils.multiplyAdd(seg.ta, poly_n, seg.radius, va);
//var va = vec2.mad(seg.ta, poly_n, seg.r);
var vb = new Phaser.Vec2();
- Phaser.Vec2Utils.multiplyAdd(seg.tb, poly_n, seg.r, vb);
+ Phaser.Vec2Utils.multiplyAdd(seg.tb, poly_n, seg.radius, vb);
//var vb = vec2.mad(seg.tb, poly_n, seg.r);
if(poly.containPoint(va)) {
contactArr.push(new Advanced.Contact(va, poly_n, poly_d, (seg.id << 16) | 0));
@@ -20182,16 +20521,16 @@ var Phaser;
if(contactArr.length == 0) {
var poly_a = poly.tverts[poly_i];
var poly_b = poly.tverts[(poly_i + 1) % poly.verts.length];
- if(this._circle2Circle(seg.ta, seg.r, poly_a, 0, contactArr)) {
+ if(this._circle2Circle(seg.ta, seg.radius, poly_a, 0, contactArr)) {
return 1;
}
- if(this._circle2Circle(seg.tb, seg.r, poly_a, 0, contactArr)) {
+ if(this._circle2Circle(seg.tb, seg.radius, poly_a, 0, contactArr)) {
return 1;
}
- if(this._circle2Circle(seg.ta, seg.r, poly_b, 0, contactArr)) {
+ if(this._circle2Circle(seg.ta, seg.radius, poly_b, 0, contactArr)) {
return 1;
}
- if(this._circle2Circle(seg.tb, seg.r, poly_b, 0, contactArr)) {
+ if(this._circle2Circle(seg.tb, seg.radius, poly_b, 0, contactArr)) {
return 1;
}
}
@@ -20290,7 +20629,6 @@ var Phaser;
(function (Phaser) {
(function (Physics) {
///
- ///
///
///
///
@@ -21187,420 +21525,6 @@ var Phaser;
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
-(function (Phaser) {
- (function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - ShapePoly (convex only)
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
- (function (Advanced) {
- var ShapePoly = (function (_super) {
- __extends(ShapePoly, _super);
- function ShapePoly(verts) {
- console.log('ShapePoly created', verts);
- _super.call(this, Advanced.Manager.SHAPE_TYPE_POLY);
- this.verts = [];
- this.planes = [];
- this.tverts = [];
- this.tplanes = [];
- if(verts) {
- for(var i = 0; i < verts.length; i++) {
- //console.log('cloning vert', i);
- this.verts[i] = Phaser.Vec2Utils.clone(verts[i]);
- this.tverts[i] = this.verts[i];
- this.tplanes[i] = {
- };
- this.tplanes[i].n = new Phaser.Vec2();
- this.tplanes[i].d = 0;
- }
- }
- //console.log('ShapePoly finished', this.verts);
- this.finishVerts();
- //console.log('ShapePoly finished 2', this.verts);
- }
- ShapePoly.prototype.finishVerts = function () {
- if(this.verts.length < 2) {
- this.convexity = false;
- this.planes = [];
- return;
- }
- this.convexity = true;
- this.tverts = [];
- this.tplanes = [];
- // Must be counter-clockwise verts
- for(var i = 0; i < this.verts.length; i++) {
- var a = this.verts[i];
- var b = this.verts[(i + 1) % this.verts.length];
- var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
- this.planes[i] = {
- };
- this.planes[i].n = n;
- this.planes[i].d = Phaser.Vec2Utils.dot(n, a);
- this.tverts[i] = this.verts[i];
- this.tplanes[i] = {
- };
- this.tplanes[i].n = new Phaser.Vec2();
- this.tplanes[i].d = 0;
- }
- for(var i = 0; i < this.verts.length; i++) {
- var b = this.verts[(i + 2) % this.verts.length];
- var n = this.planes[i].n;
- var d = this.planes[i].d;
- if(Phaser.Vec2Utils.dot(n, b) - d > 0) {
- this.convexity = false;
- }
- }
- };
- ShapePoly.prototype.duplicate = function () {
- return new ShapePoly(this.verts);
- };
- ShapePoly.prototype.recenter = function (c) {
- for(var i = 0; i < this.verts.length; i++) {
- this.verts[i].subtract(c);
- }
- };
- ShapePoly.prototype.transform = function (xf) {
- for(var i = 0; i < this.verts.length; i++) {
- this.verts[i] = xf.transform(this.verts[i]);
- }
- };
- ShapePoly.prototype.untransform = function (xf) {
- for(var i = 0; i < this.verts.length; i++) {
- this.verts[i] = xf.untransform(this.verts[i]);
- }
- };
- ShapePoly.prototype.area = function () {
- return Advanced.Manager.areaForPoly(this.verts);
- };
- ShapePoly.prototype.centroid = function () {
- return Advanced.Manager.centroidForPoly(this.verts);
- };
- ShapePoly.prototype.inertia = function (mass) {
- return Advanced.Manager.inertiaForPoly(mass, this.verts, new Phaser.Vec2());
- };
- ShapePoly.prototype.cacheData = function (xf) {
- this.bounds.clear();
- var numVerts = this.verts.length;
- //console.log('shapePoly cacheData', numVerts);
- if(numVerts == 0) {
- return;
- }
- for(var i = 0; i < numVerts; i++) {
- Phaser.TransformUtils.transform(xf, this.tverts[i], this.tverts[i]);
- //this.tverts[i] = xf.transform(this.verts[i]);
- }
- if(numVerts < 2) {
- this.bounds.addPoint(this.tverts[0]);
- return;
- }
- for(var i = 0; i < numVerts; i++) {
- var a = this.tverts[i];
- var b = this.tverts[(i + 1) % numVerts];
- var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
- this.tplanes[i].n = n;
- this.tplanes[i].d = Phaser.Vec2Utils.dot(n, a);
- this.bounds.addPoint(a);
- }
- };
- ShapePoly.prototype.pointQuery = function (p) {
- if(!this.bounds.containPoint(p)) {
- return false;
- }
- return this.containPoint(p);
- };
- ShapePoly.prototype.findVertexByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- for(var i = 0; i < this.tverts.length; i++) {
- if(Phaser.Vec2Utils.distanceSq(this.tverts[i], p) < dsq) {
- return i;
- }
- }
- return -1;
- };
- ShapePoly.prototype.findEdgeByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- var numVerts = this.tverts.length;
- for(var i = 0; i < this.tverts.length; i++) {
- var v1 = this.tverts[i];
- var v2 = this.tverts[(i + 1) % numVerts];
- var n = this.tplanes[i].n;
- var dtv1 = Phaser.Vec2Utils.cross(v1, n);
- var dtv2 = Phaser.Vec2Utils.cross(v2, n);
- var dt = Phaser.Vec2Utils.cross(p, n);
- if(dt > dtv1) {
- if(Phaser.Vec2Utils.distanceSq(v1, p) < dsq) {
- return i;
- }
- } else if(dt < dtv2) {
- if(Phaser.Vec2Utils.distanceSq(v2, p) < dsq) {
- return i;
- }
- } else {
- var dist = Phaser.Vec2Utils.dot(n, p) - Phaser.Vec2Utils.dot(n, v1);
- if(dist * dist < dsq) {
- return i;
- }
- }
- }
- return -1;
- };
- ShapePoly.prototype.distanceOnPlane = function (n, d) {
- var min = 999999;
- for(var i = 0; i < this.verts.length; i++) {
- min = Math.min(min, Phaser.Vec2Utils.dot(n, this.tverts[i]));
- }
- return min - d;
- };
- ShapePoly.prototype.containPoint = function (p) {
- for(var i = 0; i < this.verts.length; i++) {
- var plane = this.tplanes[i];
- if(Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0) {
- return false;
- }
- }
- return true;
- };
- ShapePoly.prototype.containPointPartial = function (p, n) {
- for(var i = 0; i < this.verts.length; i++) {
- var plane = this.tplanes[i];
- if(Phaser.Vec2Utils.dot(plane.n, n) < 0.0001) {
- continue;
- }
- if(Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0) {
- return false;
- }
- }
- return true;
- };
- return ShapePoly;
- })(Phaser.Physics.Advanced.Shape);
- Advanced.ShapePoly = ShapePoly;
- })(Physics.Advanced || (Physics.Advanced = {}));
- var Advanced = Physics.Advanced;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - ShapeBox
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
- (function (Advanced) {
- var ShapeBox = (function (_super) {
- __extends(ShapeBox, _super);
- // Give in pixels
- function ShapeBox(x, y, width, height) {
- console.log('creating box', x, y, width, height);
- x = Advanced.Manager.pixelsToMeters(x);
- y = Advanced.Manager.pixelsToMeters(y);
- width = Advanced.Manager.pixelsToMeters(width);
- height = Advanced.Manager.pixelsToMeters(height);
- var hw = width * 0.5;
- var hh = height * 0.5;
- _super.call(this, [
- new Phaser.Vec2(-hw + x, +hh + y),
- new Phaser.Vec2(-hw + x, -hh + y),
- new Phaser.Vec2(+hw + x, -hh + y),
- new Phaser.Vec2(+hw + x, +hh + y)
- ]);
- }
- return ShapeBox;
- })(Phaser.Physics.Advanced.ShapePoly);
- Advanced.ShapeBox = ShapeBox;
- })(Physics.Advanced || (Physics.Advanced = {}));
- var Advanced = Physics.Advanced;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - Shape
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
- (function (Advanced) {
- var ShapeSegment = (function (_super) {
- __extends(ShapeSegment, _super);
- function ShapeSegment(a, b, radius) {
- _super.call(this, Advanced.Manager.SHAPE_TYPE_SEGMENT);
- // What types are A and B??!
- this.a = a.duplicate();
- this.b = b.duplicate();
- this.radius = radius;
- this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(b, a));
- this.normal.normalize();
- this.ta = new Phaser.Vec2();
- this.tb = new Phaser.Vec2();
- this.tn = new Phaser.Vec2();
- this.finishVerts();
- }
- ShapeSegment.prototype.finishVerts = function () {
- this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.b, this.a));
- this.normal.normalize();
- this.radius = Math.abs(this.radius);
- };
- ShapeSegment.prototype.duplicate = function () {
- return new ShapeSegment(this.a, this.b, this.radius);
- };
- ShapeSegment.prototype.recenter = function (c) {
- this.a.subtract(c);
- this.b.subtract(c);
- };
- ShapeSegment.prototype.transform = function (xf) {
- Phaser.TransformUtils.transform(xf, this.a, this.a);
- Phaser.TransformUtils.transform(xf, this.b, this.b);
- //this.a = xf.transform(this.a);
- //this.b = xf.transform(this.b);
- };
- ShapeSegment.prototype.untransform = function (xf) {
- Phaser.TransformUtils.untransform(xf, this.a, this.a);
- Phaser.TransformUtils.untransform(xf, this.b, this.b);
- //this.a = xf.untransform(this.a);
- //this.b = xf.untransform(this.b);
- };
- ShapeSegment.prototype.area = function () {
- return Advanced.Manager.areaForSegment(this.a, this.b, this.radius);
- };
- ShapeSegment.prototype.centroid = function () {
- return Advanced.Manager.centroidForSegment(this.a, this.b);
- };
- ShapeSegment.prototype.inertia = function (mass) {
- return Advanced.Manager.inertiaForSegment(mass, this.a, this.b);
- };
- ShapeSegment.prototype.cacheData = function (xf) {
- Phaser.TransformUtils.transform(xf, this.a, this.ta);
- Phaser.TransformUtils.transform(xf, this.b, this.tb);
- //this.ta = xf.transform(this.a);
- //this.tb = xf.transform(this.b);
- this.tn = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.tb, this.ta)).normalize();
- var l;
- var r;
- var t;
- var b;
- if(this.ta.x < this.tb.x) {
- l = this.ta.x;
- r = this.tb.x;
- } else {
- l = this.tb.x;
- r = this.ta.x;
- }
- if(this.ta.y < this.tb.y) {
- b = this.ta.y;
- t = this.tb.y;
- } else {
- b = this.tb.y;
- t = this.ta.y;
- }
- this.bounds.mins.setTo(l - this.radius, b - this.radius);
- this.bounds.maxs.setTo(r + this.radius, t + this.radius);
- };
- ShapeSegment.prototype.pointQuery = function (p) {
- if(!this.bounds.containPoint(p)) {
- return false;
- }
- var dn = Phaser.Vec2Utils.dot(this.tn, p) - Phaser.Vec2Utils.dot(this.ta, this.tn);
- var dist = Math.abs(dn);
- if(dist > this.radius) {
- return false;
- }
- var dt = Phaser.Vec2Utils.cross(p, this.tn);
- var dta = Phaser.Vec2Utils.cross(this.ta, this.tn);
- var dtb = Phaser.Vec2Utils.cross(this.tb, this.tn);
- if(dt <= dta) {
- if(dt < dta - this.radius) {
- return false;
- }
- return Phaser.Vec2Utils.distanceSq(this.ta, p) < (this.radius * this.radius);
- } else if(dt > dtb) {
- if(dt > dtb + this.radius) {
- return false;
- }
- return Phaser.Vec2Utils.distanceSq(this.tb, p) < (this.radius * this.radius);
- }
- return true;
- };
- ShapeSegment.prototype.findVertexByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- if(Phaser.Vec2Utils.distanceSq(this.ta, p) < dsq) {
- return 0;
- }
- if(Phaser.Vec2Utils.distanceSq(this.tb, p) < dsq) {
- return 1;
- }
- return -1;
- };
- ShapeSegment.prototype.distanceOnPlane = function (n, d) {
- var a = Phaser.Vec2Utils.dot(n, this.ta) - this.radius;
- var b = Phaser.Vec2Utils.dot(n, this.tb) - this.radius;
- return Math.min(a, b) - d;
- };
- return ShapeSegment;
- })(Phaser.Physics.Advanced.Shape);
- Advanced.ShapeSegment = ShapeSegment;
- })(Physics.Advanced || (Physics.Advanced = {}));
- var Advanced = Physics.Advanced;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - ShapeTriangle
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
- (function (Advanced) {
- var ShapeTriangle = (function (_super) {
- __extends(ShapeTriangle, _super);
- function ShapeTriangle(p1, p2, p3) {
- _super.call(this, [
- new Phaser.Vec2(p1.x, p1.y),
- new Phaser.Vec2(p2.x, p2.y),
- new Phaser.Vec2(p3.x, p3.y)
- ]);
- }
- return ShapeTriangle;
- })(Phaser.Physics.Advanced.ShapePoly);
- Advanced.ShapeTriangle = ShapeTriangle;
- })(Physics.Advanced || (Physics.Advanced = {}));
- var Advanced = Physics.Advanced;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
(function (Phaser) {
(function (Physics) {
(function (Advanced) {
@@ -21608,7 +21532,7 @@ var Phaser;
///
///
///
- ///
+ ///
/**
* Phaser - Advanced Physics - Shapes - Box
*
@@ -21633,7 +21557,7 @@ var Phaser;
]);
}
return Box;
- })(Phaser.Physics.Advanced.ShapePoly);
+ })(Phaser.Physics.Advanced.Shapes.Poly);
Shapes.Box = Box;
})(Advanced.Shapes || (Advanced.Shapes = {}));
var Shapes = Advanced.Shapes;
@@ -21647,76 +21571,28 @@ var Phaser;
(function (Physics) {
(function (Advanced) {
///
- ///
///
///
///
+ ///
/**
- * Phaser - Advanced Physics - Shape - Circle
+ * Phaser - Advanced Physics - Shapes - Triangle
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
(function (Shapes) {
- var Circle = (function (_super) {
- __extends(Circle, _super);
- function Circle(radius, x, y) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- _super.call(this, Advanced.Manager.SHAPE_TYPE_CIRCLE);
- this.center = new Phaser.Vec2(x, y);
- this.radius = radius;
- this.tc = new Phaser.Vec2();
- this.finishVerts();
+ var Triangle = (function (_super) {
+ __extends(Triangle, _super);
+ function Triangle(p1, p2, p3) {
+ _super.call(this, [
+ new Phaser.Vec2(p1.x, p1.y),
+ new Phaser.Vec2(p2.x, p2.y),
+ new Phaser.Vec2(p3.x, p3.y)
+ ]);
}
- Circle.prototype.finishVerts = function () {
- this.radius = Math.abs(this.radius);
- };
- Circle.prototype.duplicate = function () {
- return new Advanced.ShapeCircle(this.center.x, this.center.y, this.radius);
- };
- Circle.prototype.recenter = function (c) {
- this.center.subtract(c);
- };
- Circle.prototype.transform = function (xf) {
- Phaser.TransformUtils.transform(xf, this.center, this.center);
- //this.center = xf.transform(this.center);
- };
- Circle.prototype.untransform = function (xf) {
- Phaser.TransformUtils.untransform(xf, this.center, this.center);
- //this.center = xf.untransform(this.center);
- };
- Circle.prototype.area = function () {
- return Advanced.Manager.areaForCircle(this.radius, 0);
- };
- Circle.prototype.centroid = function () {
- return Phaser.Vec2Utils.clone(this.center);
- };
- Circle.prototype.inertia = function (mass) {
- return Advanced.Manager.inertiaForCircle(mass, this.center, this.radius, 0);
- };
- Circle.prototype.cacheData = function (xf) {
- Phaser.TransformUtils.transform(xf, this.center, this.tc);
- //this.tc = xf.transform(this.center);
- this.bounds.mins.setTo(this.tc.x - this.radius, this.tc.y - this.radius);
- this.bounds.maxs.setTo(this.tc.x + this.radius, this.tc.y + this.radius);
- };
- Circle.prototype.pointQuery = function (p) {
- //return vec2.distsq(this.tc, p) < (this.r * this.r);
- return Phaser.Vec2Utils.distanceSq(this.tc, p) < (this.radius * this.radius);
- };
- Circle.prototype.findVertexByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- if(Phaser.Vec2Utils.distanceSq(this.tc, p) < dsq) {
- return 0;
- }
- return -1;
- };
- Circle.prototype.distanceOnPlane = function (n, d) {
- Phaser.Vec2Utils.dot(n, this.tc) - this.radius - d;
- };
- return Circle;
- })(Phaser.Physics.Advanced.Shape);
- Shapes.Circle = Circle;
+ return Triangle;
+ })(Phaser.Physics.Advanced.Shapes.Poly);
+ Shapes.Triangle = Triangle;
})(Advanced.Shapes || (Advanced.Shapes = {}));
var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
@@ -21724,367 +21600,6 @@ var Phaser;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Advanced) {
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - Shapes - Convex Polygon
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
- (function (Shapes) {
- var Poly = (function (_super) {
- __extends(Poly, _super);
- function Poly(verts) {
- _super.call(this, Advanced.Manager.SHAPE_TYPE_POLY);
- this.verts = [];
- this.planes = [];
- this.tverts = [];
- this.tplanes = [];
- if(verts) {
- for(var i = 0; i < verts.length; i++) {
- this.verts[i] = Phaser.Vec2Utils.clone(verts[i]);
- this.tverts[i] = this.verts[i];
- this.tplanes[i] = {
- };
- this.tplanes[i].n = new Phaser.Vec2();
- this.tplanes[i].d = 0;
- }
- }
- this.finishVerts();
- }
- Poly.prototype.finishVerts = function () {
- if(this.verts.length < 2) {
- this.convexity = false;
- this.planes = [];
- return;
- }
- this.convexity = true;
- this.tverts = [];
- this.tplanes = [];
- // Must be counter-clockwise verts
- for(var i = 0; i < this.verts.length; i++) {
- var a = this.verts[i];
- var b = this.verts[(i + 1) % this.verts.length];
- var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
- this.planes[i] = {
- };
- this.planes[i].n = n;
- this.planes[i].d = Phaser.Vec2Utils.dot(n, a);
- this.tverts[i] = this.verts[i];
- this.tplanes[i] = {
- };
- this.tplanes[i].n = new Phaser.Vec2();
- this.tplanes[i].d = 0;
- }
- for(var i = 0; i < this.verts.length; i++) {
- var b = this.verts[(i + 2) % this.verts.length];
- var n = this.planes[i].n;
- var d = this.planes[i].d;
- if(Phaser.Vec2Utils.dot(n, b) - d > 0) {
- this.convexity = false;
- }
- }
- };
- Poly.prototype.duplicate = function () {
- return new Advanced.ShapePoly(this.verts);
- };
- Poly.prototype.recenter = function (c) {
- for(var i = 0; i < this.verts.length; i++) {
- this.verts[i].subtract(c);
- }
- };
- Poly.prototype.transform = function (xf) {
- for(var i = 0; i < this.verts.length; i++) {
- this.verts[i] = xf.transform(this.verts[i]);
- }
- };
- Poly.prototype.untransform = function (xf) {
- for(var i = 0; i < this.verts.length; i++) {
- this.verts[i] = xf.untransform(this.verts[i]);
- }
- };
- Poly.prototype.area = function () {
- return Advanced.Manager.areaForPoly(this.verts);
- };
- Poly.prototype.centroid = function () {
- return Advanced.Manager.centroidForPoly(this.verts);
- };
- Poly.prototype.inertia = function (mass) {
- return Advanced.Manager.inertiaForPoly(mass, this.verts, new Phaser.Vec2());
- };
- Poly.prototype.cacheData = function (xf) {
- this.bounds.clear();
- var numVerts = this.verts.length;
- //console.log('shapePoly cacheData', numVerts);
- if(numVerts == 0) {
- return;
- }
- for(var i = 0; i < numVerts; i++) {
- Phaser.TransformUtils.transform(xf, this.tverts[i], this.tverts[i]);
- //this.tverts[i] = xf.transform(this.verts[i]);
- }
- if(numVerts < 2) {
- this.bounds.addPoint(this.tverts[0]);
- return;
- }
- for(var i = 0; i < numVerts; i++) {
- var a = this.tverts[i];
- var b = this.tverts[(i + 1) % numVerts];
- var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
- this.tplanes[i].n = n;
- this.tplanes[i].d = Phaser.Vec2Utils.dot(n, a);
- this.bounds.addPoint(a);
- }
- };
- Poly.prototype.pointQuery = function (p) {
- if(!this.bounds.containPoint(p)) {
- return false;
- }
- return this.containPoint(p);
- };
- Poly.prototype.findVertexByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- for(var i = 0; i < this.tverts.length; i++) {
- if(Phaser.Vec2Utils.distanceSq(this.tverts[i], p) < dsq) {
- return i;
- }
- }
- return -1;
- };
- Poly.prototype.findEdgeByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- var numVerts = this.tverts.length;
- for(var i = 0; i < this.tverts.length; i++) {
- var v1 = this.tverts[i];
- var v2 = this.tverts[(i + 1) % numVerts];
- var n = this.tplanes[i].n;
- var dtv1 = Phaser.Vec2Utils.cross(v1, n);
- var dtv2 = Phaser.Vec2Utils.cross(v2, n);
- var dt = Phaser.Vec2Utils.cross(p, n);
- if(dt > dtv1) {
- if(Phaser.Vec2Utils.distanceSq(v1, p) < dsq) {
- return i;
- }
- } else if(dt < dtv2) {
- if(Phaser.Vec2Utils.distanceSq(v2, p) < dsq) {
- return i;
- }
- } else {
- var dist = Phaser.Vec2Utils.dot(n, p) - Phaser.Vec2Utils.dot(n, v1);
- if(dist * dist < dsq) {
- return i;
- }
- }
- }
- return -1;
- };
- Poly.prototype.distanceOnPlane = function (n, d) {
- var min = 999999;
- for(var i = 0; i < this.verts.length; i++) {
- min = Math.min(min, Phaser.Vec2Utils.dot(n, this.tverts[i]));
- }
- return min - d;
- };
- Poly.prototype.containPoint = function (p) {
- for(var i = 0; i < this.verts.length; i++) {
- var plane = this.tplanes[i];
- if(Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0) {
- return false;
- }
- }
- return true;
- };
- Poly.prototype.containPointPartial = function (p, n) {
- for(var i = 0; i < this.verts.length; i++) {
- var plane = this.tplanes[i];
- if(Phaser.Vec2Utils.dot(plane.n, n) < 0.0001) {
- continue;
- }
- if(Phaser.Vec2Utils.dot(plane.n, p) - plane.d > 0) {
- return false;
- }
- }
- return true;
- };
- return Poly;
- })(Phaser.Physics.Advanced.Shape);
- Shapes.Poly = Poly;
- })(Advanced.Shapes || (Advanced.Shapes = {}));
- var Shapes = Advanced.Shapes;
- })(Physics.Advanced || (Physics.Advanced = {}));
- var Advanced = Physics.Advanced;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Advanced) {
- ///
- ///
- ///
- ///
- ///
- /**
- * Phaser - Advanced Physics - Shapes - Segment
- *
- * Based on the work Ju Hyung Lee started in JS PhyRus.
- */
- (function (Shapes) {
- var Segment = (function (_super) {
- __extends(Segment, _super);
- function Segment(a, b, radius) {
- _super.call(this, Advanced.Manager.SHAPE_TYPE_SEGMENT);
- // What types are A and B??!
- this.a = a.duplicate();
- this.b = b.duplicate();
- this.radius = radius;
- this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(b, a));
- this.normal.normalize();
- this.ta = new Phaser.Vec2();
- this.tb = new Phaser.Vec2();
- this.tn = new Phaser.Vec2();
- this.finishVerts();
- }
- Segment.prototype.finishVerts = function () {
- this.normal = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.b, this.a));
- this.normal.normalize();
- this.radius = Math.abs(this.radius);
- };
- Segment.prototype.duplicate = function () {
- return new Advanced.ShapeSegment(this.a, this.b, this.radius);
- };
- Segment.prototype.recenter = function (c) {
- this.a.subtract(c);
- this.b.subtract(c);
- };
- Segment.prototype.transform = function (xf) {
- Phaser.TransformUtils.transform(xf, this.a, this.a);
- Phaser.TransformUtils.transform(xf, this.b, this.b);
- //this.a = xf.transform(this.a);
- //this.b = xf.transform(this.b);
- };
- Segment.prototype.untransform = function (xf) {
- Phaser.TransformUtils.untransform(xf, this.a, this.a);
- Phaser.TransformUtils.untransform(xf, this.b, this.b);
- //this.a = xf.untransform(this.a);
- //this.b = xf.untransform(this.b);
- };
- Segment.prototype.area = function () {
- return Advanced.Manager.areaForSegment(this.a, this.b, this.radius);
- };
- Segment.prototype.centroid = function () {
- return Advanced.Manager.centroidForSegment(this.a, this.b);
- };
- Segment.prototype.inertia = function (mass) {
- return Advanced.Manager.inertiaForSegment(mass, this.a, this.b);
- };
- Segment.prototype.cacheData = function (xf) {
- Phaser.TransformUtils.transform(xf, this.a, this.ta);
- Phaser.TransformUtils.transform(xf, this.b, this.tb);
- //this.ta = xf.transform(this.a);
- //this.tb = xf.transform(this.b);
- this.tn = Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(this.tb, this.ta)).normalize();
- var l;
- var r;
- var t;
- var b;
- if(this.ta.x < this.tb.x) {
- l = this.ta.x;
- r = this.tb.x;
- } else {
- l = this.tb.x;
- r = this.ta.x;
- }
- if(this.ta.y < this.tb.y) {
- b = this.ta.y;
- t = this.tb.y;
- } else {
- b = this.tb.y;
- t = this.ta.y;
- }
- this.bounds.mins.setTo(l - this.radius, b - this.radius);
- this.bounds.maxs.setTo(r + this.radius, t + this.radius);
- };
- Segment.prototype.pointQuery = function (p) {
- if(!this.bounds.containPoint(p)) {
- return false;
- }
- var dn = Phaser.Vec2Utils.dot(this.tn, p) - Phaser.Vec2Utils.dot(this.ta, this.tn);
- var dist = Math.abs(dn);
- if(dist > this.radius) {
- return false;
- }
- var dt = Phaser.Vec2Utils.cross(p, this.tn);
- var dta = Phaser.Vec2Utils.cross(this.ta, this.tn);
- var dtb = Phaser.Vec2Utils.cross(this.tb, this.tn);
- if(dt <= dta) {
- if(dt < dta - this.radius) {
- return false;
- }
- return Phaser.Vec2Utils.distanceSq(this.ta, p) < (this.radius * this.radius);
- } else if(dt > dtb) {
- if(dt > dtb + this.radius) {
- return false;
- }
- return Phaser.Vec2Utils.distanceSq(this.tb, p) < (this.radius * this.radius);
- }
- return true;
- };
- Segment.prototype.findVertexByPoint = function (p, minDist) {
- var dsq = minDist * minDist;
- if(Phaser.Vec2Utils.distanceSq(this.ta, p) < dsq) {
- return 0;
- }
- if(Phaser.Vec2Utils.distanceSq(this.tb, p) < dsq) {
- return 1;
- }
- return -1;
- };
- Segment.prototype.distanceOnPlane = function (n, d) {
- var a = Phaser.Vec2Utils.dot(n, this.ta) - this.radius;
- var b = Phaser.Vec2Utils.dot(n, this.tb) - this.radius;
- return Math.min(a, b) - d;
- };
- return Segment;
- })(Phaser.Physics.Advanced.Shape);
- Shapes.Segment = Segment;
- })(Advanced.Shapes || (Advanced.Shapes = {}));
- var Shapes = Advanced.Shapes;
- })(Physics.Advanced || (Physics.Advanced = {}));
- var Advanced = Physics.Advanced;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-// Module
-var Shapes;
-(function (Shapes) {
- // Class
- var Point = (function () {
- // Constructor
- function Point(x, y) {
- this.x = x;
- this.y = y;
- }
- Point.prototype.getDist = // Instance member
- function () {
- return Math.sqrt(this.x * this.x + this.y * this.y);
- };
- Point.origin = new Point(0, 0);
- return Point;
- })();
- Shapes.Point = Point;
-})(Shapes || (Shapes = {}));
-// Local variables
-var p = new Shapes.Point(3, 4);
-var dist = p.getDist();
///
///
///