PlayRho  2.0.0
An interactive physics engine & library.
playrho::d2::DistanceProxy Class Reference

Distance Proxy. More...

#include <playrho/d2/DistanceProxy.hpp>

Public Types

using ConstNormalIterator = ConstNormalPointer
 Constant normal iterator.
 
using ConstNormalPointer = const UnitVec *
 Constant normal pointer.
 
using ConstVertexIterator = ConstVertexPointer
 Constant vertex iterator.
 
using ConstVertexPointer = const Length2 *
 Constant vertex pointer.
 

Public Member Functions

 DistanceProxy ()=default
 Default constructor.
 
 DistanceProxy (const DistanceProxy &copy) noexcept
 Copy constructor. More...
 
 DistanceProxy (const NonNegative< Length > &vertexRadius, const VertexCounter count, const Length2 *vertices, const UnitVec *normals) noexcept
 Initializing constructor. More...
 
auto GetNormal (VertexCounter index) const noexcept
 Gets the normal for the given index. More...
 
Span< const UnitVecGetNormals () const noexcept
 Gets the normals.
 
auto GetVertex (VertexCounter index) const noexcept
 Gets a vertex by index. More...
 
auto GetVertexCount () const noexcept
 Gets the vertex count. More...
 
auto GetVertexRadius () const noexcept
 Gets the vertex radius of the vertices of the associated shape. More...
 
Span< const Length2GetVertices () const noexcept
 Gets the vertices.
 

Related Functions

(Note that these are not member functions.)

AABB ComputeAABB (const DistanceProxy &proxy, const Transformation &xf) noexcept
 Computes the AABB. More...
 
AABB ComputeAABB (const DistanceProxy &proxy, const Transformation &xfm0, const Transformation &xfm1) noexcept
 Computes the AABB. More...
 
DistanceOutput Distance (const DistanceProxy &proxyA, const Transformation &transformA, const DistanceProxy &proxyB, const Transformation &transformB, DistanceConf conf=DistanceConf{})
 Determines the closest points between two shapes using an iterative method. More...
 
SeparationInfo GetMaxSeparation (const DistanceProxy &proxy1, const DistanceProxy &proxy2, Length stop=MaxFloat *Meter)
 Gets the max separation information. More...
 
SeparationInfo GetMaxSeparation (const DistanceProxy &proxy1, const Transformation &xf1, const DistanceProxy &proxy2, const Transformation &xf2)
 Gets the max separation information. More...
 
SeparationInfo GetMaxSeparation (const DistanceProxy &proxy1, const Transformation &xf1, const DistanceProxy &proxy2, const Transformation &xf2, Length stop)
 Gets the max separation information. More...
 
SeparationInfo GetMaxSeparation4x4 (const DistanceProxy &proxy1, const Transformation &xf1, const DistanceProxy &proxy2, const Transformation &xf2)
 Gets the max separation information for the first four vertices of the two given shapes. More...
 
template<class T >
VertexCounter GetSupportIndex (const DistanceProxy &proxy, T dir) noexcept
 Gets the supporting vertex index in given direction for given distance proxy. More...
 
auto GetVertexRadius (const DistanceProxy &arg) noexcept
 Gets the vertex radius property of a given distance proxy.
 
bool operator!= (const DistanceProxy &lhs, const DistanceProxy &rhs) noexcept
 Determines with the two given distance proxies are not equal.
 
bool operator== (const DistanceProxy &lhs, const DistanceProxy &rhs) noexcept
 Determines with the two given distance proxies are equal.
 
RayCastOutput RayCast (const DistanceProxy &proxy, const RayCastInput &input, const Transformation &transform) noexcept
 Cast a ray against the distance proxy. More...
 
Area TestOverlap (const DistanceProxy &proxyA, const Transformation &xfA, const DistanceProxy &proxyB, const Transformation &xfB, DistanceConf conf=DistanceConf{})
 Determine if two generic shapes overlap. More...
 
bool TestPoint (const DistanceProxy &proxy, const Length2 &point) noexcept
 Tests a point for containment in the given distance proxy. More...
 

Detailed Description

Distance Proxy.

A distance proxy aggregates a convex set of vertices, their normals, and a vertex radius of those vertices. This can be visualized as a convex N-sided polygon with rounded corners. It's meant to represent any single portion of a shape identified by its child-index.

