home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Corrida / amazingrace.swf / scripts / __Packages / Pirrest / PhisicsEngine / AngularConstraint.as next >
Encoding:
Text File  |  2006-06-13  |  2.6 KB  |  81 lines

  1. class Pirrest.PhisicsEngine.AngularConstraint
  2. {
  3.    var pA;
  4.    var pB;
  5.    var pC;
  6.    var lineA;
  7.    var lineB;
  8.    var pD;
  9.    var lineC;
  10.    var targetTheta;
  11.    var coeffStiff;
  12.    function AngularConstraint($pA, $pB, $pC)
  13.    {
  14.       this.init($pA,$pB,$pC);
  15.    }
  16.    function init($pA, $pB, $pC)
  17.    {
  18.       this.pA = $pA.curr;
  19.       this.pB = $pB.curr;
  20.       this.pC = $pC.curr;
  21.       this.lineA = new Pirrest.PhisicsEngine.Line(this.pA,this.pB);
  22.       this.lineB = new Pirrest.PhisicsEngine.Line(this.pB,this.pC);
  23.       this.pD = new Pirrest.PhisicsEngine.Vector(this.pB.x + 0,this.pB.y - 1);
  24.       this.lineC = new Pirrest.PhisicsEngine.Line(this.pB,this.pD);
  25.       this.targetTheta = this.calcTheta(this.pA,this.pB,this.pC);
  26.       this.coeffStiff = 1;
  27.    }
  28.    function resolve()
  29.    {
  30.       var _loc5_ = this.getCentroid();
  31.       this.lineC.p2.x = this.lineC.p1.x + 0;
  32.       this.lineC.p2.y = this.lineC.p1.y - 1;
  33.       var _loc9_ = this.pA.distance(this.pB);
  34.       var _loc8_ = this.pB.distance(this.pC);
  35.       var _loc12_ = this.calcTheta(this.pA,this.pB,this.pC);
  36.       var _loc13_ = this.calcTheta(this.pA,this.pB,this.pD);
  37.       var _loc11_ = this.calcTheta(this.pC,this.pB,this.pD);
  38.       var _loc6_ = (this.targetTheta - _loc12_) / 2;
  39.       var _loc10_ = _loc13_ + _loc6_ * this.coeffStiff;
  40.       var _loc4_ = _loc11_ - _loc6_ * this.coeffStiff;
  41.       this.pA.x = _loc9_ * Math.sin(_loc10_) + this.pB.x;
  42.       this.pA.y = _loc9_ * Math.cos(_loc10_) + this.pB.y;
  43.       this.pC.x = _loc8_ * Math.sin(_loc4_) + this.pB.x;
  44.       this.pC.y = _loc8_ * Math.cos(_loc4_) + this.pB.y;
  45.       var _loc7_ = this.getCentroid();
  46.       var _loc3_ = _loc7_.x - _loc5_.x;
  47.       var _loc2_ = _loc7_.y - _loc5_.y;
  48.       this.pA.x -= _loc3_;
  49.       this.pA.y -= _loc2_;
  50.       this.pB.x -= _loc3_;
  51.       this.pB.y -= _loc2_;
  52.       this.pC.x -= _loc3_;
  53.       this.pC.y -= _loc2_;
  54.    }
  55.    function calcTheta($pA, $pB, $pC)
  56.    {
  57.       var _loc2_ = new Pirrest.PhisicsEngine.Vector($pB.x - $pA.x,$pB.y - $pA.y);
  58.       var _loc3_ = new Pirrest.PhisicsEngine.Vector($pC.x - $pB.x,$pC.y - $pB.y);
  59.       var _loc4_ = _loc2_.dot(_loc3_);
  60.       var _loc5_ = _loc2_.cross(_loc3_);
  61.       return Math.atan2(_loc5_,_loc4_);
  62.    }
  63.    function set theta($t)
  64.    {
  65.       this.targetTheta = $t;
  66.    }
  67.    function get theta()
  68.    {
  69.       return this.targetTheta;
  70.    }
  71.    function paint()
  72.    {
  73.    }
  74.    function getCentroid()
  75.    {
  76.       var _loc3_ = (this.pA.x + this.pB.x + this.pC.x) / 3;
  77.       var _loc2_ = (this.pA.y + this.pB.y + this.pC.y) / 3;
  78.       return new Pirrest.PhisicsEngine.Vector(_loc3_,_loc2_);
  79.    }
  80. }
  81.