WhoCanDo Posted May 28, 2010 Share Posted May 28, 2010 I want to create an object: repeat if (MouseDown(x1, y1)) then begin moveto(x1, y1); x2 := x1 + 580; y2 := y1; closepoly; poly (30,#90,x2,#0,30,#-90); h := lnewobj; end; until (h <> Nil); and after h := lnewobj; I want to pick the object and free rotate it with the mouse around x1,y1 until I pick a second point with the mouse. I've tried repeat getmouse (x3, y3); rotatepoint (x1, y1, AngleOfRotation); redraw; until (MouseDown (x3, y3)); but I think I am on the wrong track. Any suggestions please? Quote Link to comment
MullinRJ Posted May 28, 2010 Share Posted May 28, 2010 Hi Who, ???You're definitely on the right track. However, you need to calculate the angle you want to rotate from points 1 and 3 before you call the RotatePoint() function. This is most easily done with vector function Vec2Ang(). Since point 1 is the center of interest (and rotation) subtract it from point 3 and stuff it into vector V as follows: V.x := x3 - x1; V.y := y3 - y1; AngleOfPt3 := Vec2Ang(V);???{ relative to point 1 } The following script is not what you want, but it executes in a humorous way. Try it. PROCEDURE yyy; VAR H :Handle; x1, y1, x2, y2, x3, y3, AngleOfPt3 :Real; V :Vector; BEGIN repeat if (MouseDown(x1, y1)) then begin moveto(x1, y1); x2 := x1 + 580; y2 := y1; closepoly; poly (30,#90,x2,#0,30,#-90); H := lnewobj; end; until (H <> Nil); repeat getmouse (x3, y3); V.x := x3 - x1; V.y := y3 - y1; AngleOfPt3 := Vec2Ang(V); RotatePoint (x1, y1, AngleOfPt3); redraw; until (MouseDown (x3, y3)); END; Run(yyy); Since you are in a loop, each time through you will rotate your object again, so your script has to remember how much it rotated the object the last time through and subtract that off for the current pass through the loop. This example should be more to your liking. PROCEDURE xxx; VAR H :Handle; x1, y1, x2, y2, x3, y3 :Real; AngleOfPt3, lastPt3Ang :Real; V :Vector; BEGIN repeat if (MouseDown(x1, y1)) then begin moveto(x1, y1); x2 := x1 + 580; y2 := y1; closepoly; poly (30,#90,x2,#0,30,#-90); H := lnewobj; end; until (H <> Nil); lastPt3Ang := 0; repeat getmouse (x3, y3); V.x := x3 - x1; V.y := y3 - y1; AngleOfPt3 := Vec2Ang(V); RotatePoint (x1, y1, AngleOfPt3 - lastPt3Ang); { rotate by delta angle } lastPt3Ang := AngleOfPt3; redraw; until (MouseDown (x3, y3)); END; Run(xxx); HTH, Raymond Quote Link to comment
WhoCanDo Posted June 3, 2010 Author Share Posted June 3, 2010 Thanks Raymond, I didn't know I was so close. I've not used vectors before so I will have to study it more. Love the first macro. Regards Quote Link to comment
WhoCanDo Posted June 8, 2010 Author Share Posted June 8, 2010 A little more help please. I have replaced the first "repeat until" with a GetPt because I want to be able to pick an existing object to align this new object with. The problem is that GetMouse turns off snapping opitons. Is there another way to do the following? procedure Get_Placement; var h1, h2 :Handle; x1, y1, x2, y2 : real; AngleOfPt2, LastPt2Ang : real; V : vector; begin GetPt ( x1, y1); moveto (x1, y1); closepoly; poly (60, #90, 580, #0, 60, #-90); LastPt2Ang := 0; repeat GetMouse (x2, y2); V.x := x2 - x1; V.y := y2 - y1; AngleOfPt2 := Vec2Ang (V); RotatePoint (x1, y1, AngleOfPt2 - LastPt2Ang); { rotate by delta angle } LastPt2Ang := AngleOfPt2; Redraw; until (MouseDown (x2, y2)); end; run (Get_Placement); Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.