Warning
It is the programmer's responsibility to ensure that the DistanceProxy does not outlive the pointed-to vertices or normals!
Examples
Compositor.cpp.

Constructor & Destructor Documentation

◆ DistanceProxy() [1/2]

playrho::d2::DistanceProxy::DistanceProxy ( const DistanceProxy copy)
inlinenoexcept

Copy constructor.

Warning
It is the programmer's responsibility to ensure that this DistanceProxy does not outlive the copied from DistanceProxy.

◆ DistanceProxy() [2/2]

playrho::d2::DistanceProxy::DistanceProxy ( const NonNegative< Length > &  vertexRadius,
const VertexCounter  count,
const Length2 vertices,
const UnitVec normals 
)
inlinenoexcept

Initializing constructor.

Constructs a distance proxy for n-point shape (like a polygon).

Parameters
vertexRadiusRadius of the given vertices.
countCount of elements of the vertices and normals arrays.
verticesPointer to array of vertices of shape (relative to shape's origin).
normalsPointer to array of normals of the shape.
Note
The vertices collection must have more than zero elements and no more than MaxShapeVertices elements.
Warning
It is the programmer's responsibility to ensure that the DistanceProxy does not outlive the pointed-to vertices or normals!
Behavior not specified if vertices array has less than one element or more than MaxShapeVertices elements.
Behavior is not specified if vertices are not in counter-clockwise order.
Behavior is not specified if shape defined by the vertices is not convex.
Behavior is not specified if normals aren't normals for adjacent vertices.
Behavior is not specified if any normal is not unique.

Member Function Documentation

◆ GetNormal()

auto playrho::d2::DistanceProxy::GetNormal ( VertexCounter  index) const
inlinenoexcept

Gets the normal for the given index.

Precondition
The given index is less than GetVertexCount().

Referenced by playrho::d2::GetManifold(), GetMaxSeparation(), and GetMaxSeparation4x4().

◆ GetVertex()

auto playrho::d2::DistanceProxy::GetVertex ( VertexCounter  index) const
inlinenoexcept

Gets a vertex by index.

Parameters
indexIndex value less than count of vertices represented by this proxy.
Precondition
The given index is less than GetVertexCount().
Returns
Vertex linear position (relative to shape's origin) at the given index.
See also
Distance, GetVertexCount.

Referenced by playrho::d2::Manifold::CollideShapes(), playrho::d2::GetManifold(), GetMaxSeparation(), GetMaxSeparation4x4(), and playrho::d2::GetSeparationScenario().

◆ GetVertexCount()

auto playrho::d2::DistanceProxy::GetVertexCount ( ) const
inlinenoexcept

Gets the vertex count.

This is the count of valid vertex elements that this object provides.

Returns
Value between 0 and MaxShapeVertices.
Note
This only returns 0 if this proxy was default constructed.

Referenced by playrho::d2::Manifold::CollideShapes(), Distance(), playrho::d2::GetManifold(), GetMaxSeparation(), playrho::d2::GetSeparationScenario(), and playrho::d2::Shape::GetVertexCount().

◆ GetVertexRadius()

auto playrho::d2::DistanceProxy::GetVertexRadius ( ) const
inlinenoexcept

Gets the vertex radius of the vertices of the associated shape.

Returns
Non-negative distance.

Referenced by playrho::d2::Manifold::CollideShapes(), playrho::d2::GetManifold(), and TestOverlap().

Friends And Related Function Documentation

◆ ComputeAABB() [1/2]

AABB ComputeAABB ( const DistanceProxy proxy,
const Transformation xf 
)
related

Computes the AABB.

Computes the Axis Aligned Bounding Box (AABB) for the given child shape at a given a transform.

Parameters
proxyDistance proxy for the child shape.
xfWorld transform of the shape.
Precondition
xf is valid.
Returns
AABB for the proxy shape or the default AABB if the proxy has a zero vertex count.

◆ ComputeAABB() [2/2]

AABB ComputeAABB ( const DistanceProxy proxy,
const Transformation xfm0,
const Transformation xfm1 
)
related

Computes the AABB.

Computes the Axis Aligned Bounding Box (AABB) for the given child shape at the given transforms.

Parameters
proxyDistance proxy for the child shape.
xfm0World transform 0 of the shape.
xfm1World transform 1 of the shape.
Precondition
xfm0 and xfm1 are both valid.
Returns
AABB for the proxy shape or the default AABB if the proxy has a zero vertex count.

◆ Distance()

DistanceOutput Distance ( const DistanceProxy proxyA,
const Transformation transformA,
const DistanceProxy proxyB,
const Transformation transformB,
DistanceConf  conf = DistanceConf{} 
)
related

Determines the closest points between two shapes using an iterative method.

Note
Supports any combination of convex shapes.
Uses the G.J.K. (GJK) algorithm: "a method for determining the minimum distance between two convex sets".
On the first call, size(conf.cache.indices) should be zero.
Parameters
proxyAProxy A.
transformATransform of A.
proxyBProxy B.
transformBTransform of B.
confConfiguration to use including the simplex cache for assisting the determination.
Returns
Closest points between the two shapes, the count of iterations it took to determine them, and the reason iterations stopped. The iteration count will always be greater than zero unless DefaultMaxDistanceIters is zero.
See also
https://en.wikipedia.org/wiki/Gilbert%2DJohnson%2DKeerthi_distance_algorithm
GetMaxSeparation.

◆ GetMaxSeparation() [1/3]

SeparationInfo GetMaxSeparation ( const DistanceProxy proxy1,
const DistanceProxy proxy2,
Length  stop = MaxFloat *Meter 
)
related

Gets the max separation information.

Returns
Index of the vertex and normal from proxy1, index of the vertex from proxy2 (that had the maximum separation distance from each other in the direction of that normal), and the maximal distance.
See also
Distance.

◆ GetMaxSeparation() [2/3]

SeparationInfo GetMaxSeparation ( const DistanceProxy proxy1,
const Transformation xf1,
const DistanceProxy proxy2,
const Transformation xf2 
)
related

Gets the max separation information.

Note
Prefer using this function - over the GetMaxSeparation function that takes a stopping length - when it's already known that the two convex shapes' AABBs overlap.
Returns
Index of the vertex and normal from proxy1, index of the vertex from proxy2 (that had the maximum separation distance from each other in the direction of that normal), and the maximal distance.
See also
Distance.

Referenced by playrho::d2::Manifold::CollideShapes().

◆ GetMaxSeparation() [3/3]

SeparationInfo GetMaxSeparation ( const DistanceProxy proxy1,
const Transformation xf1,
const DistanceProxy proxy2,
const Transformation xf2,
Length  stop 
)
related

Gets the max separation information.

Returns
Index of the vertex and normal from proxy1, index of the vertex from proxy2 (that had the maximum separation distance from each other in the direction of that normal), and the maximal distance.
See also
Distance.

◆ GetMaxSeparation4x4()

SeparationInfo GetMaxSeparation4x4 ( const DistanceProxy proxy1,
const Transformation xf1,
const DistanceProxy proxy2,
const Transformation xf2 
)
related

Gets the max separation information for the first four vertices of the two given shapes.

This is a version of the get-max-separation functions that is optimized for two quadrilateral (4-sided) polygons.

Returns
Index of the vertex and normal from proxy1, index of the vertex from proxy2 (that had the maximum separation distance from each other in the direction of that normal), and the maximal distance.
See also
Distance.

Referenced by playrho::d2::Manifold::CollideShapes().

◆ GetSupportIndex()

template<class T >
VertexCounter GetSupportIndex ( const DistanceProxy proxy,
dir 
)
related

Gets the supporting vertex index in given direction for given distance proxy.

This finds the vertex that's most significantly in direction of the given vector and returns its index.

Note
0 is returned for a given zero length direction vector.
Parameters
proxyDistance proxy object to find index in if a valid index exists for it.
dirDirection vector to find index for.
Returns
InvalidVertex if d is invalid or the count of vertices is zero, otherwise a value from 0 to one less than count.
See also
GetVertexCount().

◆ TestOverlap()

Area TestOverlap ( const DistanceProxy proxyA,
const Transformation xfA,
const DistanceProxy proxyB,
const Transformation xfB,
DistanceConf  conf = DistanceConf{} 
)
related

Determine if two generic shapes overlap.

Note
The returned touching state information typically agrees with that returned from the CollideShapes function. This is not always the case however especially when the separation or overlap distance is closer to zero.

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