home *** CD-ROM | disk | FTP | other *** search
- class Pirrest.PhisicsEngine.Surface extends MovieClip
- {
- var coord_space;
- var p1;
- var p2;
- var isOrientH;
- var normal;
- var rise;
- var run;
- var invRun;
- var slope;
- var invB;
- function Surface()
- {
- super();
- }
- function init($coord_space)
- {
- this.coord_space = $coord_space;
- this.p1.init($coord_space);
- this.p2.init($coord_space);
- this.isOrientH = true;
- this.normal = new Pirrest.PhisicsEngine.Vector(0,0);
- this.calcNormal();
- this.rise = this.p2.y - this.p1.y;
- this.run = this.p2.x - this.p1.x;
- this.invRun = 1 / this.run;
- this.slope = this.rise / this.run;
- this.invB = 1 / (this.run * this.run + this.rise * this.rise);
- this.coord_space.lineStyle(10,2237064,100);
- }
- function setIsOrientH($isOrientH)
- {
- this.isOrientH = $isOrientH;
- }
- function calcNormal()
- {
- var _loc4_ = this.p2.x - this.p1.x;
- var _loc3_ = this.p2.y - this.p1.y;
- this.normal.x = _loc3_;
- this.normal.y = - _loc4_;
- var _loc2_ = Math.sqrt(this.normal.x * this.normal.x + this.normal.y * this.normal.y);
- this.normal.x /= _loc2_;
- this.normal.y /= _loc2_;
- }
- function paint()
- {
- Pirrest.PhisicsEngine.Graphics.prototype.paintLine(this.coord_space,this.p1.x,this.p1.y,this.p2.x,this.p2.y);
- }
- function resolveWheelCollision($w)
- {
- if(this.bounds($w.wp.curr,$w.contactRadius))
- {
- this.getClosestPoint($w.wp.curr,$w.closestPoint);
- var _loc3_ = $w.closestPoint.minusNew($w.wp.curr);
- _loc3_.normalize();
- if(this.inequality($w.wp.curr))
- {
- var _loc5_ = Math.abs(_loc3_.x);
- _loc3_.x = this.normal.x >= 0 ? - _loc5_ : _loc5_;
- _loc3_.y = Math.abs(_loc3_.y);
- }
- var _loc4_ = $w.wp.curr.plusNew(_loc3_.mult($w.wr));
- if(this.segmentInequality(_loc4_))
- {
- var _loc7_ = _loc4_.x - $w.closestPoint.x;
- var _loc6_ = _loc4_.y - $w.closestPoint.y;
- $w.wp.curr.x -= _loc7_;
- $w.wp.curr.y -= _loc6_;
- $w.resolve(this.normal);
- }
- }
- }
- function resolveParticleCollision($p, $sysObj)
- {
- if(this.boundedSegmentInequality($p.curr))
- {
- var _loc3_ = $p.curr.minusNew($p.prev);
- var _loc2_ = this.normal.dot(_loc3_);
- if(_loc2_ < 0)
- {
- var _loc8_ = _loc3_.minusNew(this.normal.multNew(_loc2_));
- var _loc5_ = _loc8_.multNew($sysObj.coeffFric);
- var _loc6_ = this.normal.multNew(_loc2_ * $sysObj.coeffRest);
- var _loc7_ = _loc6_.plusNew(_loc5_);
- var _loc11_ = _loc3_.minusNew(_loc7_);
- var _loc10_ = this.normal.dot($p.curr.minusNew(this.p1)) * $sysObj.coeffRest;
- }
- }
- }
- function segmentInequality($toPoint)
- {
- var _loc2_ = this.findU($toPoint);
- var _loc3_ = this.inequality($toPoint);
- return _loc2_ >= 0 && _loc2_ <= 1 && _loc3_;
- }
- function boundedSegmentInequality($toPoint)
- {
- var _loc3_ = undefined;
- if(this.isOrientH)
- {
- _loc3_ = $toPoint.x >= this.p1.x && $toPoint.x <= this.p2.x;
- }
- else if(this.p1.y < this.p2.y)
- {
- _loc3_ = $toPoint.y >= this.p1.y && $toPoint.y <= this.p2.y;
- }
- else
- {
- _loc3_ = $toPoint.y <= this.p1.y && $toPoint.y >= this.p2.y;
- }
- if(_loc3_)
- {
- return this.inequality($toPoint);
- }
- return false;
- }
- function inequality($toPoint)
- {
- var _loc2_ = this.slope * ($toPoint.x - this.p1.x) + (this.p1.y - $toPoint.y);
- return _loc2_ <= 0;
- }
- function bounds($toPoint, $r)
- {
- return $toPoint.x >= this.p1.x - $r && $toPoint.x <= this.p2.x + $r;
- }
- function getClosestPoint($toPoint, $returnVect)
- {
- var _loc2_ = this.findU($toPoint);
- if(_loc2_ <= 0)
- {
- return this.p1;
- }
- if(_loc2_ >= 1)
- {
- return this.p2;
- }
- var _loc4_ = this.p1.x + _loc2_ * (this.p2.x - this.p1.x);
- var _loc3_ = this.p1.y + _loc2_ * (this.p2.y - this.p1.y);
- $returnVect.x = _loc4_;
- $returnVect.y = _loc3_;
- }
- function findU($p)
- {
- var _loc2_ = ($p.x - this.p1.x) * this.run + ($p.y - this.p1.y) * this.rise;
- return _loc2_ * this.invB;
- }
- }
-