rotating primitives?
sensmaster

What is the best way to rotate a primitive?
For example, I am trying to rotate a rectangle with a reference point.
I have no idea how to do this..

Please help me :(

William Labbett

Take a look at this :-

https://www.allegro.cc/manual/5/al_draw_rotated_bitmap

Is it what you need ?

You could make a bitmap of the rectangle first and then rotate it.

SiegeLord
/* Setup the transformation */
ALLEGRO_TRANSFORM trans;
al_identity_transform(&trans);
al_translate_transform(&trans, -ref_x, -ref_y);
al_rotate_transform(&trans, angle_in_radians);
al_translate_transform(&trans, ref_x, ref_y);

al_use_transform(&trans);
/* Draw whatevs here */

/* Turn off the rotation */
al_identity_transform(&trans);
al_use_transform(&trans);

sensmaster

First of all,
thanks for the reply.

I am not asking for the bitmap to rotate,
Just a simple primitive that I have drawn using
al_draw_rectangle(...)

any ideas? :(

SiegeLord
Quote:

any ideas? :(

Did I post in invisible ink or something?

Arthur Kalliokoski
SiegeLord said:

Did I post in invisible ink or something?

It's all geek to him...

sensmaster

I have seen your code, but doesn't that rotate the whole screen?

For instance, I have a circle and a rectangle.
I only want to rotate the rectangle and circle will remain as it is.
If I use your code, doesn't it rotate the whole screen?

Arthur Kalliokoski

It rotates whatever's drawn next until the al_identity_transform() and al_use_transform() resets it to normal.

sensmaster

oh thanks...
I am new at this :(

Thanks so much. I got it working now.

I have one more question.
Could you please explain how its working?

al_translate_transform(&trans, - ref_x, - ref_y);
al_rotate_transform(&trans, Degrees * 3.1415 / 180);
al_translate_transform(&trans, ref_x, ref_y);

I do not understand those 3 steps...

Arthur Kalliokoski
SiegeLord said:

al_translate_transform(&trans, - ref_x, - ref_y);
al_rotate_transform(&trans, Degrees * 3.1415 / 180);
al_translate_transform(&trans, ref_x, ref_y);

al_translate_transform() moves it across/updown to set position on the screen. The reason the minus signs are stuck in there is because you don't move the camera, you move the world (think about that a minute).

al_rotate_transform() twists it around to rotate it.

al_translate_transform() moves it once again on screen to re-adjust position because al_rotate_transform() moved it from the rotation point.

Thomas Fjellstrom

The main reason for the two transforms is it makes it so your origin is the center of the object you're trying to rotate. If you didn't transform like that, you'd end up rotating around a different center, and not actually just rotating your object.

Thread #611588. Printed from Allegro.cc