SFML community forums

Help => Graphics => Topic started by: Ahmed5036 on December 28, 2020, 10:34:17 am

Title: Rotate a Image around its center/Axis
Post by: Ahmed5036 on December 28, 2020, 10:34:17 am
Hi there, I'm new to SFML and a student and using SFML 2.4.2 version
I've selected a project on Music Player. I've completed it using Linked list but my teacher asked me to do some animation and I've searched and couldn't find any help.
I wanted to the following Disc image to rotate around its center.
Title: Re: Rotate a Image around its center/Axis
Post by: Stauricus on December 28, 2020, 12:17:30 pm
hi
I didn't really get what you do need help for.
but the usual way would be to just set the origin of the sprite to the center and rotate it by X degrees each Y milliseconds

https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php
https://www.sfml-dev.org/tutorials/2.5/graphics-transform.php

https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Transformable.php#a56c67bd80aae8418d13fb96c034d25ec
https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Transformable.php#a32baf2bf1a74699b03bf8c95030a38ed
Title: Re: Rotate a Image around its center/Axis
Post by: Hapax on December 28, 2020, 07:29:08 pm
Just as a general rule to remember, transformables always rotate around its origin.

So, yes, as said above, if you want to rotate around its centre, its origin must be at its centre.

Indeed, all transformations are based around the origin: scale will scale outwards from its origin and setting its position technically sets where its origin will be (this means that you will likely need to reposition it after changing its origin - set its new position to where you want its centre to be, for example).
Title: Re: Rotate a Image around its center/Axis
Post by: calibru99 on January 05, 2021, 12:14:55 am
Dunno if this helps but when I first had this problem my main issue was that i was drawing the certain piece and setting its position/origin inside a loop. this resulted in the fact that with every loop iteration the origin/position of it would shift, as i was setting the origin everytime.
long story short: set the origin in another part other than where you loop thru and draw the shape, this way the rotation will work 100%