realbasic-games
[Top] [All Lists]

Re: Drawing Rotated Image

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Drawing Rotated Image
From: Toon Van Acker <toon dot van dot acker at mac dot com>
Date: Mon, 26 Sep 2005 09:32:37 +0200
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <496bf51a05092019337180466a at mail dot gmail dot com> <a06200704bf567b8c2eb0 at 10 dot 0 dot 1 dot 4> <496bf51a0509211826355b31bb at mail dot gmail dot com> <a06200702bf57caa5de4d at 10 dot 0 dot 1 dot 4> <496bf51a050922191027900e59 at mail dot gmail dot com> <a06200703bf59bdf0dd80 at [10 dot 0 dot 1 dot 4]> <0809ade5daadaea777c60fe4a3c4e71e at rpsystems dot net> <a06200710bf59cb3dfb3b at [10 dot 0 dot 1 dot 4]> <071a7167dbb0422dc47129a40a7a1e57 at rpsystems dot net>
You can use this bit of code to calculate the full rectangular (or whatever I'm supposed to call it) size of the picture, and the x and y coordinate of where the Object2D should be so the edges aren't clipped off.

dim w, h, newX, newY, newW, newH, rotation, cosR, sinR as double

w = imageWidth / 2.0
h = imageHeight / 2.0

cosR = cos(rotation)
sinR = sin(rotation)

newX = max( abs(cosR * w - sinR * h), abs(cosR * w + sinR * h) )
newY = max( abs(sinR * w + cosR * h), abs(sinR * w - cosR * h) )

newW = newX * 2.0
newH = newY * 2.0

Rotation is in radians and imageWidth and imageHeight are well... the width and height of the image. (This is taken out from the middle of other code. It should work, but if it doesn't, tell me. Also, you might have to handle rounding from double to integer to make sure a pixel isn't accidently clipped off, but I never really needed that myself so it isn't in here. A ceil (newX) and ceil(newY) would probably be easiest.)


---
Toon Van Acker <toon dot van dot acker at mac dot com>
             <http://homepage.mac.com/barthold.van.acker/realbasic/>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>