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

Author Topic: Drawing convex shapes using a vector of Vector2f's  (Read 1858 times)

0 Members and 1 Guest are viewing this topic.

SeBy24

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Drawing convex shapes using a vector of Vector2f's
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Drawing convex shapes using a vector of Vector2f's
« Reply #1 on: January 04, 2014, 02:24:42 pm »
You could use a vertex array directly, but you'd loose the nice interface for transformations.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Drawing convex shapes using a vector of Vector2f's
« Reply #2 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).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

SeBy24

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Drawing convex shapes using a vector of Vector2f's
« Reply #3 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Drawing convex shapes using a vector of Vector2f's
« Reply #4 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?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

SeBy24

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Drawing convex shapes using a vector of Vector2f's
« Reply #5 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).

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Drawing convex shapes using a vector of Vector2f's
« Reply #6 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);
}
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: