/** * Flade - Flash Dynamics Engine * Release 0.4 alpha * RimParticle class * Copyright 2004, 2005 Alec Cove * * This file is part of Flade. The Flash Dynamics Engine. * * Flade is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Flade is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Flade; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Flash is a registered trademark of Macromedia */ /* * The RimParticle is really just a second component of the wheel model. * The rim particle is simulated in a coordsystem relative to the wheel's * center, not in worldspace */ RimParticle = function(r, mt) { this.curr = new Vector(r, 0); this.prev = new Vector(0, 0); this.vs = 0; // variable speed this.speed = 0; // initial speed this.maxTorque = mt; this.wr = r; } RimParticle.prototype.depth = 4000; RimParticle.prototype.verlet = function(sysObj) { //clamp torques to valid range this.speed = Math.max(-this.maxTorque, Math.min(this.maxTorque, this.speed + this.vs)); //apply torque //this is the tangent vector at the rim particle var dx = -this.curr.y; var dy = this.curr.x; //normalize so we can scale by the rotational speed var len = Math.sqrt(dx * dx + dy * dy); dx /= len; dy /= len; this.curr.x += this.speed * dx; this.curr.y += this.speed * dy; var ox = this.prev.x; var oy = this.prev.y; var px = this.prev.x = this.curr.x; var py = this.prev.y = this.curr.y; this.curr.x += sysObj.coeffDamp * (px - ox); this.curr.y += sysObj.coeffDamp * (py - oy); // hold the rim particle in place var clen = Math.sqrt(this.curr.x * this.curr.x + this.curr.y * this.curr.y); var diff = (clen - this.wr) / clen; this.curr.x -= this.curr.x * diff; this.curr.y -= this.curr.y * diff; }