From: galetti@uservx.plk.af.mil
Newsgroups: comp.sys.amiga.programmer
Subject: Re: BitMap rotating code...
Date: 7 Apr 92 19:21:22 GMT
Article-I.D.: uservx.1992Apr7.192122.32736
Organization: Phillips Laboratory - Kirtland AFB

In article <1992Apr4.124025.4807@cccan.uucp>, entity@cccan.uucp (Cybernetworx) writes:
> In article <1992Mar31.115613.3720@CSD-NewsHost.Stanford.EDU> amorgan@Xenon.Stanford.EDU (Crunchy Frog) writes:
>>In article <1992Mar31.175544.4681@kosmos.wcc.govt.nz> 
>>  lennox_r@kosmos.wcc.govt.nz writes:
>>
>>>Can anybody point me in the direction of some fast bitmap rotating routines?
>>>The faster the better :-)
>>
>>>I need to rotate a small bitmap through a given angle... and it has to be fast!
>>
>>How small are they and how many of them are there?
>>
>>At the very least tableize your sines and cosines.  If the bitmaps are small

	(Stuff deleted)
> 
> Agggh!  Something like this is TOO slow for something like a game.  If you
> have a set bitmap size you want to rotate, (eg all BOBs are 64x64) then
> the FASTEST way that I know of is to use a 2 pass transformation.  The first
> pass you do a column-preserving transformation.  Second pass you do a
> row-preserving transformation.  By taking specific cases for 0-45 degrees,

The two-pass shear you describe here won't preserve the shape of the rotated 
object.  Along with two shears you also need two scaling operations.  The
scaling operations can be incorporated into the shears, but this involves
pixel operations and not simple row and column operations like you describe
here.  It is possible to decompose the general rotation matrix into three
shears which do preserve the shape of the object, assuming square pixels of
course.  And of course, we Amiga people don't have square pixels, but if
you're doing simple rotations for a game, you may not care about this.  Also,
if you're not too concerned with the way the object distorts with the two-pass
shearing algorithm, that might be ok for your purposes too.

Note that the blitter is ideal for shearing.  Also, if you're really ambitious,
you can use the copper to perform the third shear with the three-pass
algorithm.  You need to have a different copperlist for each possible rotation
angle, though.

> 45-90, etc. you can have this routine FLY!  If you don't have arbitrary bitmap
> sizes, you can use tables to significantly speed this up as well since you can
> specify for every given angle exactly how much to shift each scanline
> horizontally and vertically.  The table generated is small as long as your
> bitmap is not too huge.  To handle cases let's say between 45-90 degrees,
> first flip the image horizontally and then do the 90-degree as your angle and
> shift the other way.  Similarly for all the other quadrants.  This method
> DESTROYS the normal method of rotating bitmaps in terms of sheer execution
> speed.

And I'll second that--You absolutely DO NOT want to rotate bitmaps with the
"normal method" unless you've got all the time in the world.

> 
> 
> -- 
>           __
>     __   ///
>     \\\ ///               UUCP:   ...uunet!utai!lsuc!becker!cccan!entity
>  CYBERNETWORX             INET:   entity@cccan.gts.org
>  
-- 
  ___________________________________________________________________________
 /   Ralph Galetti                  Internet:   galetti@uservx.plk.af.mil    \
|    PL/LTT                         Interests:  computers, music, computers   |
|    Kirtland AFB, NM 87117-6008                and music, golf, sleep.       |
 \"What's he like?  It's not important--Particle Man." - They Might Be Giants/
Newsgroups: comp.sys.amiga.programmer