/** * Flade - Flash Dynamics Engine * Release 0.4 alpha * CircleSurface 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 */ CircleSurface = function(cx, cy, r) { this.cx = cx; this.cy = cy; this.r = r; var drawClipName = "circsurfdrawclip_" + this.depth; this.dmc = createEmptyMovieClip (drawClipName, this.depth); this.dmc.lineStyle(0, 0x222288, 100); CircleSurface.prototype.depth++; } CircleSurface.prototype.depth = 9000; CircleSurface.prototype.paint = function() { Graphics.prototype.paintCircle(this.dmc, this.cx, this.cy, this.r); } CircleSurface.prototype.resolveWheelCollision = function(w, sysObj) { var dx = this.cx - w.wp.curr.x; var dy = this.cy - w.wp.curr.y; var len = Math.sqrt(dx * dx + dy * dy); var pen = (w.wr + this.r) - len; if (pen > 0) { dx /= len; dy /= len; w.wp.curr.x -= dx * pen; w.wp.curr.y -= dy * pen; var wheelNormal = new Vector(-dx, -dy); w.resolve(wheelNormal); } } CircleSurface.prototype.resolveParticleCollision = function(p, sysObj) { // TBD: move to constructor, and change constructor args var circleCenter = new Vector(this.cx, this.cy); var dist = circleCenter.distance(p.curr); // test if point is within circle if (dist <= this.r) { // get the normal of the surface relative to the location of the point var surfaceNormal = (p.curr.minusNew(circleCenter)).normalize(); // project out to surface of circle var surfacePos = circleCenter.plusNew(surfaceNormal.multNew(this.r)); p.curr = surfacePos; } }