SFML community forums

Help => Graphics => Topic started by: Mangocheese on March 25, 2010, 01:56:49 pm

Title: Deleting points in a shape
Post by: Mangocheese on March 25, 2010, 01:56:49 pm
Hello again,

I searched high and low for a function or a way to delete the points within a shape, and I haven't been able to find anything!

How do I delete points from a shape?

Thanks
Title: Deleting points in a shape
Post by: nulloid on March 25, 2010, 03:29:00 pm
Well, if it isn't added (yet), then either you write it for yourself in the sfml code, or you inherit a class from sf::Shape and add to it. Or, alternatively, you can create another sf::Shape, add points from the existing shape, but skip those points you want to "delete".

But a function like this would be useful, indeed :)
Title: Deleting points in a shape
Post by: model76 on March 25, 2010, 04:15:10 pm
Here is how I do it in my application: Keep a pure logical shape, and draw a new sf::shape based on that, whenever it changes.

A logical shape is an instance of a class that has an std::vector of sf::vector2f to keep track of the vertices, and methods to add and delete vertices.
Title: Deleting points in a shape
Post by: Mangocheese on March 25, 2010, 04:48:32 pm
Thanks for the prompt replies!

My application only needs to display the shape so I know where my logical shape is. So I just added this to the SFML Shape source code:

Code: [Select]

void Shape::ClearShape()
{
myPoints.clear();
    // Put a placeholder for the center of the shape
    myPoints.push_back(Point())
}


Pretty easy. Although, I am not too sure how much it "breaks" the shape, but it doesn't matter for me since I just use the logical shape anyway.