Re: [AD] rotate_sprite_h_flip

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Andrew Geers patched:
> DO_ROTATE(8, 1,
>-          pixel = sprite->line[sy][sx],
>+          pixel = sprite->line[(v_flip ? sprite->h - sy - 1 : sy)]
>+                              [(h_flip ? sprite->w - sx - 1 : sx)],

Cool, these functions can be useful. But I think you can do it both
without the speed penalty induced by extra conditions in the inner loop,
and without duplicating the inner loops. You just need to change the
loop direction. This can be done by initially (before the loops) change
f2x (which is the fixed point representation of sx) like this:

   if (h_flip)
      f2x = itofix(sprite->h) - f2x - itofix(1);
   if (v_flip)
      f2y = itofix(sprite->w) - f2y - itofix(1);

and then increase the variables backwards, ie put the following before
the loops:

   if(h_flip)
      f2xd = -f2xd;
   if(v_flip)
      f2yd = -f2yd;

This way no extra code is needed in the inner loops at all. Sorry I'm
talking so much without having a patch :-). I'll be far too busy in
school for a month or so to do any coding, but I will implement it later
if no one else does it.

Btw, it might be easier to implement if you only support hflip (not
vflip) in the lowlevel rotate_scaled_sprite_flip() (or the other way
around), since vflip can be faked by doing hflip and then add 180
degrees to the angle. Similary, flipping both horizontally and
vertically is the same as just rotating 180 degrees.

Sven



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/