Visibility polygon help needed - Graphics and GPU Programming - GameDev.net

Visibility polygon help needed

Started by
10 comments, last by nortski 8 minutes ago

@JoeJ 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;
Advertisement