El Octavio  1.0
This is a video game about adventures.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sf::ConvexShape Class Reference

Specialized shape representing a convex polygon. More...

#include <ConvexShape.hpp>

+ Inheritance diagram for sf::ConvexShape:
+ Collaboration diagram for sf::ConvexShape:

Public Member Functions

 ConvexShape (std::size_t pointCount=0)
 Default constructor. More...
 
void setPointCount (std::size_t count)
 Set the number of points of the polygon. More...
 
virtual std::size_t getPointCount () const
 Get the number of points of the polygon. More...
 
void setPoint (std::size_t index, const Vector2f &point)
 Set the position of a point. More...
 
virtual Vector2f getPoint (std::size_t index) const
 Get the position of a point. More...
 
- Public Member Functions inherited from sf::Shape
virtual ~Shape ()
 Virtual destructor. More...
 
void setTexture (const Texture *texture, bool resetRect=false)
 Change the source texture of the shape. More...
 
void setTextureRect (const IntRect &rect)
 Set the sub-rectangle of the texture that the shape will display. More...
 
void setFillColor (const Color &color)
 Set the fill color of the shape. More...
 
void setOutlineColor (const Color &color)
 Set the outline color of the shape. More...
 
void setOutlineThickness (float thickness)
 Set the thickness of the shape's outline. More...
 
const TexturegetTexture () const
 Get the source texture of the shape. More...
 
const IntRectgetTextureRect () const
 Get the sub-rectangle of the texture displayed by the shape. More...
 
const ColorgetFillColor () const
 Get the fill color of the shape. More...
 
const ColorgetOutlineColor () const
 Get the outline color of the shape. More...
 
float getOutlineThickness () const
 Get the outline thickness of the shape. More...
 
virtual std::size_t getPointCount () const =0
 Get the total number of points of the shape. More...
 
virtual Vector2f getPoint (std::size_t index) const =0
 Get a point of the shape. More...
 
FloatRect getLocalBounds () const
 Get the local bounding rectangle of the entity. More...
 
FloatRect getGlobalBounds () const
 Get the global (non-minimal) bounding rectangle of the entity. More...
 
- Public Member Functions inherited from sf::Drawable
virtual ~Drawable ()
 Virtual destructor. More...
 
- Public Member Functions inherited from sf::Transformable
 Transformable ()
 Default constructor. More...
 
virtual ~Transformable ()
 Virtual destructor. More...
 
void setPosition (float x, float y)
 set the position of the object More...
 
void setPosition (const Vector2f &position)
 set the position of the object More...
 
void setRotation (float angle)
 set the orientation of the object More...
 
void setScale (float factorX, float factorY)
 set the scale factors of the object More...
 
void setScale (const Vector2f &factors)
 set the scale factors of the object More...
 
void setOrigin (float x, float y)
 set the local origin of the object More...
 
void setOrigin (const Vector2f &origin)
 set the local origin of the object More...
 
const Vector2fgetPosition () const
 get the position of the object More...
 
float getRotation () const
 get the orientation of the object More...
 
const Vector2fgetScale () const
 get the current scale of the object More...
 
const Vector2fgetOrigin () const
 get the local origin of the object More...
 
void move (float offsetX, float offsetY)
 Move the object by a given offset. More...
 
void move (const Vector2f &offset)
 Move the object by a given offset. More...
 
void rotate (float angle)
 Rotate the object. More...
 
void scale (float factorX, float factorY)
 Scale the object. More...
 
void scale (const Vector2f &factor)
 Scale the object. More...
 
const TransformgetTransform () const
 get the combined transform of the object More...
 
const TransformgetInverseTransform () const
 get the inverse of the combined transform of the object More...
 

Additional Inherited Members

- Protected Member Functions inherited from sf::Shape
 Shape ()
 Default constructor. More...
 
void update ()
 Recompute the internal geometry of the shape. More...
 
virtual void draw (RenderTarget &target, RenderStates states) const =0
 Draw the object to a render target. More...
 

Detailed Description

Specialized shape representing a convex polygon.

This class inherits all the functions of sf::Transformable (position, rotation, scale, bounds, ...) as well as the functions of sf::Shape (outline, color, texture, ...).

It is important to keep in mind that a convex shape must always be... convex, otherwise it may not be drawn correctly. Moreover, the points must be defined in order; using a random order would result in an incorrect shape.

Usage example:

polygon.setPointCount(3);
polygon.setPoint(0, sf::Vector2f(0, 0));
polygon.setPoint(1, sf::Vector2f(0, 10));
polygon.setPoint(2, sf::Vector2f(25, 5));
polygon.setPosition(10, 20);
...
window.draw(polygon);
static const Color Red
Red predefined color.
Definition: Color.hpp:85
Specialized shape representing a convex polygon.
Definition: ConvexShape.hpp:43
void setPointCount(std::size_t count)
Set the number of points of the polygon.
void setPoint(std::size_t index, const Vector2f &point)
Set the position of a point.
void setOutlineColor(const Color &color)
Set the outline color of the shape.
void setOutlineThickness(float thickness)
Set the thickness of the shape's outline.
void setPosition(float x, float y)
set the position of the object
See also
sf::Shape, sf::RectangleShape, sf::CircleShape

Definition at line 42 of file ConvexShape.hpp.

Constructor & Destructor Documentation

◆ ConvexShape()

sf::ConvexShape::ConvexShape ( std::size_t  pointCount = 0)
explicit

Default constructor.

Parameters
pointCountNumber of points of the polygon

Member Function Documentation

◆ getPoint()

virtual Vector2f sf::ConvexShape::getPoint ( std::size_t  index) const
virtual

Get the position of a point.

The returned point is in local coordinates, that is, the shape's transforms (position, rotation, scale) are not taken into account. The result is undefined if index is out of the valid range.

Parameters
indexIndex of the point to get, in range [0 .. getPointCount() - 1]
Returns
Position of the index-th point of the polygon
See also
setPoint

Implements sf::Shape.

◆ getPointCount()

virtual std::size_t sf::ConvexShape::getPointCount ( ) const
virtual

Get the number of points of the polygon.

Returns
Number of points of the polygon
See also
setPointCount

Implements sf::Shape.

◆ setPoint()

void sf::ConvexShape::setPoint ( std::size_t  index,
const Vector2f point 
)

Set the position of a point.

Don't forget that the polygon must remain convex, and the points need to stay ordered! setPointCount must be called first in order to set the total number of points. The result is undefined if index is out of the valid range.

Parameters
indexIndex of the point to change, in range [0 .. getPointCount() - 1]
pointNew position of the point
See also
getPoint

◆ setPointCount()

void sf::ConvexShape::setPointCount ( std::size_t  count)

Set the number of points of the polygon.

count must be greater than 2 to define a valid shape.

Parameters
countNew number of points of the polygon
See also
getPointCount

The documentation for this class was generated from the following file: