[Gambas-user] the math behind full screen rotation

Kevin Fishburne kevinfishburne at ...1887...
Sat Mar 26 04:08:19 CET 2011


On 03/24/2011 12:05 AM, John Spikowski wrote:
> On Wed, 2011-03-23 at 23:03 -0400, Kevin Fishburne wrote:
>
>> That will probably work, but there should be a mathematical way to
>> compensate for not cropping the image twice, or even once. As long as
>> the entire image is preserved by the rotation function (it is) and it
>> behaves in a predictable manner (it does), the camera's coordinates
>> should be able to be translated and rotated so that they are in the same
>> position in the rotated image as they were in the non-rotated image. For
>> the sake of efficiency that is what I'm trying to accomplish.
> This thread might help. (or not)
>
> http://forums.libsdl.org/viewtopic.php?t=2983&sid=1d2c6a94470c0fd56f3f542cd702ec37

No go, but thanks for trying to help. Right now my code looks something 
like this:

   ' Convert camera coordinates to their distance from the center of the 
tile grid.
   newcx = newcx - (bworkspace.Width / 2)
   newcy = newcy - (bworkspace.Height / 2)

   ' Rotate camera.
   newcx = Cos(Rad(- Client.orientation)) * newcx - Sin(Rad(- 
Client.orientation)) * newcy
   newcy = Sin(Rad(- Client.orientation)) * newcx + Cos(Rad(- 
Client.orientation)) * newcy

   ' Adjust the camera coordinates to fit the rotated tile grid.
   newcx = newcx + (brotated.Width / 2)
   newcy = newcy + (brotated.Height / 2)

   ' Draw the rotated workspace centered on the camera and cropped by 
the render window size.
   Draw.Image(brotated, 0, 0, swidth, sheight, newcx - swidth / 2, newcy 
- sheight / 2, swidth, sheight)

First I figure out the distance of the camera from the center of the 
non-rotated image. Then I rotate the camera using those distance values 
as the camera's coordinates. That should in effect make the center of 
the non-rotated image the origin of rotation. I then take the rotated 
camera values and add them to the center point of the rotated image to 
determine the camera's position in the rotated image.

Maybe my logic is wrong, maybe it's my math. Maybe demons are hovering 
over my shoulder casting black magic. I'm about to hit up Facebook for 
an old math whiz I knew in high school, as gamedev.net has failed me as 
well. <blood curdling Arnold scream from Predator>

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list