home *** CD-ROM | disk | FTP | other *** search
- class Pirrest.PhisicsEngine.Wheel extends MovieClip
- {
- var _coord_space;
- var wr;
- var wp;
- var rp;
- var contactRadius;
- var coeffSlip;
- var closestPoint;
- function Wheel()
- {
- super();
- }
- function init($coord_space, $mass)
- {
- if(Pirrest.Common.PiVal.isEmpty($coord_space))
- {
- this._coord_space = this._parent;
- }
- else
- {
- this._coord_space = $coord_space;
- }
- var _loc2_ = {x:this._x,y:this._y};
- this._parent.localToGlobal(_loc2_);
- $coord_space.globalToLocal(_loc2_);
- this.wr = this._width / 2;
- this.wp = new Pirrest.PhisicsEngine.Particle(_loc2_.x,_loc2_.y,$mass);
- this.rp = new Pirrest.PhisicsEngine.RimParticle(this.wr,2);
- this.contactRadius = this.wr;
- this.coeffSlip = 0.1;
- this.closestPoint = new Pirrest.PhisicsEngine.Vector(0,0);
- }
- function verlet($sysObj)
- {
- this.rp.verlet($sysObj);
- this.wp.verlet($sysObj);
- }
- function checkCollision($surface, $sysObj)
- {
- $surface.resolveWheelCollision(this);
- }
- function paint()
- {
- var _loc7_ = this.wp.curr.x;
- var _loc6_ = this.wp.curr.y;
- var _loc4_ = this.rp.curr.x;
- var _loc2_ = this.rp.curr.y;
- this._x = _loc7_;
- this._y = _loc6_;
- var _loc3_ = 57.29578;
- var _loc5_ = (- Math.atan2(_loc4_,_loc2_)) * _loc3_;
- this._rotation = _loc5_;
- }
- function resolve($n)
- {
- var _loc3_ = - this.rp.curr.y;
- var _loc2_ = this.rp.curr.x;
- var _loc4_ = Math.sqrt(_loc3_ * _loc3_ + _loc2_ * _loc2_);
- _loc3_ /= _loc4_;
- _loc2_ /= _loc4_;
- var _loc13_ = _loc3_ * this.rp.speed;
- var _loc11_ = _loc2_ * this.rp.speed;
- var _loc12_ = this.wp.curr.x - this.wp.prev.x;
- var _loc10_ = this.wp.curr.y - this.wp.prev.y;
- var _loc9_ = _loc12_ + _loc13_;
- var _loc8_ = _loc10_ + _loc11_;
- var _loc6_ = (- $n.y) * _loc9_ + $n.x * _loc8_;
- this.rp.prev.x = this.rp.curr.x - _loc6_ * _loc3_;
- this.rp.prev.y = this.rp.curr.y - _loc6_ * _loc2_;
- var _loc7_ = 1 - this.coeffSlip;
- this.wp.curr.x += _loc7_ * this.rp.speed * (- $n.y);
- this.wp.curr.y += _loc7_ * this.rp.speed * $n.x;
- this.rp.speed *= this.coeffSlip;
- }
- }
-