Rotate around center without centered handle
BlitzMax Forums/BlitzMax Programming/Rotate around center without centered handle
| ||
I want to rotate a 2D image of an airplane so that its nose points up or down, probably using SetRotation. For it to look nice, the rotation would have to be performed around the center of the image, but I am using the default upper left corner of the image (0,0) as its handle. Is there a way to use the upper left corner of the image for drawing, while at the same time using the center of the image for rotating? I could use the center of the image for drawing too, but the rest of the code (collisions etc.) assumes the handle is at 0,0. |
| ||
Function SetImageHandle( image:TImage,x#,y# ) Description: Set an image's handle to an arbitrary point Information: An image's handle is subtracted from the coordinates of DrawImage before rotation and scale are applied. Hope that helps. |
| ||
oh dear, you've just asked the same question as stanrol. |
| ||
No, Stanrol asked a different question. Only the first line of my question is the same. |
| ||
Function MidHandleImage(Image:TImage)set a rotation center to the mid of the image. |
| ||
Thanks for that, but that would also change the drawing location of the image, if I am not mistaken. I think I will either not rotate the image, or I will use MidHandleImage and then do some additional math (as suggested by Warpy) when drawing the image to get it at the right location, as if the handle was still at 0,0. |
| ||
What kind of collision detection are you doing? It might actually be easier to reset the collision code to work from the center of the image. Unless you have already taken into account the math for collision based on the rotated position of the item, in which case the match for displaying it in the correct place should be trivial. (or I'm overthinking this) |
| ||
What kind of collision detection are you doing? It might actually be easier to reset the collision code to work from the center of the image. This is true... for this or a following game I could consider using centered handles for all game objects. |
| ||
midhandle image then drawimage img,x-imagewidth(img)/2,y-imageheight(img)/2 that what you mean? you will draw in same place but rotate around center |
| ||
Yes that is what I mean. I will try something like that the next time I am at my computer. (ImageWidth and ImageHeight may use the unrotated width and height but I will figure this out.) Thanks for the suggestions and help! |