Gamedev Framework (gf)  0.10.0
A C++14 framework for 2D games
Public Member Functions | List of all members
gf::ConvexShape Class Reference

Specialized shape representing a convex polygon. More...

#include <gf/Shapes.h>

Inheritance diagram for gf::ConvexShape:
Inheritance graph
[legend]

Public Member Functions

 ConvexShape (std::size_t pointCount)
 Default constructor. More...
 
 ConvexShape (const Polygon &polygon)
 Constructor with a polygon. More...
 
void setPointCount (std::size_t pointCount)
 Set the number of points of the polygon. More...
 
void setPoint (std::size_t index, Vector2f point)
 Get the number of points of the polygon. More...
 
virtual std::size_t getPointCount () const override
 Get the total number of points of the shape. More...
 
virtual Vector2f getPoint (std::size_t index) const override
 Get a point of the shape. More...
 
- Public Member Functions inherited from gf::Shape
 Shape ()
 Default constructor. More...
 
void setTexture (const Texture &texture, bool resetRect=false)
 Change the source texture of the shape. More...
 
const TexturegetTexture () const
 Get the source texture of the shape. More...
 
bool hasTexture () const
 Check if a texture is set. More...
 
void unsetTexture ()
 Unset the source texture of the shape. More...
 
void setTextureRect (const RectF &rect)
 Set the sub-rectangle of the texture that the shape will display. More...
 
const RectFgetTextureRect () const
 Get the sub-rectangle of the texture displayed by the shape. More...
 
void setColor (const Color4f &color)
 Set the fill color of the shape. More...
 
const Color4fgetColor () const
 Get the fill color of the shape. More...
 
void setOutlineColor (const Color4f &color)
 Set the outline color of the shape. More...
 
const Color4fgetOutlineColor () const
 Get the outline color of the shape. More...
 
void setOutlineThickness (float thickness)
 Set the thickness of the shape's outline. More...
 
float getOutlineThickness () const
 Get the outline thickness of the shape. More...
 
RectF getLocalBounds () const
 Get the local bounding rectangle of the entity. More...
 
void setAnchor (Anchor anchor)
 Set the anchor origin of the entity. More...
 
VertexBuffer commitGeometry () const
 Create a buffer with the current geometry. More...
 
VertexBuffer commitOutlineGeometry () const
 Create a buffer with the current outline geometry. More...
 
virtual void draw (RenderTarget &target, const RenderStates &states) override
 Draw the object to a render target. More...
 
- Public Member Functions inherited from gf::Transformable
 Transformable ()
 Default constructor. More...
 
void setOrigin (Vector2f origin)
 Set the local origin of the object. More...
 
Vector2f getOrigin () const
 Get the local origin of the object. More...
 
void setPosition (Vector2f position)
 Set the position of the object. More...
 
Vector2f getPosition () const
 Get the position of the object. More...
 
void move (Vector2f offset)
 Move the object by a given offset. More...
 
void setRotation (float angle)
 Set the orientation of the object. More...
 
float getRotation () const
 Get the orientation of the object. More...
 
void rotate (float angle)
 Rotate the object. More...
 
void setScale (Vector2f factors)
 Set the scale factors of the object. More...
 
void setScale (float factor)
 Set the scale factor of the object. More...
 
Vector2f getScale () const
 Get the current scale of the object. More...
 
void scale (Vector2f factors)
 Scale the object. More...
 
void scale (float factor)
 Scale the object. More...
 
Matrix3f getTransform () const
 Get the combined transform of the object. More...
 
Matrix3f getInverseTransform () const
 Get the inverse of the combined transform of the object. More...
 
- Public Member Functions inherited from gf::Drawable
virtual ~Drawable ()
 Virtual desctructor. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gf::Shape
void updateGeometry ()
 Recompute the internal geometry of the shape. More...
 
- Protected Member Functions inherited from gf::Transformable
void setOriginFromAnchorAndBounds (Anchor anchor, const RectF &bounds)
 Set the origin from an anchor and bounds. More...
 

Detailed Description

Specialized shape representing a convex polygon.

This class inherits all the functions of gf::Transformable (position, rotation, scale, bounds, ...) as well as the functions of gf::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, { 0.0f, 0.0f });
polygon.setPoint(1, { 0.0f, 10.0f });
polygon.setPoint(2, { 25.0f, 5.0f });
polygon.setPosition({ 10.0f, 20.0f });
...
window.draw(polygon);
See also
gf::Shape

Constructor & Destructor Documentation

◆ ConvexShape() [1/2]

gf::ConvexShape::ConvexShape ( std::size_t  pointCount)

Default constructor.

Parameters
pointCountNumber of points of the polygon

◆ ConvexShape() [2/2]

gf::ConvexShape::ConvexShape ( const Polygon polygon)

Constructor with a polygon.

Parameters
polygonThe polygon

Member Function Documentation

◆ getPoint()

virtual Vector2f gf::ConvexShape::getPoint ( std::size_t  index) const
overridevirtual

Get a point of the shape.

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, n-1] \) where \( n \) is the number of points of the shape.
Returns
index-th point of the shape
See also
getPointCount()

Implements gf::Shape.

◆ getPointCount()

virtual std::size_t gf::ConvexShape::getPointCount ( ) const
overridevirtual

Get the total number of points of the shape.

Returns
Number of points of the shape
See also
getPoint()

Implements gf::Shape.

◆ setPoint()

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

Get the number of points of the polygon.

Returns
Number of points of the polygon
See also
setPointCount(), getPoint()

◆ setPointCount()

void gf::ConvexShape::setPointCount ( std::size_t  pointCount)

Set the number of points of the polygon.

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

Parameters
pointCountNew number of points of the polygon
See also
getPointCount()