Here is a snippet of the source, any thoughts on how this can be simplified?
... function getDistortedRect(rect:Rectangle, d:DisplacementMapFilter):Array { var resultArr:Array = new Array(); resultArr.push( getDistortedPoint(rect.topLeft, d)); resultArr.push( getDistortedPoint(new Point(rect.x + rect.width, rect.y), d)); resultArr.push( getDistortedPoint(rect.bottomRight, d)); resultArr.push( getDistortedPoint(new Point(rect.x, rect.y + rect.height), d)); return (resultArr); } function getDistortedPoint(o:Point, d:DisplacementMapFilter):Point { var hex = (d.mapBitmap.getPixel(o.x, o.y).toString(16)); //1 (red), 2 (green), 4 (blue) switch(d.componentX) { case 1: var xChannel = HexToR(hex); break; case 2: var xChannel = HexToG(hex); break; case 4: var xChannel = HexToB(hex); break; default: break; } switch(d.componentY) { case 1: var yChannel = HexToR(hex); break; case 2: var yChannel = HexToG(hex); break; case 4: var yChannel = HexToB(hex); break; default: break; } var destinationX:Number = o.x - ((xChannel-128) * d.scaleX)/256; var destinationY:Number = o.y - ((yChannel-128) * d.scaleY)/256; return (new Point(destinationX, destinationY)); } //hex conversion helpers function HexToR(h) {return parseInt(h.substring(0,2),16)} function HexToG(h) {return parseInt(h.substring(2,4),16)} function HexToB(h) {return parseInt(h.substring(4,6),16)} -----Original Message----- From: [EMAIL PROTECTED] on behalf of Howard Nager Sent: Sun 12/18/2005 1:17 PM To: Flashcoders mailing list; Flashcoders mailing list Subject: RE: [Flashcoders] Displacement Maps, and Button actions Thanks for the tip - the formula looks like: dstPixel[x, y] = srcPixel[x + ((componentX(x, y) - 128) * scaleX) / 256, y + ((componentY(x, y) - 128) * scaleY) / 256] I am assuming that (componentX(x, y) should have a result from 0-255. So to get this I am grabbing the value at a given pixel in the displacementmap bitmap (getPixel), converting that value to rgb, then grabbing the the correct channel's value (defined as componentX when I set up the filter) using a conversion function: function HexToR(h) {return parseInt(h.substring(0,2),16)} function HexToG(h) {return parseInt(h.substring(2,4),16)} function HexToB(h) {return parseInt(h.substring(4,6),16)} I repeat the same for y then calculate out the rest of the function. I must be doing something wrong in this process because the displacement I am calculating isn't visually matching up. Is there a different way that I should be grabbing the channel value? -----Original Message----- From: [EMAIL PROTECTED] on behalf of Alan MacDougall Sent: Sat 12/17/2005 11:08 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Displacement Maps, and Button actions Howard Nager wrote: >Thanks - the buttons are rectangular - any tips on how to calculate the corner >positions if the displacement map is a gradient distorting on both x and y? > > > I don't know the math behind the displacement map (I glanced at the formula and decided not to figure it out unless I had to!) If you do a little trial and error until you can get a single point to match, you should be able to calculate exactly how each gray value translates each point. The documentation for the DisplacementMapFilter object does list the formula, which should be a good starting point. _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders