PlayRho  2.0.0
An interactive physics engine & library.
playrho::d2::PolygonShapeConf Struct Reference

An n-vertex convex polygon shaped part eligible for use with a Shape. More...

#include <playrho/d2/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())
 Initializing constructor for a 4-sided box polygon. More...
 
 PolygonShapeConf (Span< const Length2 > points, const PolygonShapeConf &conf=GetDefaultConf())
 Creates a convex hull from the given array of local points. More...
 
UnitVec GetNormal (VertexCounter index) const
 
Span< const UnitVecGetNormals () const noexcept
 Gets the span of normals.
 
Length2 GetVertex (VertexCounter index) const
 
VertexCounter GetVertexCount () const noexcept
 
Span< const Length2GetVertices () const noexcept
 
PolygonShapeConfRotate (const UnitVec &value)
 Rotates all the vertices by the given amount.
 
PolygonShapeConfScale (const Vec2 &value)
 Scales all the vertices by the given amount.
 
PolygonShapeConfSet (const VertexSet &points)
 Sets the vertices to a convex hull of the given ones. More...
 
PolygonShapeConfSet (Span< const Length2 > points)
 Sets the vertices to a convex hull of the given ones. More...
 
PolygonShapeConfSetAsBox (Length hx, Length hy)
 Sets the vertices to represent an axis-aligned box centered on the local origin. More...
 
PolygonShapeConfSetAsBox (Length hx, Length hy, const Length2 &center, Angle angle)
 Sets the vertices for the described box.
 
PolygonShapeConfTransform (const Mat22 &m)
 Transforms the vertices by the given transformation matrix. More...
 
PolygonShapeConfTransform (const Transformation &xfm)
 Transforms the vertices by the given transformation.
 
PolygonShapeConfTranslate (const Length2 &value)
 Translates all the vertices by the given amount.
 
PolygonShapeConfUseVertexRadius (NonNegative< Length > value) noexcept
 Uses the given vertex radius.
 
PolygonShapeConfUseVertices (const Span< const Length2 > &verts)
 Uses the given vertices.
 
- Public Member Functions inherited from playrho::d2::ShapeBuilder< PolygonShapeConf >
constexpr PolygonShapeConfUseDensity (NonNegative< AreaDensity > value) noexcept
 Uses the given density.
 
constexpr PolygonShapeConfUseFilter (Filter value) noexcept
 Uses the given filter.
 
constexpr PolygonShapeConfUseFriction (NonNegative< Real > value) noexcept
 Uses the given friction.
 
constexpr PolygonShapeConfUseIsSensor (bool value) noexcept
 Uses the given is-sensor value.
 
constexpr PolygonShapeConfUseRestitution (Finite< Real > value) noexcept
 Uses the given restitution.
 

Static Public Member Functions

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

Public Attributes

NgonWithFwdNormals ngon
 N-gon data.
 
NonNegativeFF< LengthvertexRadius = GetDefaultVertexRadius()
 Vertex radius. More...
 
- Public Attributes inherited from playrho::d2::BaseShapeConf
NonNegative< AreaDensitydensity = DefaultDensity
 Area density of the associated shape. More...
 
Filter filter = DefaultFilter
 Filtering data for contacts.
 
NonNegative< Realfriction = DefaultFriction
 Friction coefficient. More...
 
bool isSensor = DefaultIsSensor
 A sensor shape collects contact information but never generates a collision response.
 
Finite< Realrestitution = DefaultRestitution
 Restitution (elasticity) of the associated shape. More...
 

Static Public Attributes

static constexpr auto DefaultVertexRadius = NonNegative<Length>{DefaultLinearSlop * 2}
 Default vertex radius.
 
- Static Public Attributes inherited from playrho::d2::BaseShapeConf
static constexpr auto DefaultDensity = NonNegative<AreaDensity>{0_kgpm2}
 Default density value.
 
static constexpr auto DefaultFilter = Filter{}
 Default filter value.
 
static constexpr auto DefaultFriction = NonNegative<Real>{Real{2} / Real{10}}
 Default friction value.
 
static constexpr auto DefaultIsSensor = false
 Default is-sensor value.
 
static const auto DefaultRestitution = Finite<Real>{}
 Default restitution value.
 

Friends

bool operator!= (const PolygonShapeConf &lhs, const PolygonShapeConf &rhs) noexcept
 Inequality operator.
 
bool operator== (const PolygonShapeConf &lhs, const PolygonShapeConf &rhs) noexcept
 Equality operator.
 

Related Functions

(Note that these are not member functions.)

DistanceProxy GetChild (const PolygonShapeConf &arg, ChildCounter index)
 Gets the "child" shape for the given shape configuration.
 
constexpr ChildCounter GetChildCount (const PolygonShapeConf &) noexcept
 Gets the "child" count for the given shape configuration. More...
 
MassData GetMassData (const PolygonShapeConf &arg)
 Gets the mass data for the given shape configuration.
 
NonNegative< LengthGetVertexRadius (const PolygonShapeConf &arg) noexcept
 Gets the vertex radius of the given shape configuration.
 
NonNegative< LengthGetVertexRadius (const PolygonShapeConf &arg, ChildCounter) noexcept
 Gets the vertex radius of the given shape configuration.
 
void Transform (PolygonShapeConf &arg, const Mat22 &m)
 Transforms the given polygon configuration's vertices by the given transformation matrix. More...
 

Detailed Description

An n-vertex convex polygon shaped part eligible for use with a Shape.

Note
The interior of the polygon geometry is to the left of each edge. The maximum number of vertices this can have is defined by MaxShapeVertices. If all you want is a rectangular part (that will only ever have 4-vertices) you may want to consider using a rectangular playrho::d2::part::Compositor instead.
See also
Shape, playrho::d2::part::Compositor.

Constructor & Destructor Documentation

◆ PolygonShapeConf() [1/2]

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

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() 
)
explicit

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

◆ GetDefaultVertexRadius()

static constexpr NonNegative<Length> playrho::d2::PolygonShapeConf::GetDefaultVertexRadius ( )
inlinestaticconstexprnoexcept

Gets the default vertex radius for the PolygonShapeConf.

Note
This is just a backward compatibility interface for getting the default vertex radius. The new way is to use DefaultVertexRadius directly.
Returns
DefaultVertexRadius.

◆ 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.

◆ GetVertexCount()

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

Gets the vertex count.

Returns
value between 0 and MaxShapeVertices inclusive.
See also
MaxShapeVertices

Referenced by GetChild(), GetNormal(), and GetVertex().

◆ GetVertices()

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

Gets the span of vertices.

Vertices go counter-clockwise.

Referenced by GetChild(), and GetMassData().

◆ Set() [1/2]

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

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

Note
The size of the span must be in the range [0, MaxShapeVertices].
This function provides the strong exception guarantee.
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 points)

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.

Referenced by PolygonShapeConf(), Rotate(), Scale(), Transform(), Translate(), and UseVertices().

◆ SetAsBox()

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

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

Parameters
hxthe half-width.
hythe half-height.

Referenced by SetAsBox().

◆ Transform()

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

Transforms the vertices by the given transformation matrix.

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

Friends And Related Function Documentation

◆ GetChildCount()

constexpr ChildCounter GetChildCount ( const PolygonShapeConf )
related

Gets the "child" count for the given shape configuration.

Returns
1.

◆ Transform()

void Transform ( PolygonShapeConf arg,
const Mat22 m 
)
related

Transforms the given polygon configuration's vertices by the given transformation matrix.

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

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

Member Data Documentation

◆ vertexRadius

NonNegativeFF<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 GetChild(), and GetMassData().


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