[Gambas-user] the math behind full screen rotation
Kevin Fishburne
kevinfishburne at ...1887...
Thu Mar 24 04:03:20 CET 2011
On 03/23/2011 09:13 AM, Benoît Minisini wrote:
>> I'm trying to implement full screen rotation in an overhead-perspective
>> game. The angle of the screen is locked to the angle of the player. If
>> the player turns then the screen also turns, meaning the player is
>> always facing "up". Here is an example of exactly what I'm trying to do:
>> http://www.youtube.com/watch?v=lX_bhygaSy0
>>
>> These are the variables I'm working with:
>>
>> orientation ' Player/camera's angle in degrees (Rad(orientation)).
>> bworkspace ' Image buffer containing the original non-rotated background.
>> brotated ' Image buffer containing the new rotated bworkspace.
>> cx ' Camera's x coordinate in bworkspace.
>> cy ' Camera's y coordinate in bworkspace.
>>
>> brotated is larger than bworkspace because the rotation function doesn't
>> crop the rotated image:
>>
>> http://www.eightvirtues.com/sanctimonia/images/bworkspace.png (512x512)
>> http://www.eightvirtues.com/sanctimonia/images/brotated.png(725x726)
>>
>> How do I convert the camera coordinates (cx, cy) in bworkspace to the
>> equivalent coordinates in brotated? Essentially I need bworkspace to be
>> rotated around (cx,cy), but the rotate function only rotates about the
>> center of the image. Because of this I think I need some combination of
>> rotating (cx,cy) about some point and offseting it as well. Reading my
>> own email it sounds simple, but I've tried so many things that I can't
>> believe I haven't solved the problem through sheer luck.
> The Rotate method is slow, and it rotates only around the image center.
>
> So you have to crop the image first, rotate it, and crop it again. The initial
> crop should be the size of the final display * SQR(2), so that any rotation
> will fit.
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.
--
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