SFML community forums

Help => Graphics => Topic started by: William_Hazem on May 27, 2021, 10:29:59 pm

Title: SFML custom shape, problem with fill vertex
Post by: William_Hazem on May 27, 2021, 10:29:59 pm
I'm Trynig to make a Arrow Class that extends the sf::Shape, but when i draw the shape this happen:

(https://i.imgur.com/jVUlwW6.png)

Outline are correct, but when i set the fill color, it's fill outside the area.


unsigned int Arrow::getPointCount() const {
    return 5;
}

sf::Vector2f Arrow::getPoint(unsigned int index) const {
    float x = origin.x;
    float y = origin.y;

    if(index == 0)
        return {x, y - tickness/2};
    else if(index == 1)
        return {x + length, y - tickness/2};
    else if(index == 2)
        return {x + length, y - tickness/2 - 30.f};
    else if(index == 3)
        return {x + length + 30.f, y};
    return {x , y};
   
   
}
 
Title: Re: SFML custom shape, problem with fill vertex
Post by: eXpl0it3r on June 01, 2021, 08:35:32 am
Shape can only handle Convex shapes, an arrow is concave, thus you get a wrong shape.

You can either manually do it with a vertex array, or you can use Thor's Concave Shape (https://bromeon.ch/libraries/thor/documentation/v2.1/classthor_1_1_concave_shape.html)
Title: Re: SFML custom shape, problem with fill vertex
Post by: William_Hazem on June 19, 2021, 12:38:39 am
Thanks!