The order in which you define the points is very important. To construct a convex shape, you must first set the number of points it should have and then define the points.ĬtPoint(1, sf::Vector2f(150, 10)) ĬtPoint(2, sf::Vector2f(120, 90)) ĬtPoint(3, sf::Vector2f(30, 100)) If you need to draw a concave shape, you'll have to split it into multiple convex polygons. The sf::ConvexShape class is the ultimate shape class: It allows you to define any convex shape. A sf::CircleShape with 3 points is a triangle, with 4 points it's a square, etc. Since circles are approximated by polygons with many sides, you just have to play with the number of sides to get the desired polygons. There's no dedicated class for regular polygons, in fact you can represent a regular polygon with any number of sides using the sf::CircleShape class: change the number of sides (points) to 100 If you draw bigĬircles, or zoom on regular circles, you'll most likely need more sides. If you draw small circles, you'll probably only need a few sides. The number of sides is an optionalĪttribute, it allows you to adjust the "quality" of the circle: Circles have to be approximated by polygons with many sides (the graphics card is unable to draw a perfectĬircle directly), and this attribute defines how many sides your circle approximation will have. It has two attributes: The radius and the number of sides. tSize(sf::Vector2f(100, 100)) Ĭircles are represented by the sf::CircleShape class. Sf::RectangleShape rectangle(sf::Vector2f(120, 50)) It has a single attribute: The size of the rectangle. To draw rectangles, you can use the sf::RectangleShape class. To disable texturing, call setTexture(NULL).ĭrawing a shape is as simple as drawing any other SFML entity: If its fill color is sf::Color::White, the texture will appear unmodified. It is important to know that the texture is modulated (multiplied) with the shape's fill color. tTexture(&texture) // texture is a sf::Texture map a 100x100 textured rectangle to the shape Individually setting the texture coordinates of each point of the shape. This method doesn't offer maximum flexibility, but it is much easier to use than It takes the texture rectangle to map to the bounding rectangle of the shape. To specify a part of the texture to be mapped to the shape, you must use the setTextureRect function. Shapes can also be textured, just like sprites. If you only want the outline, you can set the fill color to sf::Color::Transparent. To disable the outline, set its thickness to 0. You can make it extrude towards the center of the shape instead, by setting a negative thickness. if you have a circle with a radius of 10 and an outline thickness of 5, the total radius of the circle will be 15). tOutlineColor(sf::Color(250, 150, 100)) īy default, the outline is extruded outwards from the shape (e.g. You can set the thickness and color of the outline with the setOutlineThickness and setOutlineColor functions. You can change with the setFillColor function. One of the basic properties of a shape is its color. These properties are common to all the SFML graphical classes, so they are explained in a separate tutorial: Each class then adds its own specifics: a radius property for the circle class, a size for the rectangle class,Ĭommon shape properties Transformation (position, rotation, scale) They have access to the same subset of common features. Each type of shape is a separate class, but they all derive from the same base class so that SFML provides a set of classes that represent simple shape entities. Click here to switch to the latest version. Warning: this page refers to an old version of SFML. For the image on the right, angle a is obviously 0 deg, but what about arbitrary intermediate rectangles?Īnd how does this generalize to 6, 8, 10. If w and h are given, how do I solve for a ? I am afraid my trigonometry is insufficient for this.įor the image on the left, angle a is obviously 60 deg. With width w, height h, radius r and angle a: I can see some relations, but do not know how to go further from that: How do I go about calculating the radius of the circles for given width and height of the rectangle? Or how do I calculate the angle between 2 circles and the horizontal? If I have the radius, I can calculate the angle, and vice versa. The one in the middle is an arbitrary example of an intermediate rectangle. So the 'most square' rectangle is shown on the left, and the most wide rectangle is shown on the right. The aspect ratio of the rectangle is such that 4 circles fit in the latticed way shown in the image. For a given a rectangle with known width and height, I want to fit 4 circles of equal size regularly (see image) in such a way that the radius of the circles is maximized.
0 Comments
Leave a Reply. |