SFML community forums

Help => Graphics => Topic started by: Flaze07 on May 01, 2018, 11:45:49 am

Title: transforming on each vertex array
Post by: Flaze07 on May 01, 2018, 11:45:49 am
for example :
std::vector< sf::RectangleShape > rect;
//stuffs

int i = 0;
for ( auto& a : rect )
{
        ++i;
        rect.setRotation( 90 + i );
}
 

each of the rect will have different rotations.
I know how to apply transform to vertex array, but if I want the vertex array to have different roations, how do I do that ?

sf::VertexArray vert{ sf::Quads, 8 };
//stufs
sf::Transform t;
t.setRotation( 90 );
win.draw( vert, t ) // unable to set rotation for each 4 vertices
 
Title: Re: transforming on each vertex array
Post by: Hapax on May 01, 2018, 02:48:37 pm
The setRotation method is a part of an object transform and is generally applied when drawing to all vertices.
However, you can apply custom transforms (or just calculate manually, for example your rotations) to each vertex manually. Of course, you may no longer need the object transform.

One way to rotate a vertex is by using a transform (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Transform.php). Start with the indentity transform and apply the transformations you wish to apply and then you can use the transformPoint (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Transform.php#ac322cd8f6d606598d1aacc4d1d160ad6) method.

To rotate a point around another point manually, you will need trigonometric functions. You can google this; it's not too complicated. :)
Title: Re: transforming on each vertex array
Post by: Flaze07 on May 10, 2018, 02:12:12 pm
after thinking for several hours, I finally got what you mean, thank you