/** * Flade - Flash Dynamics Engine * Release 0.4 alpha * Constraint 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 */ Constraint = function(p1, p2) { this.p1 = p1; this.p2 = p2; this.restLength = p1.curr.distance(p2.curr); var drawClipName = "constdrawclip_" + this.depth; this.dmc = createEmptyMovieClip (drawClipName, this.depth); Constraint.prototype.depth++; } Constraint.prototype.depth = 3000; Constraint.prototype.resolve = function() { var delta = this.p1.curr.minusNew(this.p2.curr); var deltaLength = this.p1.curr.distance(this.p2.curr); var diff = (deltaLength - this.restLength) / deltaLength; var dmd = delta.mult(diff * 0.5); this.p1.curr.minus(dmd); this.p2.curr.plus(dmd); } Constraint.prototype.setRestLength = function(r) { this.restLength = r; } Constraint.prototype.paint = function() { this.dmc.clear(); this.dmc.lineStyle(0, 0x996633, 100); Graphics.prototype.paintLine( this.dmc, this.p1.curr.x, this.p1.curr.y, this.p2.curr.x, this.p2.curr.y); }