PDA

View Full Version : Rotate tool based on mouse's x/y lcoation.


Cyd
05-15-2006, 02:58 AM
Im trying to make a rotate tool that allows me to click on the end of the symbol and have the symbol rotate by following the mouse.

I have all the proper clicking programming down, and it works perfectly. But when I have it find the angle of rotation based on the previous position, it rotates more or less fine, doesnt exactly follow the mouse as it moves, but the big problem is that as I rotate it around - the whole symbol begins to shrink the more I rotate it.

Heres the code. I get the angle of rotation by using atan2. Since atan is from the origin, I take the angle of the new click, and I subtract the old click from it. This in theory should give me the new angle at which I should rotate it to match up with the mouse's position.

penPointx = fl.tools.penLoc.x;
penPointy = fl.tools.penLoc.y;

mat = fl.getDocumentDOM().selection[0].matrix;
relativex = penPointx - mat.tx;
relativey = (-1)*(penPointy - mat.ty);
srelativex = startPointx - mat.tx;
srelativey =(-1)*(startPointy - mat.ty);

firstAngle = Math.atan2(srelativey, srelativex);
secondAngle = Math.atan2(relativey, relativex);
deg = (-1)*(secondAngle - firstAngle);

deg = (deg * 180)/Math.PI;
fl.getDocumentDOM().rotateSelection(deg)

var transPoint = fl.getDocumentDOM().getTransformationPoint();
mat = fl.getDocumentDOM().selection[0].matrix;
xpos = mat.tx + transPoint.x;
ypos = mat.ty + transPoint.y; //Finding the transform point's location on the outside

startPointx = fl.tools.penLoc.x;
startPointy = fl.tools.penLoc.y;

Any help would be great.

-Chris