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

Author Topic: How to calculate a polygon from a vector of vertices i.e draw thick lines?  (Read 1452 times)

0 Members and 1 Guest are viewing this topic.

darkbeanies

  • Newbie
  • *
  • Posts: 2
    • View Profile
Yes, I used the lovely search function and google first.   :)

So, I would like to draw a line from a vector of vertices.  Let's say they're roads, and the vector goes from road.begin to road.end and doesn't visit any coordinate more than once and does not collide with itself.

So, most of the roads I've been on have greater than zero thickness, so I'd like to give it a width.  I saw somewhere in the manual that if my lines have thickness, they "Must Be" rectangles.  Hmmmm.  Fair enough, if by "line" you mean "an edge connecting two points".  But when I talk of lines, they have hundreds of points.  And obviously, if I was to create a series of rectangles from point to point, this would not in fact work correctly because there would be little gaps and overlaps caused by the rotation of the rectangles.

So, can anyone point me to a "polygonize line" algorithm, or post a decent bit of working code that allows me to convert a list of x,y vertices into a nice sfml shape class of some sort with a proper width that is constant along the entire line? 

Thanks!

« Last Edit: January 12, 2014, 05:50:56 pm by darkbeanies »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
This thread might be interesting for you. Spline interpolation or bezier curves are probably the keywords you're looking for.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

darkbeanies

  • Newbie
  • *
  • Posts: 2
    • View Profile
Thanks a lot, I shall take a look.  Also, I just found "Minkowski sum", which I think looks quite good too.  My program seems to contain 90% theories and algorithms by Minkowski...

Erm..I took a look at the example:

https://github.com/SFML/SFML/wiki/Source%3A-line-with-thickness

"The code above uses the following extensions to Vector2f"

Okay, how do I add extensions to Vector2f?  ( I have no clue what I'm doing really!)

And, since when does std::vector have a member "Append" (notice the capital "A")

And, what the hell sort of keyword is "var"?




THIS LINK solved all my problems instantly.  Put it in the manual or something!!!

https://gist.github.com/eXpl0it3r/6057215
« Last Edit: January 12, 2014, 06:49:27 pm by darkbeanies »