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

Author Topic: Figuring out how to implement a Triangle as a starting and end point? [SOLVED]  (Read 2375 times)

0 Members and 1 Guest are viewing this topic.

SFMLNewGuy

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Hello, so I am watching a great video on "Line Of Sight". Everything has gone great, until he used his "FillTriangle" function to create the sight. Here is the part I need to figure out how to do in SFML properly.

FillTriangle(
                                fSourceX,
                                fSourceY,

                                get<1>(vecVisibilityPolygonPoints[vecVisibilityPolygonPoints.size() - 1]),
                                get<2>(vecVisibilityPolygonPoints[vecVisibilityPolygonPoints.size() - 1]),

                                get<1>(vecVisibilityPolygonPoints[0]),
                                get<2>(vecVisibilityPolygonPoints[0]));

The vector is a tuple of floats.  (angle, x, y)

As far as I know, SFML doesn't work like this. Typically when I come across stuff like this, I'll manually set the size and position and call a draw on it. But this one has me confused.

You can do sf::CircleShape triangle(size,3) I know. How can I still use this formula and get a triangle out there using SFML?

I hope this question makes sense. Any help would be appreciated.

PS: I am using SelbaWards line function, but I'm hoping there is an easier way than trying to make a huge function to do this properly.
« Last Edit: August 29, 2019, 11:16:13 pm by SFMLNewGuy »

SFMLNewGuy

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Thanks anyway, I solved it myself.

For those curious, I looked into sf::ConvexShape.

sf::ConvexShape convex

convex.setPointCount(3);
convex.setPoint(0, {sourceX,sourceY});
convex.setPoint(1, {std::get<1> m_vecVisibilityPolygonPoints[m_vecVisibilityPolygonPoints.size()-1]),
std::get<2>(m_vecVisibilityPolygonPoints[m_vecVisibilityPolygonPoints.size() - 1])});

convex.setPoint(2, {std::get<1>(m_vecVisibilityPolygonPoints[0]),std::get<2> m_vecVisibilityPolygonPoints[0])});

m_window->draw(convex);

 

anything