Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: removing sf::VertexArray from the middle  (Read 2990 times)

0 Members and 1 Guest are viewing this topic.

Flaze07

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
removing sf::VertexArray from the middle
« on: July 30, 2017, 02:04:53 pm »
is it possible ??

Flaze07

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: removing sf::VertexArray from the middle
« Reply #1 on: July 30, 2017, 02:09:30 pm »
like sf::VertexArray::Erase(2);

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: removing sf::VertexArray from the middle
« Reply #2 on: July 30, 2017, 02:20:30 pm »
No.

However, there are solutions:
1)
copy all the vertices to the right (assuming the left is the beginning and the right is the end) of the one you want to remove to the one to its left and then resize so that it is one smaller.
2)
use a vector of vertices instead of an sf::VertexArray. Remember that you may also need to store the primitive type. You can then, of course, use a vector's erase method to remove an element.
e.g. (assumes a drawable class set-up)
// storage
sf::PrimitiveType m_primitiveType;
std::vector<sf::Vertex> m_vertices;

// in draw method
target.draw(m_vertices.data(), m_vertices.size(), m_primitiveType, renderStates);

// erase
m_vertices.erase(m_vertices.begin() + 2);

EDIT: corrected mistake (wrote sf::VectorArray instead of sf::VertexArray)
« Last Edit: July 30, 2017, 03:54:59 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Flaze07

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: removing sf::VertexArray from the middle
« Reply #3 on: July 30, 2017, 02:27:38 pm »
ah, thank you,I will take the first option...that being said...why don't sf::VertexArray has erase option ?

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: removing sf::VertexArray from the middle
« Reply #4 on: July 30, 2017, 04:01:11 pm »
I honestly don't think it needs one. It's a simple container to simplify storing vertices along with its primitive type. However, if you need anything other than that - or, indeed, even if you don't - you can just use a vector of vertices, which I would personally recommend anyway. The draw command may look more confusing at first but it's really not once you've used it a couple of times.

If you think about it, it's called vertex array and you wouldn't expect to be able to remove elements from an array. The fact that you can resize it is a bonus. Also, just so you know, sf::VertexArray actually stores the vertices in a vector (as I mentioned above) so there's no reason you can't just do that yourself. ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Flaze07

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: removing sf::VertexArray from the middle
« Reply #5 on: July 30, 2017, 04:16:24 pm »
yeah...I looked at the implementation it is simple indeed :D
but I think I can just copy the entire code and just add a simple remove function :D

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: removing sf::VertexArray from the middle
« Reply #6 on: July 30, 2017, 06:19:57 pm »
You could fork SFML and modify it to include that functionality for yourself.

However, what's wrong with just using std::vector<sf::Vertex>? :P
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything