Allegro.cc Forums » Programming Questions » Transforming

 Edgar Reynaldo Major Reynaldo May 2007 dakatt,Please show more code. Please show us what you have or are trying right now, and tell us what you expect it to do.You say you've got the world rotated now. That's a good first step. So you know how to rotate. That's good.To rotate a rectangle in place takes a little more work, but not much.1. Get the current view matrix from allegro using al_get_current_transform. ```ALLEGRO_TRANSFORM t,original; t = *al_get_current_transform(); original = t; // save for later ``` 2. Decide on a pivot for your shape. Usually it's the center. You will translate by this vector before doing anything else so the rotation will work properly. ```al_translate_transform(&t , -centerx , -centery); ``` 3. Now that you have made the center of your rectangle the origin (0,0) with al_translate_transform, you can safely rotate it around this pivot. ```al_rotate_transform(&t , 45.0*M_PI/180.0);// rotate by 45 degrees ``` 4. Now you have to move your shape back to where it was, so translate by the opposite of the first translation. ```al_translate_transform(&t , centerx , centery); ``` 5. Now use the new transform and you're ready to draw your rectangle. ```al_use_transform(&t); /// Draw a regular rectangle //void al_draw_rectangle(float x1, float y1, float x2, float y2, // ALLEGRO_COLOR color, float thickness) al_draw_rectangle(0 , 0 , rwidth , rheight , al_map_rgb(0,255,0) , 5.0); ``` You draw the rectangle at (0,0,w,h) because your code translates by the rectangle's center so you don't have to draw it at its real position.6. Now clean up after yourself. ```al_use_transform(&original); ```