[英]How do I draw an advanced shape with SFML in C++?
这是我为你做的东西。 这可能听起来很傻,但它的作用是,您可以绘制形状轮廓,然后单击鼠标右键将矩形位置 (X,Y) 转换为凸形将采用的点并将其自身创建为一个漂亮的形状。
//This is not necessary, but it helps if you going to move the camera.
Vector2i pixelPos = Mouse::getPosition(*Twin);
Vector2f worldPos = Twin->mapPixelToCoords(pixelPos);
// declare the variables
RectangleShape* brush;
vector<RectangleShape> brushV;
ConvexShape yourShape;
vector<Vector2f> pos;
brush = new RectangleShape;
// the brush, which creates rectangles
if (Mouse::isButtonPressed(Mouse::Left))
{
brushV.push_back(*brush);
brushV[brushV.size() - 1].setSize(Vector2f(10, 10));
brushV[brushV.size() - 1].setPosition(Vector2f(worldPos));
pos.push_back(worldPos);
}
// creates the whole shape which you drew
if (Mouse::isButtonPressed(Mouse::Right))
{
yourShape.setPointCount(pos.size());
for (int i = 0; i < pos.size(); i++)
{
yourShape.setPoint(i, pos[i]);
}
brushV.clear();
}
// render
for (int i = 0; i < brushV.size(); i++)
{
window->draw(brushV[i]);
}
window->draw(yourShape);
如果边缘看起来很粗糙,您可以尝试使用抗锯齿。
sf::ContextSettings settings;
settings.antialiasingLevel = 8;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.