SFML community forums

Help => Graphics => Topic started by: SeBy24 on January 04, 2014, 02:07:10 pm

Title: Drawing convex shapes using a vector of Vector2f's
Post by: SeBy24 on January 04, 2014, 02:07:10 pm
So i'm working on my game engine using SFML and i'd like to be able to draw a convex shape just by knowing it's points, so my object class would not need to have both a ConvexShape and a vector of points..
Is there any way i could do that with minimum effort ?

Thanks :D
Title: Re: Drawing convex shapes using a vector of Vector2f's
Post by: eXpl0it3r on January 04, 2014, 02:24:42 pm
You could use a vertex array directly, but you'd loose the nice interface for transformations.
Title: Re: Drawing convex shapes using a vector of Vector2f's
Post by: Nexus on January 04, 2014, 02:25:42 pm
Have a look at the documentation. sf::ConvexShape provides methods to set its points.

If your question aims at not duplicating information: Either create the shape on-the-fly, or keep only the shape (and not a separate point vector).
Title: Re: Drawing convex shapes using a vector of Vector2f's
Post by: SeBy24 on January 04, 2014, 02:35:41 pm
Using a vertex could work , but losing the transformations .. i don't think so :)

The fact that i have to keep my points in a ConvexShape instead of an vector really annoys me because i have to keep track of it's point count .. Since i can't find a better alternative , i decided i'll only keep the shape. Thanks a lot :3
Title: Re: Drawing convex shapes using a vector of Vector2f's
Post by: Nexus on January 04, 2014, 02:37:17 pm
because i have to keep track of it's point count ..
What do you mean, or why is that a problem?
Title: Re: Drawing convex shapes using a vector of Vector2f's
Post by: SeBy24 on January 04, 2014, 02:42:29 pm
I mean , adding a point to a vector of vertices would be as simple as
vertices.push_back(point);
while adding a point to a ConvexShape means i have to raise the point count and then add the point (i believe that's how it works).
Title: Re: Drawing convex shapes using a vector of Vector2f's
Post by: Nexus on January 04, 2014, 03:31:04 pm
Is that the problem? Just write a function that does it for you:
void addPoint(sf::ConvexShape& shape, sf::Vector2f point)
{
        std::size_t size = shape.getPointCount();
        shape.setPointCount(size + 1);
        shape.setPoint(size, point);
}