Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Clipping / Rotation

This thread is locked; no one can reply to it. rss feed Print
Clipping / Rotation
Kev Callahan
Member #6,022
July 2005
avatar

An interesting issue/problem I think -

I'm using a landscape screen in portrait mode and before I draw everything to screen I setup transformation as follows -

// initiate portrait rotation
al_identity_transform(&transf);
al_translate_transform(&transf, screen_w/-2, screen_w/-2); // move to centre
al_rotate_transform(&transf, screen_angle_rad);            // rotate
al_translate_transform(&transf, screen_w/2, screen_w/2);   // return to top left corner
al_use_transform(&transf);

However, this (obviously) doesn't affect the clipping coordinates..

I have a method to convert from landscape to portrait values by subtracting/adding x,y,width & height values from the screen dimensions, which works fine for (say a specific) 90 degree rotation..

I wondered if there was a more flexible method to create the new clipping rectangle after a rotation?

Anyone..?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Kev Callahan
Member #6,022
July 2005
avatar

Sorry I'm not explaining myself very well ;)

I do the following so I can use a 'standard screen in portrait mode (ie rotate 90 degrees c/w) -

al_build_transform(&transf, screen_w, 0.0, 1.0, 1.0, screen_angle_rad);
al_use_transform  (&transf);

I have the clipping rectangle defined for portrait mode but the above transformation has no effect on the clipping values, so I have to adjust them as follows (clx,y,w,h are original portrait values, lx,y,w,h are landscape ones that Allegro expects)-

// fix clipping rectangle for portrait (rotation transforms don't affect clipping)
lx  = screen_w - cly - clh/2;
ly  =            clx - clw/2;
lw  =            clh;
lh  =            clw;

I just wondered if there was a quick method that would work for any angle rotation.

SiegeLord
Member #7,827
October 2006
avatar

You can take each corner of your screen, [[0, 0], [w, 0], ...] and transform them using your transformation via al_transform_coordinates. You can then compute the new bounding box for those coordinates via a judicious use of min and max.

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

Kev Callahan
Member #6,022
July 2005
avatar

Go to: