home *** CD-ROM | disk | FTP | other *** search
- class org.cove.flade.DynamicsEngine
- {
- var primitives;
- var surfaces;
- var MoveSurfaces;
- var constraints;
- var gravity;
- var coeffRest;
- var coeffFric;
- var coeffDamp;
- var totalTime = 0;
- function DynamicsEngine()
- {
- this.primitives = new Array();
- this.surfaces = new Array();
- this.MoveSurfaces = new Array();
- this.constraints = new Array();
- this.gravity = new org.cove.flade.util.Vector(0,1);
- this.coeffRest = 1.5;
- this.coeffFric = 0.01;
- this.coeffDamp = 0.99;
- }
- function ClearSurfaces()
- {
- var _loc2_ = 0;
- while(_loc2_ < this.surfaces.length)
- {
- this.surfaces[_loc2_].clear();
- _loc2_ = _loc2_ + 1;
- }
- _loc2_ = 0;
- while(_loc2_ < this.MoveSurfaces.length)
- {
- this.MoveSurfaces[_loc2_].clear();
- _loc2_ = _loc2_ + 1;
- }
- this.surfaces = new Array();
- this.MoveSurfaces = new Array();
- }
- function ClearAll()
- {
- this.surfaces = new Array();
- this.MoveSurfaces = new Array();
- this.constraints = new Array();
- }
- function addPrimitive(p)
- {
- this.primitives.push(p);
- }
- function addSurface(s)
- {
- this.surfaces.push(s);
- }
- function addMoveSurface(s)
- {
- this.MoveSurfaces.push(s);
- }
- function addConstraint(c)
- {
- this.constraints.push(c);
- }
- function paintSurfaces()
- {
- var _loc2_ = 0;
- while(_loc2_ < this.surfaces.length)
- {
- this.surfaces[_loc2_].paint();
- _loc2_ = _loc2_ + 1;
- }
- }
- function paintMoveSurfaces()
- {
- var _loc2_ = 0;
- while(_loc2_ < this.MoveSurfaces.length)
- {
- this.MoveSurfaces[_loc2_].paint();
- _loc2_ = _loc2_ + 1;
- }
- }
- function paintPrimitives()
- {
- var _loc2_ = 0;
- while(_loc2_ < this.primitives.length)
- {
- this.primitives[_loc2_].paint();
- _loc2_ = _loc2_ + 1;
- }
- }
- function paintConstraints()
- {
- var _loc2_ = 0;
- while(_loc2_ < this.constraints.length)
- {
- this.constraints[_loc2_].paint();
- _loc2_ = _loc2_ + 1;
- }
- }
- function timeStep()
- {
- this.verlet();
- this.satisfyConstraints();
- this.checkCollisions();
- }
- function setSurfaceBounce(kfr)
- {
- this.coeffRest = 1 + kfr;
- }
- function setSurfaceFriction(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_ = 0;
- while(_loc2_ < this.primitives.length)
- {
- this.primitives[_loc2_].verlet(this);
- _loc2_ = _loc2_ + 1;
- }
- }
- function satisfyConstraints()
- {
- var _loc2_ = 0;
- while(_loc2_ < this.constraints.length)
- {
- this.constraints[_loc2_].resolve();
- _loc2_ = _loc2_ + 1;
- }
- }
- function checkCollisions()
- {
- var _loc5_ = 0;
- while(_loc5_ < this.primitives.length)
- {
- this.primitives[_loc5_].UpdateCount();
- _loc5_ = _loc5_ + 1;
- }
- var _loc4_ = 0;
- while(_loc4_ < this.surfaces.length)
- {
- var _loc3_ = this.surfaces[_loc4_];
- if(_loc3_.getActiveState())
- {
- var _loc2_ = 0;
- while(_loc2_ < this.primitives.length)
- {
- this.primitives[_loc2_].checkCollision(_loc3_,this);
- _loc2_ = _loc2_ + 1;
- }
- }
- _loc4_ = _loc4_ + 1;
- }
- _loc4_ = 0;
- while(_loc4_ < this.MoveSurfaces.length)
- {
- _loc3_ = this.MoveSurfaces[_loc4_];
- if(_loc3_.getActiveState())
- {
- _loc2_ = 0;
- while(_loc2_ < this.primitives.length)
- {
- this.primitives[_loc2_].checkCollision(_loc3_,this);
- _loc2_ = _loc2_ + 1;
- }
- }
- _loc4_ = _loc4_ + 1;
- }
- }
- }
-