Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Rotating bitmap in local and global axis ?

This thread is locked; no one can reply to it. rss feed Print
Rotating bitmap in local and global axis ?
Thinkal VB
Member #16,859
May 2018

My 2D top-down shooter game wants some syntactic sugar to rotate the bitmap and the whole bitmap around another bitmap or point (which is the player). Please help me out
Thanks in advance

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Dizzy Egg
Member #10,824
March 2009
avatar

rotate_bitmap_around_another_bitmap();

Cookies please.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Thinkal VB
Member #16,859
May 2018

Edgar Reynaldo and Dizzy Egg - than you for the replay.
I will try to sort out a way to do that using trigonometry or simple geometric mathematics.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Neil Roy
Member #2,229
April 2002
avatar

Take the rotation of the world, add in the rotation of the object in the world with it, then draw it on your rotated world.

---
“I love you too.” - last words of Wanda Roy

Thinkal VB
Member #16,859
May 2018

Edgar Reynaldo and Neil Roy- thank you for replying
I fixed it using the transform

al_identity_transform(&transform);
al_translate_transform(&transform, -playerX, -playerY);
al_rotate_transform(&transform, cameraRotation * 3.14 / 180);
al_translate_transform(&transform, playerX, playerY);
al_use_transform(&transform);

when drawing the player i used rotation (360 - cameraRotation), so that the player won't rotate, rather the world will rotate around the player.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Thinkal VB
Member #16,859
May 2018

Thank you Edgar Reynaldo, for your compliments and help.

Elias
Member #358
May 2000

You should probably use a few more decimal places with your 3.14 constant there or after you spin the camera a few times it will start being off...

--
"Either help out or stop whining" - Evert

Eric Johnson
Member #14,841
January 2013
avatar

Elias said:

You should probably use a few more decimal places with your 3.14 constant there or after you spin the camera a few times it will start being off...

He should use ALLEGRO_PI.

Thinkal VB
Member #16,859
May 2018

Thank you Elias and Eric Johnson,
I used #define PI 3.14159f in my actual code.
That code was purely representational(in the post). However, thank you for letting me know about the ALLEGRO_PI. I will change my code to use ALLEGRO_PI as it is more precise.

Go to: