PlayRho  1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
playrho::d2::PolygonShapeConf Class Reference

Polygon shape configuration. More...

#include <PolygonShapeConf.hpp>

Inheritance diagram for playrho::d2::PolygonShapeConf:
[legend]
Collaboration diagram for playrho::d2::PolygonShapeConf:
[legend]

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...
 
PolygonShapeConfUseVertexRadius (NonNegative< Length > value) noexcept
 Uses the given vertex radius.
 
PolygonShapeConfUseVertices (const std::vector< Length2 > &verts) noexcept
 Uses the given vertices.
 
PolygonShapeConfSetAsBox (Length hx, Length hy) noexcept
 Sets the vertices to represent an axis-aligned box centered on the local origin. More...
 
PolygonShapeConfSetAsBox (Length hx, Length hy, Length2 center, Angle angle) noexcept
 Sets the vertices for the described box.
 
PolygonShapeConfSet (Span< const Length2 > verts) noexcept
 Sets the vertices to a convex hull of the given ones. More...
 
PolygonShapeConfSet (const VertexSet &points) noexcept
 Sets the vertices to a convex hull of the given ones. More...
 
PolygonShapeConfTransform (Transformation xfm) noexcept
 Transforms the vertices by the given transformation.
 
PolygonShapeConfTransform (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 Length2GetVertices () const noexcept
 Gets the span of vertices. More...
 
Span< const UnitVecGetNormals () 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 PolygonShapeConfUseFriction (NonNegative< Real > value) noexcept
 Uses the given friction.
 
constexpr PolygonShapeConfUseRestitution (Finite< Real > value) noexcept
 Uses the given restitution.
 
constexpr PolygonShapeConfUseDensity (NonNegative< AreaDensity > value) noexcept
 Uses the given density.
 

Static Public Member Functions

static constexpr NonNegative< LengthGetDefaultVertexRadius () noexcept
 Gets the default vertex radius for the PolygonShapeConf.
 
static PolygonShapeConf GetDefaultConf () noexcept
 Gets the default configuration for a PolygonShapeConf.
 

Public Attributes

NonNegative< LengthvertexRadius = GetDefaultVertexRadius()
 Vertex radius. More...
 
- Public Attributes inherited from playrho::d2::BaseShapeConf
NonNegative< Realfriction = NonNegative<Real>{Real{2} / Real{10}}
 Friction coefficient. More...
 
Finite< Realrestitution = Finite<Real>{0}
 Restitution (elasticity) of the associated shape. More...
 
NonNegative< AreaDensitydensity = NonNegative<AreaDensity>{0_kgpm2}
 Area density of the associated shape. More...
 

Private Attributes

std::vector< Length2m_vertices
 Array of vertices. More...
 
std::vector< UnitVecm_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...
 

Detailed Description

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.

Note
This data structure is 64-bytes large (with 4-byte Real).
Examples
HelloWorld.cpp, RevoluteJoint.cpp, Shape.cpp, World.cpp, and WorldBody.cpp.

Constructor & Destructor Documentation

◆ PolygonShapeConf() [1/2]

playrho::d2::PolygonShapeConf::PolygonShapeConf ( Length  hx,
Length  hy,
const PolygonShapeConf conf = GetDefaultConf() 
)
noexcept

Initializing constructor for a 4-sided box polygon.

Parameters
hxHalf of the width.
hyHalf of the height.
confAdditional configuration information.
See also
SetAsBox.

◆ PolygonShapeConf() [2/2]

playrho::d2::PolygonShapeConf::PolygonShapeConf ( Span< const Length2 points,
const PolygonShapeConf conf = GetDefaultConf() 
)
explicitnoexcept

Creates a convex hull from the given array of local points.

Note
The size of the span must be in the range [1, MaxShapeVertices].
Warning
the points may be re-ordered, even if they form a convex polygon
collinear points are handled but not removed. Collinear points may lead to poor stacking behavior.

Member Function Documentation

◆ GetNormal()

UnitVec playrho::d2::PolygonShapeConf::GetNormal ( VertexCounter  index) const
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.

Parameters
indexIndex of the normal to get.
Returns
Normal for the given index.

◆ GetVertex()

Length2 playrho::d2::PolygonShapeConf::GetVertex ( VertexCounter  index) const
inline

Gets a vertex by index.

Vertices go counter-clockwise.

Referenced by playrho::d2::GetEdge().

◆ GetVertexCount()

VertexCounter playrho::d2::PolygonShapeConf::GetVertexCount ( ) const
inlinenoexcept

Gets the vertex count.

Returns
value between 0 and MaxShapeVertices inclusive.
See also
MaxShapeVertices

Referenced by playrho::d2::GetChild(), playrho::d2::GetEdge(), GetNormal(), and GetVertex().

◆ GetVertices()

Span<const Length2> playrho::d2::PolygonShapeConf::GetVertices ( ) const
inlinenoexcept

Gets the span of vertices.

Vertices go counter-clockwise.

Referenced by playrho::d2::GetChild().

◆ Set() [1/2]

PolygonShapeConf & playrho::d2::PolygonShapeConf::Set ( const VertexSet points)
noexcept

Sets the vertices to a convex hull of the given ones.

Note
The size of the span must be in the range [1, MaxShapeVertices].
Warning
Points may be re-ordered, even if they form a convex polygon
Collinear points are handled but not removed. Collinear points may lead to poor stacking behavior.

◆ Set() [2/2]

PolygonShapeConf & playrho::d2::PolygonShapeConf::Set ( Span< const Length2 verts)
noexcept

Sets the vertices to a convex hull of the given ones.

Note
The size of the span must be in the range [1, MaxShapeVertices].
Warning
Points may be re-ordered, even if they form a convex polygon
Collinear points are handled but not removed. Collinear points may lead to poor stacking behavior.

◆ SetAsBox()

PolygonShapeConf & playrho::d2::PolygonShapeConf::SetAsBox ( Length  hx,
Length  hy 
)
noexcept

Sets the vertices to represent an axis-aligned box centered on the local origin.

Parameters
hxthe half-width.
hythe half-height.
Examples
HelloWorld.cpp, RevoluteJoint.cpp, and World.cpp.

◆ Transform()

PolygonShapeConf & playrho::d2::PolygonShapeConf::Transform ( const Mat22 m)
noexcept

Transforms the vertices by the given transformation matrix.

See also
https://en.wikipedia.org/wiki/Transformation_matrix

Friends And Related Function Documentation

◆ GetEdge()

Length2 GetEdge ( const PolygonShapeConf shape,
VertexCounter  index 
)
related

Gets the identified edge of the given polygon shape.

Note
This must not be called for shapes with less than 2 vertices.
Warning
Behavior is undefined if called for a shape with less than 2 vertices.

Member Data Documentation

◆ m_normals

std::vector<UnitVec> playrho::d2::PolygonShapeConf::m_normals
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().

◆ m_vertices

std::vector<Length2> playrho::d2::PolygonShapeConf::m_vertices
private

Array of vertices.

Consecutive vertices constitute "edges" of the polygon.

Referenced by GetNormals(), GetVertex(), GetVertexCount(), and GetVertices().

◆ vertexRadius

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.

Note
This should be a non-negative value.

Referenced by playrho::d2::GetChild().


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