SFML community forums

Help => Graphics => Topic started by: Clockwork on July 27, 2014, 01:49:52 am

Title: Setting points in sf::VertexArray relative to sprite
Post by: Clockwork on July 27, 2014, 01:49:52 am
Hi again everybody,

After more experimenting with VertexArrays, I want to set each vertex (2 vertices in the array) to one end of a sprite.  This wouldn't be that bad, except that the sprite rotates.  I might not have done too great of a job explaining what I mean, so here's a visual representation:

(http://i.imgur.com/XBwsF6c.png)

How can I set each vertex to stay at that end of the sprite?

Sorry for all the questions about this, I'm still learning more advanced topics of C++ and SFML, but I figured that a good way to learn would be pushing myself with harder projects, so I'm not entirely sure how to solve all the problems I run across.

Thanks for all the help!
Title: Re: Setting points in sf::VertexArray relative to sprite
Post by: Hapax on July 27, 2014, 02:52:44 am
Assuming your Vertex Array is inheriting from sf::Transformable (as shown in this section of the vertex array tutorial (http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php#creating-a-sfml-like-entity)), you can just apply all of the same transformations to the vertex array that you apply to the sprite.
Title: Re: Setting points in sf::VertexArray relative to sprite
Post by: Laurent on July 27, 2014, 09:04:24 am
sf::FloatRect bounds = sprite.getLocalBounds();
vertex[0].position = sf::Vector2f(0, bounds.height / 2) * sprite.getTransform();
vertex[1].position = sf::Vector2f(bounds.width, bounds.height / 2) * sprite.getTransform();
Title: Re: Setting points in sf::VertexArray relative to sprite
Post by: Hapax on July 27, 2014, 01:53:03 pm
Or that. You could just do that.  :P
Title: Re: Setting points in sf::VertexArray relative to sprite
Post by: Clockwork on July 28, 2014, 01:54:41 am
Thanks!

I just tried that but I get errors. 

IntelliSense: no operator "*" matches these operands operand types are: sf::Vector2f * const sf::Transform   
Title: Re: Setting points in sf::VertexArray relative to sprite
Post by: Laurent on July 28, 2014, 07:46:28 am
Yes, sorry, it's Transform * Vector2f. You must switch the order of arguments. (you could also go read the documentation ;))
Title: Re: Setting points in sf::VertexArray relative to sprite
Post by: Clockwork on July 28, 2014, 07:19:58 pm
Woops, I never think about the documentation for some reased!

Anyway, thank you!