home *** CD-ROM | disk | FTP | other *** search
- class smashing.Joint
- {
- var nSpring = 0.5;
- var rotateA = false;
- var rotateB = false;
- function Joint(mcA, mcB, springy)
- {
- var _loc1_ = this;
- if(springy != undefined)
- {
- _loc1_.nSpring = springy;
- }
- _loc1_.A = mcA;
- _loc1_.B = mcB;
- _loc1_.pInert = new smashing.Point(_loc1_.B._x - _loc1_.A._x,_loc1_.B._y - _loc1_.A._y);
- _loc1_.dist = _loc1_.pInert.length;
- _loc1_.pfnInert = _loc1_.pInert.cross().normalize();
- _loc1_.pnInert = _loc1_.pInert.normalize();
- }
- function update(nElapsed)
- {
- var _loc1_ = this;
- var _loc2_ = new smashing.Point(_loc1_.B.x - _loc1_.A.x,_loc1_.B.y - _loc1_.A.y);
- var d = _loc2_.dot(_loc1_.pfnInert);
- var d2 = _loc2_.dot(_loc1_.pnInert);
- if(d != 0)
- {
- var dir = d / Math.abs(d);
- var dir2 = d2 / Math.abs(d2);
- var _loc3_ = Math.acos(d2 / _loc2_.length);
- var move = _loc1_.ease(_loc3_,nElapsed) * dir;
- _loc3_ *= - dir;
- _loc3_ += move;
- _loc2_ = _loc1_.pInert.rotate(_loc3_);
- _loc1_.B.x = _loc1_.A.x + _loc2_.x;
- _loc1_.B.y = _loc1_.A.y + _loc2_.y;
- }
- var deg = _loc3_ / 3.141592653589793 * 180;
- if(_loc1_.rotateA)
- {
- _loc1_.A._rotation = deg;
- }
- else if(_loc1_.rotateAInner != null)
- {
- _loc1_.A[_loc1_.rotateAInner]._rotation = deg;
- }
- if(_loc1_.rotateB)
- {
- _loc1_.B._rotation = deg;
- }
- }
- function ease(d, nElapsed)
- {
- return d * Math.pow(nElapsed,this.nSpring);
- }
- }
-