@@ -69,6 +69,10 @@ module Phaser.Physics.Advanced {
6969
7070 }
7171
72+ public toString ( ) : string {
73+ return "[{Body (name=" + this . name + " velocity=" + this . velocity . toString ( ) + " angularVelocity: " + this . angularVelocity + ")}]" ;
74+ }
75+
7276 private _tempVec2 : Phaser . Vec2 = new Phaser . Vec2 ;
7377
7478 /**
@@ -305,25 +309,28 @@ module Phaser.Physics.Advanced {
305309
306310 this . transform . setTo ( pos , angle ) ;
307311 // inject the transform into this.position
312+ Manager . write ( 'setTransform: ' + this . position . toString ( ) ) ;
313+ Manager . write ( 'centroid: ' + this . centroid . toString ( ) ) ;
308314 Phaser . TransformUtils . transform ( this . transform , this . centroid , this . position ) ;
315+ Manager . write ( 'post setTransform: ' + this . position . toString ( ) ) ;
309316 //this.position.copyFrom(this.transform.transform(this.centroid));
310317 this . angle = angle ;
311318
312319 }
313320
314321 public syncTransform ( ) {
315322
323+ Manager . write ( 'syncTransform:' ) ;
324+ Manager . write ( 'p: ' + this . position . toString ( ) ) ;
325+ Manager . write ( 'centroid: ' + this . centroid . toString ( ) ) ;
326+ Manager . write ( 'xf: ' + this . transform . toString ( ) ) ;
327+ Manager . write ( 'a: ' + this . angle ) ;
316328 this . transform . setRotation ( this . angle ) ;
317-
318- //var rotc: Phaser.Vec2 = this.transform.rotate(this.centroid);
319- //var sub: Phaser.Vec2 = Phaser.Vec2Utils.subtract(this.position, rotc);
320- //this.transform.setPosition(sub);
321-
322- // this.transform.setPosition(vec2.sub(this.position, this.transform.rotate(this.centroid)));
323- //Phaser.Vec2Utils.subtract(this.position, this.transform.rotate(this.centroid), this.transform.t);
324-
325329 // OPTIMISE: Creating new vector
326330 Phaser . Vec2Utils . subtract ( this . position , Phaser . TransformUtils . rotate ( this . transform , this . centroid ) , this . transform . t ) ;
331+ Manager . write ( '--------------------' ) ;
332+ Manager . write ( 'xf: ' + this . transform . toString ( ) ) ;
333+ Manager . write ( '--------------------' ) ;
327334
328335 }
329336
@@ -332,17 +339,17 @@ module Phaser.Physics.Advanced {
332339 return Phaser . TransformUtils . transform ( this . transform , p ) ;
333340 }
334341
335- public getWorldVector ( v ) {
342+ public getWorldVector ( v : Phaser . Vec2 ) {
336343 // OPTIMISE: Creating new vector
337344 return Phaser . TransformUtils . rotate ( this . transform , v ) ;
338345 }
339346
340- public getLocalPoint ( p ) {
347+ public getLocalPoint ( p : Phaser . Vec2 ) {
341348 // OPTIMISE: Creating new vector
342349 return Phaser . TransformUtils . untransform ( this . transform , p ) ;
343350 }
344351
345- public getLocalVector ( v ) {
352+ public getLocalVector ( v : Phaser . Vec2 ) {
346353 // OPTIMISE: Creating new vector
347354 return Phaser . TransformUtils . unrotate ( this . transform , v ) ;
348355 }
@@ -430,21 +437,28 @@ module Phaser.Physics.Advanced {
430437 }
431438 }
432439
433- public cacheData ( ) {
440+ public cacheData ( source : string = '' ) {
434441
435- //console.log('Body cacheData', this.name, 'len', this.shapes.length);
442+ Manager . write ( 'cacheData -- start' ) ;
443+ Manager . write ( 'p: ' + this . position . toString ( ) ) ;
444+ Manager . write ( 'xf: ' + this . transform . toString ( ) ) ;
436445
437446 this . bounds . clear ( ) ;
438447
439448 for ( var i = 0 ; i < this . shapes . length ; i ++ )
440449 {
441- var shape = this . shapes [ i ] ;
450+ var shape : IShape = this . shapes [ i ] ;
442451 shape . cacheData ( this . transform ) ;
443452 this . bounds . addBounds ( shape . bounds ) ;
444453 }
445454
446- }
455+ Manager . write ( 'bounds: ' + this . bounds . toString ( ) ) ;
447456
457+ Manager . write ( 'p: ' + this . position . toString ( ) ) ;
458+ Manager . write ( 'xf: ' + this . transform . toString ( ) ) ;
459+ Manager . write ( 'cacheData -- stop' ) ;
460+
461+ }
448462
449463 public updateVelocity ( gravity , dt , damping ) {
450464
@@ -461,14 +475,44 @@ module Phaser.Physics.Advanced {
461475 // v2 = exp(-c * dt) * v1
462476 // Taylor expansion:
463477 // v2 = (1.0f - c * dt) * v1
464- this . velocity . scale ( this . game . math . clamp ( 1 - dt * ( damping + this . linearDamping ) , 0 , 1 ) ) ;
465- this . angularVelocity *= this . game . math . clamp ( 1 - dt * ( damping + this . angularDamping ) , 0 , 1 ) ;
478+ this . velocity . scale ( this . clamp ( 1 - dt * ( damping + this . linearDamping ) , 0 , 1 ) ) ;
479+ this . angularVelocity *= this . clamp ( 1 - dt * ( damping + this . angularDamping ) , 0 , 1 ) ;
466480
467481 this . force . setTo ( 0 , 0 ) ;
468482 this . torque = 0 ;
469483
470484 }
471485
486+ public inContact ( body2 : Body ) : bool {
487+
488+ if ( ! body2 || this . stepCount == body2 . stepCount )
489+ {
490+ return false ;
491+ }
492+
493+ if ( ! ( this . isAwake && this . isStatic == false ) && ! ( body2 . isAwake && body2 . isStatic == false ) )
494+ {
495+ return false ;
496+ }
497+
498+ if ( this . isCollidable ( body2 ) == false )
499+ {
500+ return false ;
501+ }
502+
503+ if ( ! this . bounds . intersectsBounds ( body2 . bounds ) )
504+ {
505+ return false ;
506+ }
507+
508+ return true ;
509+
510+ }
511+
512+ public clamp ( v , min , max ) {
513+ return v < min ? min : ( v > max ? max : v ) ;
514+ }
515+
472516 public updatePosition ( dt ) {
473517
474518 //console.log('body update pos', this.position.y);
@@ -489,7 +533,7 @@ module Phaser.Physics.Advanced {
489533 this . torque = 0 ;
490534 }
491535
492- public applyForce ( force , p ) {
536+ public applyForce ( force : Phaser . Vec2 , p : Phaser . Vec2 ) {
493537
494538 if ( this . isDynamic == false )
495539 {
@@ -511,7 +555,7 @@ module Phaser.Physics.Advanced {
511555
512556 }
513557
514- public applyForceToCenter ( force ) {
558+ public applyForceToCenter ( force : Phaser . Vec2 ) {
515559
516560 if ( this . isDynamic == false )
517561 {
@@ -527,7 +571,7 @@ module Phaser.Physics.Advanced {
527571
528572 }
529573
530- public applyTorque ( torque ) {
574+ public applyTorque ( torque : number ) {
531575
532576 if ( this . isDynamic == false )
533577 {
@@ -543,7 +587,7 @@ module Phaser.Physics.Advanced {
543587
544588 }
545589
546- public applyLinearImpulse ( impulse , p ) {
590+ public applyLinearImpulse ( impulse : Phaser . Vec2 , p : Phaser . Vec2 ) {
547591
548592 if ( this . isDynamic == false )
549593 {
@@ -560,6 +604,7 @@ module Phaser.Physics.Advanced {
560604 // this.angularVelocity += vec2.cross(vec2.sub(p, this.position), impulse) * this.inertiaInverted;
561605
562606 Phaser . Vec2Utils . subtract ( p , this . position , this . _tempVec2 ) ;
607+
563608 this . angularVelocity += Phaser . Vec2Utils . cross ( this . _tempVec2 , impulse ) * this . inertiaInverted ;
564609
565610 }
@@ -611,7 +656,7 @@ module Phaser.Physics.Advanced {
611656
612657 }
613658
614- public isCollidable ( other ) {
659+ public isCollidable ( other : Body ) {
615660
616661 if ( this == other )
617662 {
@@ -632,12 +677,7 @@ module Phaser.Physics.Advanced {
632677 {
633678 var joint = this . joints [ i ] ;
634679
635- if ( ! joint )
636- {
637- continue ;
638- }
639-
640- if ( ! joint . collideConnected && other . jointHash [ joint . id ] != undefined )
680+ if ( ! this . joints [ i ] || ( ! this . joints [ i ] . collideConnected && other . jointHash [ this . joints [ i ] . id ] != undefined ) )
641681 {
642682 return false ;
643683 }
0 commit comments