View Full Version : Reseting the bounding box after rotation. HELP!
NinoK5
10-13-2005, 05:34 AM
Hi all.
Ive been trying to find the solution to this for quite some time with no luck. I am hopeing you guys will shed some light on this, because it seems simple.
Basically i want to reset the bounding box of a movie clip after i have rotated it. That way it fits the shape better based on new rotation. I have included a picture to explain what i need.
http://niobrara.unl.edu/users/nino/files/flashprob.jpg
It seems simple but i cant seem to find the solution. Any ides?
Thanks so much in advance.
Nino
Sunny13
10-13-2005, 10:55 AM
simply take a movieclip named a_mc on stage and use this code on the first frame....:)
var bounds_obj:Object = a_mc.getBounds(this);
this.lineStyle(5, 0xFF00FF, 100);
a_mc._rotation = 20;
this.moveTo(a_mc._x);
bounds_obj = a_mc.getBounds(this);
this.moveTo(bounds_obj["xMin"], bounds_obj["yMin"]);
this.lineTo(bounds_obj["xMin"], bounds_obj["yMax"]);
this.lineTo(bounds_obj["xMax"], bounds_obj["yMax"]);
this.lineTo(bounds_obj["xMax"], bounds_obj["yMin"]);
this.lineTo(bounds_obj["xMin"], bounds_obj["yMin"]);
NinoK5
10-13-2005, 02:47 PM
Sorry, i should have been clearer. I don't need to simply draw the shape, and BTW that would draw the shape of the RED box anyway because the getBounds function returns the dimensions of the red box. :).
I actually need flash to measure the width of a rotated object NOT including its bounding box (blue). Because the object is rotated, so is its bounding box and those corners take up a lot more space then they should hence falsly reporting the width of the object. It insead reports the width of the object INCLUDING its now rotated bounding box (red).
The image should explain it better now that you guys know what to look at, hehe.
Anyway, thanks a lot for your try.
Nino.
NinoK5
10-14-2005, 09:23 PM
Seriously, this is driving me crazy.
All i want is the pixel width of a movie clip (MC that has an odd shape). Image above will explain better. Is there a way to reset the objects bounding box, because if i get the width of an object after i have rotated it, the number includes the space taken up by the rotated bounding box which is wrong obviously. How do i get around this? Can i access the vector image data somehow, or have flash reset the bounding box???
I wrote a function that goes and does hittests on every point within the bounding NEW bounding box that gets returned once the MC has been spun and sees how close it can get from each side, but as you can imagine this is rather slow (there is like a 2 sec pause each time it is used) even though i break out of the for loop as soon as a hit occurs from each side (if i dont it takes 4x longer). I need to find something that is faster, any ideas?
Im using flash 8 so all goes.
Thanks!
Sunny13
10-17-2005, 04:26 AM
the pistures are always considered as a rectangular object in flash... so is it possible to detect only the drawing area of a picture....I doubt??
NinoK5
10-17-2005, 04:37 AM
Yep, they are. I am just wondering if it is possible to get flash to recalculate the bounding box? I am currently going with a function that checks the are inside of the bounding box from each side and how far it can go inwards before it hits the object, giving me the bounding box. I made it go 2 pixels at a time to save time but its definately not something that can be done 30 times a sec.
Sunny13
10-17-2005, 09:15 AM
one way to do it can be the... find the boundary pixels of the image ... and finding the four required for the boundaries.... consider the left end of the image.... could be a white pixel... not a drawing part ... keep on tracing all the neighbours of the pixel recursively and so on ... repeat the step for all the four edges... it may help but will need a lot of input....:)
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.