Allegro.cc Forums » Programming Questions » Transformations in allegro

 Transformations in allegro
 baskerbill Member #16,397 June 2016 I'm trying to port some code from processing, and I've found problems with the PushMatrix and PopMatrix. Example: pushMatrix(); translate(x,y); rotate(alfa); translate(desx,desy); image(bitmap,0,0); pushMatrix(); translate(x,y); popMatrix(); popMatrix();Transformations in allegro are built as:ALLEGRO_TRANSFORM t;al_copy_transform(&old,&t);al_intentity_transform(&t)al_translate_transform(x,y);al_rotate_transform(alfa);al_use_transform(&t)al_draw_bitmap(bitmap,0,0);al_identity_transform(&old);al_use_transform(&old);It works perfectly with one bitmap, but I haven't foud a way to concatenate two transforms the same way as with pushMatrix, and I think I don't fully understand the behavior of allegro transformations.Any tip or help will be wellcome. Thanks!
 Mark Oates Member #1,146 March 2001 In AllegroFlare's placement2d, you get these two functions: #SelectExpand 1void placement2d::start_transform() 2{ 3 ALLEGRO_TRANSFORM transform; 4 5 al_copy_transform(&previous_transform, al_get_current_transform()); 6 al_identity_transform(&transform); 7 8 al_translate_transform(&transform, -align.x*size.x, -align.y*size.y); 9 al_scale_transform(&transform, scale.x, scale.y); 10 al_translate_transform(&transform, anchor.x, anchor.y); 11 al_rotate_transform(&transform, rotation); 12 al_translate_transform(&transform, position.x, position.y); 13 14 al_compose_transform(&transform, &previous_transform); 15 16 al_use_transform(&transform); 17} 18 19 20 21 22void placement2d::restore_transform() 23{ 24 al_use_transform(&previous_transform); 25} previous_transform is an ALLEGRO_TRANSFORM, member of placement2d --Streaming KrampusHack 2020 LIVE on Twitch - (status: ⭕️ OFFLINE) - https://twitch.tv/markoates)AllegroFlare • allegro.cc markdown • Allegro logo
 baskerbill Member #16,397 June 2016 Thank you very much. I missed the function al_compose_transform, which is the key to combine the matrix stack.I should read more carefully the man pages. Again, thank you for your time.
 Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads