SFML community forums

Help => Graphics => Topic started by: darkbeanies on January 12, 2014, 05:49:11 pm

Title: How to calculate a polygon from a vector of vertices i.e draw thick lines?
Post by: darkbeanies on January 12, 2014, 05:49:11 pm
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!

Title: Re: How to calculate a polygon from a vector of vertices i.e draw thick lines?
Post by: Nexus on January 12, 2014, 06:01:37 pm
This thread (http://en.sfml-dev.org/forums/index.php?topic=12944) might be interesting for you. Spline interpolation or bezier curves are probably the keywords you're looking for.
Title: Re: How to calculate a polygon from a vector of vertices i.e draw thick lines?
Post by: darkbeanies on January 12, 2014, 06:07:44 pm
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