home *** CD-ROM | disk | FTP | other *** search
- class Pirrest.PhisicsEngine.ParticleSystem
- {
- var _particles_ar;
- var _surfaces_ar;
- var _constraints_ar;
- var _wheels_ar;
- var gravity;
- var coeffRest;
- var coeffFric;
- var coeffDamp;
- var _p_count;
- var _w_count;
- var _s_count;
- var _c_count;
- function ParticleSystem()
- {
- this.init();
- }
- function init()
- {
- this._particles_ar = [];
- this._surfaces_ar = [];
- this._constraints_ar = [];
- this._wheels_ar = [];
- this.gravity = new Pirrest.PhisicsEngine.Vector(0,1);
- this.coeffRest = 1.5;
- this.coeffFric = 0.1;
- this.coeffDamp = 0;
- }
- function addParticle($px, $py, $mass)
- {
- var _loc2_ = new Pirrest.PhisicsEngine.Particle($px,$py,$mass);
- this._particles_ar.push(_loc2_);
- this._p_count = this._particles_ar.length;
- return _loc2_;
- }
- function addWheel($wheel)
- {
- this._wheels_ar.push($wheel);
- this._w_count = this._wheels_ar.length;
- }
- function addSurface($s)
- {
- this._surfaces_ar.push($s);
- this._s_count = this._surfaces_ar.length;
- }
- function addCircleSurface($s)
- {
- this._surfaces_ar.push($s);
- this._s_count = this._surfaces_ar.length;
- }
- function addConstraint($p1, $p2)
- {
- var _loc2_ = new Pirrest.PhisicsEngine.Constraint($p1,$p2);
- trace("Add const: " + $p1 + " " + $p2);
- this._constraints_ar.push(_loc2_);
- this._c_count = this._constraints_ar.length;
- return _loc2_;
- }
- function addRectangle($center, $rWidth, $rHeight)
- {
- return new Pirrest.PhisicsEngine.Rectangle(this,$center,$rWidth,$rHeight);
- }
- function addAngularConstraint($p1, $p2, $p3)
- {
- var _loc2_ = new Pirrest.PhisicsEngine.AngularConstraint($p1,$p2,$p3);
- this._constraints_ar.push(_loc2_);
- this._c_count = this._constraints_ar.length;
- return _loc2_;
- }
- function setKfr($kfr)
- {
- this.coeffRest = 1 + $kfr;
- }
- function setFriction($f)
- {
- this.coeffFric = $f;
- }
- function setDamping($d)
- {
- this.coeffDamp = $d;
- }
- function setGravity($gx, $gy)
- {
- this.gravity.x = $gx;
- this.gravity.y = $gy;
- }
- function verlet()
- {
- var _loc2_ = undefined;
- _loc2_ = 0;
- while(_loc2_ < this._p_count)
- {
- this._particles_ar[_loc2_].verlet(this);
- _loc2_ = _loc2_ + 1;
- }
- _loc2_ = 0;
- while(_loc2_ < this._w_count)
- {
- this._wheels_ar[_loc2_].verlet(this);
- _loc2_ = _loc2_ + 1;
- }
- }
- function satisfy_constraints_ar()
- {
- var _loc2_ = undefined;
- _loc2_ = 0;
- while(_loc2_ < this._c_count)
- {
- this._constraints_ar[_loc2_].resolve();
- _loc2_ = _loc2_ + 1;
- }
- }
- function checkCollisions()
- {
- var _loc4_ = undefined;
- var _loc3_ = undefined;
- var _loc2_ = undefined;
- _loc4_ = 0;
- while(_loc4_ < this._s_count)
- {
- _loc3_ = 0;
- while(_loc3_ < this._p_count)
- {
- this._particles_ar[_loc3_].checkCollision(this._surfaces_ar[_loc4_],this);
- _loc3_ = _loc3_ + 1;
- }
- _loc2_ = 0;
- while(_loc2_ < this._w_count)
- {
- this._wheels_ar[_loc2_].checkCollision(this._surfaces_ar[_loc4_],this);
- _loc2_ = _loc2_ + 1;
- }
- _loc4_ = _loc4_ + 1;
- }
- }
- function paintSurfaces()
- {
- var _loc2_ = 0;
- while(_loc2_ < this._surfaces_ar.length)
- {
- this._surfaces_ar[_loc2_].paint();
- _loc2_ = _loc2_ + 1;
- }
- }
- function paintParticles()
- {
- var _loc2_ = 0;
- while(_loc2_ < this._particles_ar.length)
- {
- this._particles_ar[_loc2_].paint();
- _loc2_ = _loc2_ + 1;
- }
- }
- function paintConstraints()
- {
- var _loc2_ = 0;
- while(_loc2_ < this._constraints_ar.length)
- {
- this._constraints_ar[_loc2_].paint();
- _loc2_ = _loc2_ + 1;
- }
- }
- function paintWheels()
- {
- var _loc2_ = 0;
- while(_loc2_ < this._wheels_ar.length)
- {
- this._wheels_ar[_loc2_].paint();
- _loc2_ = _loc2_ + 1;
- }
- }
- function timeStep()
- {
- this.verlet();
- this.satisfy_constraints_ar();
- this.checkCollisions();
- }
- }
-