www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/06/03:09:22

From: ovek AT arcticnet DOT no (Ove Kaaven)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro sprite rotation
Date: Thu, 06 Feb 1997 01:17:51 GMT
Organization: Vplan Programvare AS
Lines: 71
Message-ID: <5dbb9b$m2u$1@troll.powertech.no>
References: <5c6mh9$2c2k AT elmo DOT cadvision DOT com> <LukhsKANVg6yEwCT AT talula DOT demon DOT co DOT uk>
NNTP-Posting-Host: alwayscold.darkness.arcticnet.no
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk> wrote:

>I've also heard mention of a rotation algorithm based on shearing the
>image first horizontally and then vertically, which can rotate by up to
>45 degrees (flips can then be used for the other 7 octants). I've never
>tried implementing this: does anyone have any experience of it? Could it
>be faster than my line-tracing method?

As far as I know, this can't be done accurately by shearing only
twice, however it is fully possible by doing it three times. I think
I've seen rotation reduced to three "skewings" in some mathematics
book or something.

Maybe it's possible with only two shears, though, but this would most
certainly get the scale wrong. I suppose two shears and one scaling is
more expensive than three shears, so I don't think I would try to get
that to work unless I would have to scale anyway.

As for its applicability, check out Wing Commander from Origin. Fly
close to a ship and take a spin, and watch carefully. How the shearing
is done should then be obvious, their implementation seem to have
taken some "shortcuts" (the first shear is done on the unscaled image,
and the last shear is integrated into the z-scaling, which looks a bit
messy close up).

PS. I decided to exercise my algebra, here's my results.

If a rotation

v = angle to rotate
x3 = x0*cos(v)+y0*sin(v)
y3 = y0*cos(v)-x0*sin(v)

is set equal to a triple skew

First skew:
x1 = x0 + y0 * s1
y1 = y0
Second skew:
x2 = x1
y2 = y1 + x1 * s2
Third skew:
x3 = x2 + y2 * s3
y3 = y2

I think we get (correct me if I'm wrong)

s1 = (1-cos(v))/sin(v)
s2 = -sin(v)
s3 = (1-cos(v))/sin(v) = s1

So if you wish, you can check whether this way of rotating is faster
or actually slower than the one you have. I imagine that since the
data would be copied three times instead of just once, it may be
slower, especially on big sprites. But it should be fairly easy to
make a test implementation, to make sure. (You might even think of a
way to avoid one or two of the copies.)

If you want to go for two skews and one scaling, I think we get:

s1 = sin(v)/cos(v)
s2 = -sin(v)*cos(v)
scaleX = cos(v)
scaleY = 1/cos(v)

which might be useful for Wing Commander style games, where objects
have to be scaled anyway. Do as WC did and do the last shear in the
scaling routine, and you might get a pretty fast object engine (with
the same drawbacks as WC though).


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019