Mail Archives: djgpp/1997/02/06/03:09:22
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 -