home *** CD-ROM | disk | FTP | other *** search
- class Engine.Collision
- {
- var point;
- var normal;
- var edge;
- var time;
- var offCorner;
- function Collision(point, normal, time, edge, offCorner)
- {
- this.point = point;
- this.normal = normal;
- this.edge = edge;
- this.time = time;
- this.offCorner = offCorner;
- }
- function toString()
- {
- return "Collision: point: " + this.point + " normal: " + this.normal;
- }
- static function sweepSphereToStaticShape(sphere, shape, noData)
- {
- if(sphere.motionLeft > shape.right || sphere.motionRight < shape.left || sphere.motionTop > shape.bottom || sphere.motionBottom < shape.top)
- {
- return undefined;
- }
- var _loc25_ = shape.edges;
- var _loc22_ = _loc25_.length;
- var _loc15_ = sphere.motionVec;
- var _loc14_ = sphere.motionDir;
- var _loc4_ = sphere.motionDist;
- var _loc5_ = sphere.radius;
- var _loc21_ = undefined;
- var _loc12_ = undefined;
- var _loc20_ = undefined;
- var _loc7_ = 1.7976931348623157e+308;
- var _loc13_ = new Vector(sphere.x - shape.x,sphere.y - shape.y);
- var _loc1_ = undefined;
- var _loc9_ = undefined;
- var _loc23_ = undefined;
- while((_loc22_ = _loc22_ - 1) > -1)
- {
- if(_loc1_ = _loc25_[_loc22_].props & 1)
- {
- if(_loc14_.dot(_loc1_.normal) < 0)
- {
- var _loc16_ = _loc1_.a;
- _loc9_ = new Vector(_loc1_.center.x - _loc13_.x,_loc1_.center.y - _loc13_.y,0);
- if(_loc9_.length - _loc5_ - _loc4_ <= _loc1_.radius)
- {
- var _loc3_ = new Vector(_loc13_.x - _loc16_.x,_loc13_.y - _loc16_.y);
- var _loc18_ = _loc3_.dot(_loc1_.normal);
- if(!(_loc18_ < 0 || _loc18_ - _loc4_ > _loc5_))
- {
- var _loc17_ = new Vector(_loc3_.x - _loc1_.normal.x * _loc5_,_loc3_.y - _loc1_.normal.y * _loc5_);
- var _loc10_ = _loc1_.span;
- var _loc6_ = (_loc15_.x * (- _loc17_.y) - _loc15_.y * (- _loc17_.x)) / (_loc15_.y * _loc10_.x - _loc15_.x * _loc10_.y);
- var _loc2_ = undefined;
- if(_loc6_ >= 0 && _loc6_ <= 1)
- {
- var _loc11_ = new Vector(_loc10_.x * _loc6_ + _loc1_.normal.x * _loc5_,_loc10_.y * _loc6_ + _loc1_.normal.y * _loc5_);
- var _loc19_ = new Vector(_loc11_.x - _loc3_.x,_loc11_.y - _loc3_.y);
- if((_loc2_ = _loc19_.length) <= _loc4_)
- {
- if(_loc7_ < _loc2_ / _loc4_)
- {
- continue;
- }
- _loc12_ = _loc11_;
- _loc7_ = _loc2_ / _loc4_;
- if(_loc7_ < 0.001)
- {
- _loc7_ = 0;
- _loc11_.x = _loc3_.x;
- _loc11_.y = _loc3_.y;
- }
- _loc21_ = _loc1_.normal;
- _loc20_ = _loc1_;
- }
- }
- else
- {
- _loc11_ = _loc6_ <= 1 ? Vector.ZERO : _loc1_.span;
- _loc9_ = _loc23_ = new Vector(_loc11_.x - _loc3_.x,_loc11_.y - _loc3_.y).length;
- var _loc8_ = _loc23_.dot(_loc14_);
- _loc2_ = _loc5_ * _loc5_ - (_loc9_ * _loc9_ - _loc8_ * _loc8_);
- if(_loc8_ > 0 && _loc2_ > 0 && (_loc2_ = _loc8_ - Math.sqrt(_loc2_)) < _loc4_)
- {
- if(_loc7_ < _loc2_ / _loc4_ || _loc2_ / _loc4_ < 0)
- {
- continue;
- }
- _loc7_ = _loc2_ / _loc4_;
- _loc20_ = _loc1_;
- _loc12_ = new Vector(_loc3_.x + _loc2_ * _loc14_.x,_loc3_.y + _loc2_ * _loc14_.y,0);
- (_loc21_ = new Vector(_loc12_.x - _loc11_.x,_loc12_.y - _loc11_.y,0)).normalize();
- }
- }
- }
- }
- }
- }
- }
- if(_loc20_)
- {
- _loc12_.x += shape.x + _loc20_.a.x;
- _loc12_.y += shape.y + _loc20_.a.y;
- return new Engine.Collision(_loc12_,_loc21_,_loc7_,_loc20_);
- }
- return null;
- }
- static function sweepSphereToSphere(movingObj, obj, noData)
- {
- var _loc6_ = undefined;
- var _loc4_ = undefined;
- var _loc5_ = movingObj.radius + obj.radius;
- _loc4_ = _loc6_ = new Vector(obj.x - movingObj.x,obj.y - movingObj.y,0).length;
- var _loc2_ = _loc6_.dot(movingObj.motionDir);
- var _loc1_ = _loc5_ * _loc5_ - (_loc4_ * _loc4_ - _loc2_ * _loc2_);
- if(_loc1_ > 0 && (_loc1_ = _loc2_ - Math.sqrt(_loc1_)) < movingObj.motionDist)
- {
- if(_loc1_ < 0)
- {
- return false;
- }
- if(noData)
- {
- return true;
- }
- }
- return false;
- }
- }
-