home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / germ_roundup.swf / scripts / __Packages / smashing / Joint.as < prev    next >
Encoding:
Text File  |  2007-03-20  |  1.6 KB  |  57 lines

  1. class smashing.Joint
  2. {
  3.    var nSpring = 0.5;
  4.    var rotateA = false;
  5.    var rotateB = false;
  6.    function Joint(mcA, mcB, springy)
  7.    {
  8.       var _loc1_ = this;
  9.       if(springy != undefined)
  10.       {
  11.          _loc1_.nSpring = springy;
  12.       }
  13.       _loc1_.A = mcA;
  14.       _loc1_.B = mcB;
  15.       _loc1_.pInert = new smashing.Point(_loc1_.B._x - _loc1_.A._x,_loc1_.B._y - _loc1_.A._y);
  16.       _loc1_.dist = _loc1_.pInert.length;
  17.       _loc1_.pfnInert = _loc1_.pInert.cross().normalize();
  18.       _loc1_.pnInert = _loc1_.pInert.normalize();
  19.    }
  20.    function update(nElapsed)
  21.    {
  22.       var _loc1_ = this;
  23.       var _loc2_ = new smashing.Point(_loc1_.B.x - _loc1_.A.x,_loc1_.B.y - _loc1_.A.y);
  24.       var d = _loc2_.dot(_loc1_.pfnInert);
  25.       var d2 = _loc2_.dot(_loc1_.pnInert);
  26.       if(d != 0)
  27.       {
  28.          var dir = d / Math.abs(d);
  29.          var dir2 = d2 / Math.abs(d2);
  30.          var _loc3_ = Math.acos(d2 / _loc2_.length);
  31.          var move = _loc1_.ease(_loc3_,nElapsed) * dir;
  32.          _loc3_ *= - dir;
  33.          _loc3_ += move;
  34.          _loc2_ = _loc1_.pInert.rotate(_loc3_);
  35.          _loc1_.B.x = _loc1_.A.x + _loc2_.x;
  36.          _loc1_.B.y = _loc1_.A.y + _loc2_.y;
  37.       }
  38.       var deg = _loc3_ / 3.141592653589793 * 180;
  39.       if(_loc1_.rotateA)
  40.       {
  41.          _loc1_.A._rotation = deg;
  42.       }
  43.       else if(_loc1_.rotateAInner != null)
  44.       {
  45.          _loc1_.A[_loc1_.rotateAInner]._rotation = deg;
  46.       }
  47.       if(_loc1_.rotateB)
  48.       {
  49.          _loc1_.B._rotation = deg;
  50.       }
  51.    }
  52.    function ease(d, nElapsed)
  53.    {
  54.       return d * Math.pow(nElapsed,this.nSpring);
  55.    }
  56. }
  57.