1
Graphics / Re: How to correctly draw a triangle fan?
« on: May 19, 2024, 12:42:34 pm »If the triangle solution works, you must check your formation of the triangle strip to see if it's correct, including infinitely thin or 'backwards' triangles (breaking the triangle strip shape).
It might be worth making the calculations using doubles - for more accuracy - and then only converting to floats when creating the graphics (triangle strip).
Thank you for taking the time to help me with this.
I actually fixed the problem. As it turned out it was an off by one problem with my loop. A triangle fan needs to be 2 elements larger than the number of vertex points in my vector, 1 for the central position and 1 to close the gap between the last vertex and the first vertex.
// Make polygon 2 larger than vertex container
sf::VertexArray visibilityPolygon(sf::TriangleFan, vectorAngleContainer.size() + 2);
visibilityPolygon[0] = ray[0].position;
visibilityPolygon[0].color = sf::Color::Red;
for (int i = 1; i <= vectorAngleContainer.size(); i++)
{
visibilityPolygon[i] = sf::Vertex(sf::Vector2f(vectorAngleContainer[i - 1].position.x, vectorAngleContainer[i - 1].position.y), sf::Color::Red);
}
// Set the last point == to the first vertex [1] (not [0] as that is the central point)
visibilityPolygon[vectorAngleContainer.size() + 1] = visibilityPolygon[1].position;
visibilityPolygon[vectorAngleContainer.size() + 1].color = sf::Color::Red;
sf::VertexArray visibilityPolygon(sf::TriangleFan, vectorAngleContainer.size() + 2);
visibilityPolygon[0] = ray[0].position;
visibilityPolygon[0].color = sf::Color::Red;
for (int i = 1; i <= vectorAngleContainer.size(); i++)
{
visibilityPolygon[i] = sf::Vertex(sf::Vector2f(vectorAngleContainer[i - 1].position.x, vectorAngleContainer[i - 1].position.y), sf::Color::Red);
}
// Set the last point == to the first vertex [1] (not [0] as that is the central point)
visibilityPolygon[vectorAngleContainer.size() + 1] = visibilityPolygon[1].position;
visibilityPolygon[vectorAngleContainer.size() + 1].color = sf::Color::Red;