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

Author Topic: Stroke a Vertex Array  (Read 2544 times)

0 Members and 1 Guest are viewing this topic.

NeomerArcana

  • Newbie
  • *
  • Posts: 12
    • View Profile
Stroke a Vertex Array
« on: September 13, 2013, 09:11:20 am »
Hi All,

I've been scratching my head on this one for a little and I'm really just after some guidance.

I've searched google and the forums and can't find an answer, or at least one I understand. I'm trying to stroke an array of vertices. Basically, exactly like how you stroke a path in Photoshop with a Brush.

I understand that SFML can't do this out of the box.

My use case is I have a berzier curve function which I use to calculate the coords of say 10 points along the curve. I'm then adding these points to a Vertex Array as a Line Array. I'd now like to drawn a nice thick 6 pixel line (brush) along this path.

I've sort of come to the conclusion that I'd need to do this using a Polygon. So I thought if I calculate the direction vector at each point, I could then calculate the point that's at a right angle direction to either side of my original point at a distance of half the stroke width. Then I would be able to add each of these points to a Vertex Array working along the two points that are 90 degrees from the first point, 90 degress from the second point and then at the last point I can work my way back down along the 270 degree angle points.

Then I can just fill the resulting polygon that's the width I want, and centered directly on the top of my original Vertex array.

I would like to get some validation on this before I go to all the effort of learning the necessary vector math. Is there a better way to do this? Has someone already gone to the effort to code it up for me?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Stroke a Vertex Array
« Reply #1 on: September 13, 2013, 09:16:28 am »

NeomerArcana

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Stroke a Vertex Array
« Reply #2 on: September 13, 2013, 09:34:18 am »
I think it does.

I'll investigate tonight.

Cheers.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Stroke a Vertex Array
« Reply #3 on: September 13, 2013, 10:35:27 am »
You might also have a look at Zoost & Zoom or Stroke.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

NeomerArcana

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Stroke a Vertex Array
« Reply #4 on: September 14, 2013, 03:27:40 am »
In case anyone searches the forum and finds this topic: the following code sorted me out:
https://github.com/SFML/SFML/wiki/Source%3A-line-with-thickness
Though I had to make a few minor edits.

 

anything