Hi,
I am curious if I am missing something obvious.
Sf::Shape when constructed has the default "point" added to it at 0,0.
I'm reading a bunch of points out of a file, and constructing the corresponding shape based on the number of points read from the file.
When I read 4 points (which should be a rect), then go to render it, there are 5 points total.
Here's the code:
void SafeSetProperties(std::map<std::string, boost::variant<int, float, std::string, sf::Vector2f> > properties)
{
// constant string values for the function
static const std::string verticeCount = "VerticeCount";
static const std::string vertices = "Vertices";
// read in all of the vertices
if(properties.count(verticeCount) > 0)
{
const int numVertices = boost::get<int>(properties[verticeCount]);
for(auto i = 0; i < numVertices; ++i) {
std::ostringstream oss;
oss << vertices << i;
_polygonShape.AddPoint(boost::get<sf::Vector2f>(properties[oss.str()]));
}
}
Here's the resulting image (ignore the red triangle, different shape):
I'm aware of the static function sf::Shape::Rectangle, but this means I need to add a switch based on the number of points (that would make the code less maintainable, more complex, however you want to say it).
My question, why is the default placeholder point of (0,0) added to all shape's? Is there a reason why there is no way to override this behavior?
I could dive into the source code, remove the point being added in the constructor, but is that the only way?
I would like not to have to modify my sfml code (if I ever distribute, I wouldn't want a custom version of SFML).
Opening Shape.cpp we can see where this happens
////////////////////////////////////////////////////////////
Shape::Shape() :
myOutline (0.f),
myIsFillEnabled (true),
myIsOutlineEnabled(true),
myIsCompiled (false)
{
// Put a placeholder for the center of the shape
myPoints.push_back(Point());
}