[AD] rotate_sprite_v_flip

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


Hi.

Based upon Sven's suggestions, I've redone the work I did last weekend. Included is a patch from Allegro 3.9.32 to add rotate_sprite_v_flip, rotate_scaled_sprite_v_flip, pivot_sprite_v_flip and pivot_scaled_sprite_v_flip. This just has one conditional clause at the start of the loop, and so is barely slower than the original functions. If people think it would be worth it, I could make a rotate_sprite_h_flip that just adds 128 to the angle and then passes it to rotate_sprite_v_flip, but I think individual programmers can do that.
I've also added something to exsprite to demonstrate the use of this function.

In addition I've included patch3 to remove some compilation warnings with binutils 2.9.51, about indirect lcalls without a *.

Andy 
--- examples\exsprite.c Sun Jan 30 21:46:56 2000
+++ examples\exsprite.c	Sat May  6 15:46:08 2000
@@ -143,6 +143,19 @@
       angle += 4;
    } while (!next);
 
+   clear_keybuf();
+   rectfill(screen, 0, 190, 320, 200, 0);
+   textout(screen, font, "Now using rotate_sprite_v_flip", 1, 190, 15);
+
+   do {
+      /* The last argument to rotate_sprite_v_flip() is a fixed point type,
+       * so I had to use itofix() routine (integer to fixed).
+       */
+      rotate_sprite_v_flip(sprite_buffer, running_data[frame_number].dat, 0, 0, itofix(angle));
+      animate();
+      angle += 4;
+   } while (!next);
+
    unload_datafile(running_data);
    return 0;
 }
--- src/dos/gripfnc.s   Sun Jan 30 21:46:58 2000
+++ src/dos/gripfnc.s	Sat May  6 15:37:08 2000
@@ -19,7 +19,7 @@
 #include "../i386/asmdefs.inc"
 
 
-#define GRIP_CALL             lcall GLOBL(GRIP_Thunk) + 8
+#define GRIP_CALL             lcall *GLOBL(GRIP_Thunk) + 8
 
 
 .extern _GRIP_Thunk
--- include/allegro.h   Sun Mar 26 15:14:32 2000
+++ include/allegro.h	Sat May  6 15:23:20 2000
@@ -1252,6 +1252,10 @@
 AL_FUNC(void, rotate_scaled_sprite, (BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, fixed scale));
 AL_FUNC(void, pivot_sprite, (BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle));
 AL_FUNC(void, pivot_scaled_sprite, (BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle, fixed scale));
+AL_FUNC(void, rotate_sprite_v_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle));
+AL_FUNC(void, rotate_scaled_sprite_v_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, fixed scale));
+AL_FUNC(void, pivot_sprite_v_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle));
+AL_FUNC(void, pivot_scaled_sprite_v_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle, fixed scale));
 AL_FUNC(void, draw_gouraud_sprite, (BITMAP *bmp, BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4));
 AL_FUNC(void, clear, (BITMAP *bitmap));
 
--- src/rotate.c  Sun Jan 30 21:46:56 2000
+++ src/rotate.c	Sat May  6 15:51:36 2000
@@ -12,6 +12,8 @@
  *
  *      By Shawn Hargreaves.
  *
+ *      Flipping routines by Andrew Geers.
+ *
  *      See readme.txt for copyright information.
  */
 
@@ -55,6 +57,13 @@
    pivot_scaled_sprite(bmp, sprite, x, y, cx, cy, angle, itofix(1));
 }
 
+/* pivot_sprite_v_flip:
+ *  Similar to pivot_sprite, except flips the sprite vertically first.
+ */
+void pivot_sprite_v_flip(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle)
+{
+   pivot_scaled_sprite_v_flip(bmp, sprite, x, y, cx, cy, angle, itofix(1));
+}
 
 
 /* pivot_scaled_sprite:
@@ -74,6 +83,22 @@
    rotate_scaled_sprite(bmp, sprite, x, y, angle, scale);
 }
 
+/* pivot_scaled_sprite_v_flip:
+ *  Similar to pivot_scaled_sprite, except flips the sprite vertically first.
+ */
+void pivot_scaled_sprite_v_flip(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle, fixed scale)
+{
+   x -= fixtoi(sprite->w*scale/2);
+   y -= fixtoi(sprite->h*scale/2);
+
+   cx -= sprite->w/2;
+   cy -= sprite->h/2;
+
+   x -= fixtoi(fmul(cx*fcos(angle) - cy*fsin(angle), scale));
+   y -= fixtoi(fmul(cx*fsin(angle) + cy*fcos(angle), scale));
+
+   rotate_scaled_sprite_v_flip(bmp, sprite, x, y, angle, scale);
+}
 
 
 /* rotate_sprite:
@@ -88,16 +113,19 @@
    rotate_scaled_sprite(bmp, sprite, x, y, angle, itofix(1));
 }
 
+/* rotate_sprite_v_flip:
+ *  Similar to rotate_sprite, except flips the sprite vertically first.
+ */
+void rotate_sprite_v_flip(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle)
+{
+   rotate_scaled_sprite_v_flip(bmp, sprite, x, y, angle, itofix(1));
+}
 
 
-/* rotate_scaled_sprite:
- *  Draws a sprite image onto a bitmap at the specified position, rotating 
- *  it by the specified angle. The angle is a fixed point 16.16 number in 
- *  the same format used by the fixed point trig routines, with 256 equal 
- *  to a full circle, 64 a right angle, etc. This function can draw onto
- *  both linear and mode-X bitmaps.
+/* rotate_scaled_sprite_flip:
+ *  Rotates and scales a sprite, optionally flipping it about either axis.
  */
-void rotate_scaled_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, fixed scale)
+void rotate_scaled_sprite_flip(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, fixed scale, int h_flip, int v_flip)
 {
    fixed f1x, f1y, f1xd, f1yd;
    fixed f2x, f2y, f2xd, f2yd;
@@ -188,11 +216,21 @@
 
    bmp_select(bmp);
 
+   if (h_flip)
+      f2xd = -f2xd;
+   if (v_flip)
+      f2yd = -f2yd;
+
    /* and trace a bunch of lines through the bitmaps */
    for (dy=hgap-1; dy>=0; dy--) {
       f2x = f1x;
       f2y = f1y;
 
+      if (h_flip)
+         f2x = itofix(sprite->h) - f2x - itofix(1);
+      if (v_flip)
+         f2y = itofix(sprite->w) - f2y - itofix(1);
+
       if (is_linear_bitmap(bmp)) {           /* draw onto a linear bitmap */
 	 switch (bitmap_color_depth(bmp)) {
 
@@ -282,3 +320,22 @@
    bmp_unwrite_line(bmp);
 }
 
+/* rotate_scaled_sprite:
+ *  Draws a sprite image onto a bitmap at the specified position, rotating 
+ *  it by the specified angle. The angle is a fixed point 16.16 number in 
+ *  the same format used by the fixed point trig routines, with 256 equal 
+ *  to a full circle, 64 a right angle, etc. This function can draw onto
+ *  both linear and mode-X bitmaps.
+ */
+void rotate_scaled_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, fixed scale)
+{
+   rotate_scaled_sprite_flip(bmp, sprite, x, y, angle, scale, 0, 0);
+}
+
+/* rotate_scaled_sprite_v_flip:
+ *  Similar to rotate_scaled_sprite, except flips the sprite vertically first.
+ */
+void rotate_scaled_sprite_v_flip(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, fixed scale)
+{
+	rotate_scaled_sprite_flip(bmp, sprite, x, y, angle, scale, 0, 1);
+}
--
Bart's Blackboard Quote:
I will not bury the new kid.

Andrew Geers
mailto:andy@xxxxxxxxxx
http://www.geerswj.clara.net



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