[AD] rotate_sprite_h_flip |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hi.
This is my first patch to the actual library (though I've made alterations
to the grabber before) so please bare with me.
I've added four new functions:
rotate_sprite_flip
rotate_scaled_sprite_flip
pivot_sprite_flip
pivot_scaled_sprite_flip
Each of these are identical to their existing counterparts, except for the
added (int h_flip, int v_flip) at the end of the parameter list. Passing
non-zero values to either of these allows you to rotate and sprite and flip
it at the same time, something that I frequently need to do, and I'm sure
it must be quicker to do it on the fly than to flip it to a temporary
bitmap and then rotate that.
I've modified the existing functions to call their flipping counterparts
with 0, 0, and I've used those (condition ? statement1 :
statement2) statements inside the routine, to save having to copy out all
the code for every single colour depth a second time with flipping enabled.
If you'd rather I did it that way, because it would speed it up (since it
wouldn't have to check if flipping is enabled or not every single pixel)
then I could rewrite it to do that, but my current method saves duplicating
a lot of code.
Hope this is useful,
Andy Geers
P.S. I wasn't sure if you could patch two separate files from one patch, so
I've included 'patch' for rotate.c and 'patch2' for allegro.h. I made them
from within the 'allegro' directory.--- include/oldallegro.h Sun Mar 26 15:14:32 2000
+++ include/allegro.h Sun Apr 23 17:00:54 2000
@@ -1249,9 +1249,13 @@
AL_FUNC(void, masked_stretch_blit, (BITMAP *s, BITMAP *d, int s_x, int s_y, int s_w, int s_h, int d_x, int d_y, int d_w, int d_h));
AL_FUNC(void, stretch_sprite, (BITMAP *bmp, BITMAP *sprite, int x, int y, int w, int h));
AL_FUNC(void, rotate_sprite, (BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle));
+AL_FUNC(void, rotate_sprite_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, int h_flip, int v_flip));
AL_FUNC(void, rotate_scaled_sprite, (BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, fixed scale));
+AL_FUNC(void, rotate_scaled_sprite_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, fixed scale, int h_flip, int v_flip));
AL_FUNC(void, pivot_sprite, (BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle));
+AL_FUNC(void, pivot_sprite_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle, int h_flip, int v_flip));
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, pivot_scaled_sprite_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle, fixed scale, int h_flip, int v_flip));
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/oldrotate.c Sun Jan 30 21:46:56 2000
+++ src/rotate.c Sun Apr 23 17:02:04 2000
@@ -12,6 +12,8 @@
*
* By Shawn Hargreaves.
*
+ * Flipping functions added by Andrew Geers.
+ *
* See readme.txt for copyright information.
*/
@@ -52,16 +54,32 @@
*/
void pivot_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle)
{
- pivot_scaled_sprite(bmp, sprite, x, y, cx, cy, angle, itofix(1));
+ pivot_scaled_sprite_flip(bmp, sprite, x, y, cx, cy, angle, itofix(1), 0, 0);
}
-
+/* pivot_sprite_flip:
+ * Like pivot_sprite, except it flips the sprite about the specified
+ * axis before drawing.
+ */
+void pivot_sprite_flip(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle, int h_flip, int v_flip)
+{
+ pivot_scaled_sprite_flip(bmp, sprite, x, y, cx, cy, angle, itofix(1), h_flip, v_flip);
+}
/* pivot_scaled_sprite:
* Rotates a sprite around the specified pivot centre point.
*/
void pivot_scaled_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle, fixed scale)
{
+ pivot_scaled_sprite_flip(bmp, sprite, x, y, cx, cy, angle, scale, 0, 0);
+}
+
+/* pivot_scaled_sprite_flip:
+ * Like pivot_scaled_sprite, except it flips the sprite about the
+ * specified axis before drawing it.
+ */
+void pivot_scaled_sprite_flip(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle, fixed scale, int h_flip, int v_flip)
+{
x -= fixtoi(sprite->w*scale/2);
y -= fixtoi(sprite->h*scale/2);
@@ -71,7 +89,7 @@
x -= fixtoi(fmul(cx*fcos(angle) - cy*fsin(angle), scale));
y -= fixtoi(fmul(cx*fsin(angle) + cy*fcos(angle), scale));
- rotate_scaled_sprite(bmp, sprite, x, y, angle, scale);
+ rotate_scaled_sprite_flip(bmp, sprite, x, y, angle, scale, h_flip, v_flip);
}
@@ -85,9 +103,17 @@
*/
void rotate_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle)
{
- rotate_scaled_sprite(bmp, sprite, x, y, angle, itofix(1));
+ rotate_scaled_sprite_flip(bmp, sprite, x, y, angle, itofix(1), 0, 0);
}
+/* rotate_sprite_flip:
+ * Like rotate_sprite, except it flips the sprite around the specified
+ * axis before drawing it.
+ */
+void rotate_sprite_flip(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, int h_flip, int v_flip)
+{
+ rotate_scaled_sprite_flip(bmp, sprite, x, y, angle, itofix(1), h_flip, v_flip);
+}
/* rotate_scaled_sprite:
@@ -99,6 +125,15 @@
*/
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_flip:
+ * Like rotate_scaled_sprite, except it flips the sprite about the specified
+ * axis before drawing it.
+ */
+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;
fixed w, h;
@@ -200,7 +235,7 @@
case 8:
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)],
(pixel != 0));
break;
@@ -211,7 +246,7 @@
case 15:
case 16:
DO_ROTATE(16, sizeof(short),
- pixel = ((unsigned short *)sprite->line[sy])[sx],
+ pixel = ((unsigned short *)sprite->line[(v_flip ? sprite->h - sy - 1 : sy)])[(h_flip ? sprite->w - sx - 1 : sx)],
(pixel != bmp->vtable->mask_color));
break;
@@ -221,7 +256,7 @@
case 24:
DO_ROTATE(24, 3,
- bmp_select(sprite); pixel = bmp_read24((unsigned long)(sprite->line[sy]+sx*3)); bmp_select(bmp),
+ bmp_select(sprite); pixel = bmp_read24((unsigned long)(sprite->line[(v_flip ? sprite->h - sy - 1 : sy)]+(h_flip ? sprite->w - sx - 1 : sx)*3)); bmp_select(bmp),
(pixel != bmp->vtable->mask_color));
break;
@@ -231,7 +266,7 @@
case 32:
DO_ROTATE(32, sizeof(long),
- pixel = ((unsigned long *)sprite->line[sy])[sx],
+ pixel = ((unsigned long *)sprite->line[(v_flip ? sprite->h - sy - 1 : sy)])[(h_flip ? sprite->w - sx - 1 : sx)],
(pixel != bmp->vtable->mask_color));
break;
@@ -258,8 +293,8 @@
sy = fixtoi(f3y);
if ((unsigned)sy < (unsigned)sprite->h) {
- if (sprite->line[sy][sx])
- _farnspokeb(addr, sprite->line[sy][sx]);
+ if (sprite->line[(v_flip ? sprite->h - sy - 1 : sy)][(h_flip ? sprite->w - sx - 1 : sx)])
+ _farnspokeb(addr, sprite->line[(v_flip ? sprite->h - sy - 1 : sy)][(h_flip ? sprite->w - sx - 1 : sx)]);
}
}
--
Bart's Blackboard Quote:
I will not conduct my own fire drills.
Andrew Geers
mailto:andy@xxxxxxxxxx
http://www.geerswj.clara.net