I think I've worked out SetHandle now. In the Thrust-like thing I'm working on, I need to draw an image or rectangle (a thick line) representing a tractor beam from my ship to the target object.
I had this:
(pos.x,pos.y) are the co-ordinates of the ship, (p.pos.x,p.pos.y) are the co-ordinates of the target, distance(p) is the distance from the ship to the target. So SetRotation rotates the drawing axis in the direction of the target, so I just draw a rectangle 8 pixels thick with the correct length.
The problem is that the rectangle is rotated around the top-left corner, and not around a point halfway down the left-hand side. DrawRect (and the other drawing commands, I imagine) works as though it draws a rectangle width x height in size starting at the origin, then transforms it by whatever SetRotation/SetScale/SetTransform says, and finally moves it to (x,y). So, after much experimentation, I did this:
So although the draw and rotate commands are the same, the rectangle is rotated around a different point.
Like SetRotation, SetHandle applies to everything else you draw so you have to reset it to 0,0 before you draw anything else.
I had this:
SetRotation(ATan2(pos.x-p.pos.x, p.pos.y-pos.y)+90#) DrawRect(pos.x, pos.y, distance(p), 8.0#)
(pos.x,pos.y) are the co-ordinates of the ship, (p.pos.x,p.pos.y) are the co-ordinates of the target, distance(p) is the distance from the ship to the target. So SetRotation rotates the drawing axis in the direction of the target, so I just draw a rectangle 8 pixels thick with the correct length.
The problem is that the rectangle is rotated around the top-left corner, and not around a point halfway down the left-hand side. DrawRect (and the other drawing commands, I imagine) works as though it draws a rectangle width x height in size starting at the origin, then transforms it by whatever SetRotation/SetScale/SetTransform says, and finally moves it to (x,y). So, after much experimentation, I did this:
SetRotation(ATan2(pos.x-p.pos.x, p.pos.y-pos.y)+90#) SetHandle(0.0#,4.0#) DrawRect(pos.x, pos.y, distance(p), 8.0#)
So although the draw and rotate commands are the same, the rectangle is rotated around a different point.
Like SetRotation, SetHandle applies to everything else you draw so you have to reset it to 0,0 before you draw anything else.