Clipping / Rotation
Kev Callahan

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

? Apply the transformation to the rectangle position and then respect the original boundaries ?

I don't think you can clip a non AABB with Allegro, but maybe with OpenGL?

Not sure what you want.

Kev Callahan

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

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.

Kev Callahan

al_transform_coordinates() .. !

Exactly what I need; hadn't realised such a function existed :-[

Thanks SiegeLord.

Thread #617012. Printed from Allegro.cc