home *** CD-ROM | disk | FTP | other *** search
- class Pirrest.PhisicsEngine.AngularConstraint
- {
- var pA;
- var pB;
- var pC;
- var lineA;
- var lineB;
- var pD;
- var lineC;
- var targetTheta;
- var coeffStiff;
- function AngularConstraint($pA, $pB, $pC)
- {
- this.init($pA,$pB,$pC);
- }
- function init($pA, $pB, $pC)
- {
- this.pA = $pA.curr;
- this.pB = $pB.curr;
- this.pC = $pC.curr;
- this.lineA = new Pirrest.PhisicsEngine.Line(this.pA,this.pB);
- this.lineB = new Pirrest.PhisicsEngine.Line(this.pB,this.pC);
- this.pD = new Pirrest.PhisicsEngine.Vector(this.pB.x + 0,this.pB.y - 1);
- this.lineC = new Pirrest.PhisicsEngine.Line(this.pB,this.pD);
- this.targetTheta = this.calcTheta(this.pA,this.pB,this.pC);
- this.coeffStiff = 1;
- }
- function resolve()
- {
- var _loc5_ = this.getCentroid();
- this.lineC.p2.x = this.lineC.p1.x + 0;
- this.lineC.p2.y = this.lineC.p1.y - 1;
- var _loc9_ = this.pA.distance(this.pB);
- var _loc8_ = this.pB.distance(this.pC);
- var _loc12_ = this.calcTheta(this.pA,this.pB,this.pC);
- var _loc13_ = this.calcTheta(this.pA,this.pB,this.pD);
- var _loc11_ = this.calcTheta(this.pC,this.pB,this.pD);
- var _loc6_ = (this.targetTheta - _loc12_) / 2;
- var _loc10_ = _loc13_ + _loc6_ * this.coeffStiff;
- var _loc4_ = _loc11_ - _loc6_ * this.coeffStiff;
- this.pA.x = _loc9_ * Math.sin(_loc10_) + this.pB.x;
- this.pA.y = _loc9_ * Math.cos(_loc10_) + this.pB.y;
- this.pC.x = _loc8_ * Math.sin(_loc4_) + this.pB.x;
- this.pC.y = _loc8_ * Math.cos(_loc4_) + this.pB.y;
- var _loc7_ = this.getCentroid();
- var _loc3_ = _loc7_.x - _loc5_.x;
- var _loc2_ = _loc7_.y - _loc5_.y;
- this.pA.x -= _loc3_;
- this.pA.y -= _loc2_;
- this.pB.x -= _loc3_;
- this.pB.y -= _loc2_;
- this.pC.x -= _loc3_;
- this.pC.y -= _loc2_;
- }
- function calcTheta($pA, $pB, $pC)
- {
- var _loc2_ = new Pirrest.PhisicsEngine.Vector($pB.x - $pA.x,$pB.y - $pA.y);
- var _loc3_ = new Pirrest.PhisicsEngine.Vector($pC.x - $pB.x,$pC.y - $pB.y);
- var _loc4_ = _loc2_.dot(_loc3_);
- var _loc5_ = _loc2_.cross(_loc3_);
- return Math.atan2(_loc5_,_loc4_);
- }
- function set theta($t)
- {
- this.targetTheta = $t;
- }
- function get theta()
- {
- return this.targetTheta;
- }
- function paint()
- {
- }
- function getCentroid()
- {
- var _loc3_ = (this.pA.x + this.pB.x + this.pC.x) / 3;
- var _loc2_ = (this.pA.y + this.pB.y + this.pC.y) / 3;
- return new Pirrest.PhisicsEngine.Vector(_loc3_,_loc2_);
- }
- }
-