Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Bitmap Draw Stacking

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Bitmap Draw Stacking
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

SiegeLord said:

Lastly, there is a function to simplify this process a bit:

ALLEGRO_TRANSFORM T;
al_build_transform(&T, this->getX() + this->width / 2, this->getY() + this->height / 2, this->getScale(), this->getScale(), this->getRotation());
al_use_transform(&T);
al_draw_bitmap(bmp, -this->width / 2, -this->height / 2, 0, 0);

It's missing the first translation, that's all. So it actually wouldn't work, because al_build_transform sets the identity first.

Trent Gamblin
Member #261
April 2000
avatar

Elias said:

Why don't we have an al_draw_rotated_scaled_bitmap_region function? The function name is long, yes - and you can do the same thing with transformations. But we have all the other variants for doing it in a single function call so why not this?

I think it would be good, too. It's a fairly common thing to want to do, so it's a reasonable thing to add. If it weren't for the new test cases needed I could add it tomorrow. I haven't looked at adding test cases yet so I have no idea if it's a big deal. I might try it anyway if I remember this thread... but that's not a promise.

SiegeLord
Member #7,827
October 2006
avatar

It's missing the first translation, that's all.

No, it's not. As my diagram showed, it got transfered to the coordinates passed to al_draw_bitmap:

ALLEGRO_TRANSFORM T;
al_build_transform(&T, this->getX() + this->width / 2, this->getY() + this->height / 2, this->getScale(), this->getScale(), this->getRotation());
al_use_transform(&T);
al_draw_bitmap(bmp, -this->width / 2, -this->height / 2, 0, 0);

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Wouldn't you have to modify the final translation in al_draw_bitmap to account for the scaling performed in al_build_transform though? And what about the rotation? It's scaled, then rotated about its top left corner, which is not what you want.

SiegeLord
Member #7,827
October 2006
avatar

final translation in al_draw_bitmap

The translation in al_draw_bitmap is applied first, and then it is transformed using the current transformation. Doing it the other way wouldn't make any sense (it would make it clunky to use the transformations for a camera system, for example).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Elias
Member #358
May 2000

I think it would be good, too. It's a fairly common thing to want to do, so it's a reasonable thing to add. If it weren't forithe new test cases needed I could add it tomorrow. I haven't looked at adding test cases yet so I have no idea if it's a big deal. I might try it anyway if I remember this thread... but that'snot a promise.

I can also add it, just could have been that there's a reason against.
And yeah, we probably should make unit tests mandatory for any new additions :)

--
"Either help out or stop whining" - Evert

 1   2 


Go to: