### Author Topic: Setting points in sf::VertexArray relative to sprite  (Read 1240 times)

0 Members and 1 Guest are viewing this topic.

#### Clockwork

• Newbie
• Posts: 47
##### Setting points in sf::VertexArray relative to sprite
« 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:

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!

#### Hapax

• Hero Member
• Posts: 3020
• My number of posts is shown in hexadecimal.
##### Re: Setting points in sf::VertexArray relative to sprite
« Reply #1 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), you can just apply all of the same transformations to the vertex array that you apply to the sprite.
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

#### Laurent

• Hero Member
• Posts: 32453
##### Re: Setting points in sf::VertexArray relative to sprite
« Reply #2 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();
Laurent Gomila - SFML developer

#### Hapax

• Hero Member
• Posts: 3020
• My number of posts is shown in hexadecimal.
##### Re: Setting points in sf::VertexArray relative to sprite
« Reply #3 on: July 27, 2014, 01:53:03 pm »
Or that. You could just do that.
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

#### Clockwork

• Newbie
• Posts: 47
##### Re: Setting points in sf::VertexArray relative to sprite
« Reply #4 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

#### Laurent

• Hero Member
• Posts: 32453
##### Re: Setting points in sf::VertexArray relative to sprite
« Reply #5 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 )
Laurent Gomila - SFML developer

#### Clockwork

• Newbie
• Posts: 47
##### Re: Setting points in sf::VertexArray relative to sprite
« Reply #6 on: July 28, 2014, 07:19:58 pm »
Woops, I never think about the documentation for some reased!

Anyway, thank you!