Polygon shape configuration. More...
#include <PolygonShapeConf.hpp>
Public Member Functions | |
PolygonShapeConf (Length hx, Length hy, const PolygonShapeConf &conf=GetDefaultConf()) noexcept | |
Initializing constructor for a 4-sided box polygon. More... | |
PolygonShapeConf (Span< const Length2 > points, const PolygonShapeConf &conf=GetDefaultConf()) noexcept | |
Creates a convex hull from the given array of local points. More... | |
PolygonShapeConf & | UseVertexRadius (NonNegative< Length > value) noexcept |
Uses the given vertex radius. | |
PolygonShapeConf & | UseVertices (const std::vector< Length2 > &verts) noexcept |
Uses the given vertices. | |
PolygonShapeConf & | SetAsBox (Length hx, Length hy) noexcept |
Sets the vertices to represent an axis-aligned box centered on the local origin. More... | |
PolygonShapeConf & | SetAsBox (Length hx, Length hy, Length2 center, Angle angle) noexcept |
Sets the vertices for the described box. | |
PolygonShapeConf & | Set (Span< const Length2 > verts) noexcept |
Sets the vertices to a convex hull of the given ones. More... | |
PolygonShapeConf & | Set (const VertexSet &points) noexcept |
Sets the vertices to a convex hull of the given ones. More... | |
PolygonShapeConf & | Transform (Transformation xfm) noexcept |
Transforms the vertices by the given transformation. | |
PolygonShapeConf & | Transform (const Mat22 &m) noexcept |
Transforms the vertices by the given transformation matrix. More... | |
VertexCounter | GetVertexCount () const noexcept |
Gets the vertex count. More... | |
Length2 | GetVertex (VertexCounter index) const |
Gets a vertex by index. More... | |
UnitVec | GetNormal (VertexCounter index) const |
Gets a normal by index. More... | |
Span< const Length2 > | GetVertices () const noexcept |
Gets the span of vertices. More... | |
Span< const UnitVec > | GetNormals () const noexcept |
Gets the span of normals. | |
Length2 | GetCentroid () const noexcept |
Gets the centroid. | |
Public Member Functions inherited from playrho::d2::ShapeBuilder< PolygonShapeConf > | |
constexpr | ShapeBuilder ()=default |
Default constructor. | |
constexpr | ShapeBuilder (const BaseShapeConf &value) noexcept |
Initializing constructor. | |
constexpr PolygonShapeConf & | UseFriction (NonNegative< Real > value) noexcept |
Uses the given friction. | |
constexpr PolygonShapeConf & | UseRestitution (Finite< Real > value) noexcept |
Uses the given restitution. | |
constexpr PolygonShapeConf & | UseDensity (NonNegative< AreaDensity > value) noexcept |
Uses the given density. | |
Static Public Member Functions | |
static constexpr NonNegative< Length > | GetDefaultVertexRadius () noexcept |
Gets the default vertex radius for the PolygonShapeConf . | |
static PolygonShapeConf | GetDefaultConf () noexcept |
Gets the default configuration for a PolygonShapeConf . | |
Public Attributes | |
NonNegative< Length > | vertexRadius = GetDefaultVertexRadius() |
Vertex radius. More... | |
Public Attributes inherited from playrho::d2::BaseShapeConf | |
NonNegative< Real > | friction = NonNegative<Real>{Real{2} / Real{10}} |
Friction coefficient. More... | |
Finite< Real > | restitution = Finite<Real>{0} |
Restitution (elasticity) of the associated shape. More... | |
NonNegative< AreaDensity > | density = NonNegative<AreaDensity>{0_kgpm2} |
Area density of the associated shape. More... | |
Private Attributes | |
std::vector< Length2 > | m_vertices |
Array of vertices. More... | |
std::vector< UnitVec > | m_normals |
Normals of edges. More... | |
Length2 | m_centroid = GetInvalid<Length2>() |
Centroid of this shape. | |
Friends | |
bool | operator== (const PolygonShapeConf &lhs, const PolygonShapeConf &rhs) noexcept |
Equality operator. | |
bool | operator!= (const PolygonShapeConf &lhs, const PolygonShapeConf &rhs) noexcept |
Inequality operator. | |
Related Functions | |
(Note that these are not member functions.) | |
Length2 | GetEdge (const PolygonShapeConf &shape, VertexCounter index) |
Gets the identified edge of the given polygon shape. More... | |
Polygon shape configuration.
A convex polygon. The interior of the polygon is to the left of each edge. Polygons maximum number of vertices is defined by MaxShapeVertices
. In most cases you should not need many vertices for a convex polygon.
|
noexcept |
Initializing constructor for a 4-sided box polygon.
hx | Half of the width. |
hy | Half of the height. |
conf | Additional configuration information. |
|
explicitnoexcept |
Creates a convex hull from the given array of local points.
MaxShapeVertices
].
|
inline |
Gets a normal by index.
These are 90-degree clockwise-rotated (outward-facing) unit-vectors of the edges defined by consecutive pairs of vertices starting with vertex 0.
index | Index of the normal to get. |
|
inline |
|
inlinenoexcept |
Gets the vertex count.
MaxShapeVertices
inclusive. Referenced by playrho::d2::GetChild(), playrho::d2::GetEdge(), GetNormal(), and GetVertex().
|
noexcept |
Sets the vertices to a convex hull of the given ones.
MaxShapeVertices
].
|
noexcept |
Sets the vertices to a convex hull of the given ones.
MaxShapeVertices
].
|
noexcept |
Sets the vertices to represent an axis-aligned box centered on the local origin.
hx | the half-width. |
hy | the half-height. |
|
noexcept |
Transforms the vertices by the given transformation matrix.
|
related |
Gets the identified edge of the given polygon shape.
|
private |
Normals of edges.
These are 90-degree clockwise-rotated unit-vectors of the vectors defined by consecutive pairs of elements of vertices.
Referenced by GetNormal(), and GetNormals().
|
private |
Array of vertices.
Consecutive vertices constitute "edges" of the polygon.
Referenced by GetNormals(), GetVertex(), GetVertexCount(), and GetVertices().
NonNegative<Length> playrho::d2::PolygonShapeConf::vertexRadius = GetDefaultVertexRadius() |
Vertex radius.
This is the radius from the vertex that the shape's "skin" should extend outward by. While any edges — line segments between multiple vertices — are straight, corners between them (the vertices) are rounded and treated as rounded. Shapes with larger vertex radiuses compared to edge lengths therefore will be more prone to rolling or having other shapes more prone to roll off of them.
Referenced by playrho::d2::GetChild().