GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::physics::Contact< N > Struct Template Reference

Potential collision between two objects in a Simulation, including a stateful collision algorithm for generating the actual contact points between them. More...

#include <GREM/physics/collision.hpp>

Public Types

using ManifoldMask = BitArray<MAX_MANIFOLD_COUNT>
 Bitset of manifold indices in a contact.

Public Member Functions

 Contact (ShapeView< N > shapeA, ShapeView< N > shapeB)
 Construct a contact with a collision algorithm that can be used to generate contact points for a given ordered pair of shapes.
size_t insertCollision (ManifoldMask &mergedManifolds, const CollisionAlgorithmResult< N > &collision, const Transformation< N > &transformationA, const Transformation< N > &transformationB, LinearVelocity< N > linearVelocityA, LinearVelocity< N > linearVelocityB, AngularVelocity< N > angularVelocityA, AngularVelocity< N > angularVelocityB, Distance maxCollisionTouchingDistance, Scale1D minContactManifoldDotProduct)
 Merge in a new collision manifold with the existing manifolds, and calculate its new tangent and relative tangent-space velocity.
void removeManifolds (ManifoldMask removeMask)
 Remove a specific set of manifolds.

Static Public Member Functions

static OrthonormalBasis< N > getTangentSpaceBasis (Direction< N > normal, LinearVelocity< N > relativeVelocity)
 Calculate a suitable orthonormal tangent-space basis for a contact point pair given its normal and current relative velocity.

Public Attributes

InplaceArrayList< ContactManifold< N >, MAX_MANIFOLD_COUNT > manifolds {}
 List of contact manifolds between the potentially colliding objects.
CollisionAlgorithm< N > collisionAlgorithm
 Collision algorithm for generating contact points between the potentially colliding objects.
bool wasTouchingOnLastSubStep = false
 Whether the contact had at least one manifold during the last sub-step or not.

Static Public Attributes

static constexpr size_t MAX_MANIFOLD_COUNT = (N == 3) ? 4 : 2
 Maximum number of contact manifolds in a single contact.

Detailed Description

template<size_t N>
struct grem::physics::Contact< N >

Potential collision between two objects in a Simulation, including a stateful collision algorithm for generating the actual contact points between them.

Template Parameters
Nnumber of dimensions of the world space (must be 2 or 3).

Member Typedef Documentation

◆ ManifoldMask

template<size_t N>
using grem::physics::Contact< N >::ManifoldMask = BitArray<MAX_MANIFOLD_COUNT>

Bitset of manifold indices in a contact.

Constructor & Destructor Documentation

◆ Contact()

template<size_t N>
grem::physics::Contact< N >::Contact ( ShapeView< N > shapeA,
ShapeView< N > shapeB )
inline

Construct a contact with a collision algorithm that can be used to generate contact points for a given ordered pair of shapes.

Parameters
shapeAthe first shape in the pair of shapes to choose a collision algorithm for.
shapeBthe second shape to the pair of shapes to choose a collision algorithm for.
Exceptions
std::bad_allocon allocation failure.

Member Function Documentation

◆ getTangentSpaceBasis()

template<size_t N>
OrthonormalBasis< N > grem::physics::Contact< N >::getTangentSpaceBasis ( Direction< N > normal,
LinearVelocity< N > relativeVelocity )
inlinestaticnodiscard

Calculate a suitable orthonormal tangent-space basis for a contact point pair given its normal and current relative velocity.

Parameters
normalworld-space contact normal.
relativeVelocityrelative world-space velocity of the contact point (A - B).
Returns
the tangent-space basis in world space as a TBN matrix (tangent, bitangent, normal) in 3D or a TN matrix (tangent, normal) in 2D.

◆ insertCollision()

template<size_t N>
size_t grem::physics::Contact< N >::insertCollision ( ManifoldMask & mergedManifolds,
const CollisionAlgorithmResult< N > & collision,
const Transformation< N > & transformationA,
const Transformation< N > & transformationB,
LinearVelocity< N > linearVelocityA,
LinearVelocity< N > linearVelocityB,
AngularVelocity< N > angularVelocityA,
AngularVelocity< N > angularVelocityB,
Distance maxCollisionTouchingDistance,
Scale1D minContactManifoldDotProduct )
inline

Merge in a new collision manifold with the existing manifolds, and calculate its new tangent and relative tangent-space velocity.

The merging logic works as follows:

  • If there exists a manifold with equal featureTypes, featureIndices and filterTestResult that has a similar enough normal (within minContactManifoldDotProduct), and it has not already been merged, its normal is replaced with the new manifold's normal and its points are merged with the new manifold's points.
    • Before merging, existing points that are no longer within touching range are removed.
    • When merging, existing points that are within maxCollisionTouchingDistance of a new point get their offsets and localOffsets replaced, but keep the values of other fields (transformed to the new tangent-space basis).
    • Other points are transformed to the new tangent-space basis, but otherwise remain unchanged. If no nearby point was found, the new point is added to the list, unless the list is full, in which case it replaces the point with the smallest penetration depth.
  • Otherwise, if no manifold suitable for merging was found, the new manifold is added to the list, unless the list is full, in which case it replaces the manifold whose deepest point has the smallest penetration depth.
Parameters
mergedManifoldsmask of manifolds that have already been merged, which will be excluded from being merged again (unless the list is full). The mask will be updated to also contain the new index chosen by this procedure.
collisioncollision containing the new manifold to merge in.
transformationAworld-space transformation of the first object.
transformationBworld-space transformation of the second object.
linearVelocityAworld-space linear velocity of the first object.
linearVelocityBworld-space linear velocity of the second object.
angularVelocityAworld-space angular velocity of the first object.
angularVelocityBworld-space angular velocity of the second object.
maxCollisionTouchingDistancemaximum separation distance of a contact point before it is considered to no longer be touching. Must be non-negative.
minContactManifoldDotProductminimum dot product (cosine of the angle) between two manifold normals before they are no longer considered similar enough to be merged.
Returns
the index of the merged manifold.

◆ removeManifolds()

template<size_t N>
void grem::physics::Contact< N >::removeManifolds ( ManifoldMask removeMask)
inline

Remove a specific set of manifolds.

Parameters
removeMaskbitmask of manifolds to remove, where each set bit refers to the corresponding index to remove from the list of manifolds.

Member Data Documentation

◆ MAX_MANIFOLD_COUNT

template<size_t N>
size_t grem::physics::Contact< N >::MAX_MANIFOLD_COUNT = (N == 3) ? 4 : 2
staticconstexpr

Maximum number of contact manifolds in a single contact.

◆ manifolds

template<size_t N>
InplaceArrayList<ContactManifold<N>, MAX_MANIFOLD_COUNT> grem::physics::Contact< N >::manifolds {}

List of contact manifolds between the potentially colliding objects.

◆ collisionAlgorithm

template<size_t N>
CollisionAlgorithm<N> grem::physics::Contact< N >::collisionAlgorithm

Collision algorithm for generating contact points between the potentially colliding objects.

◆ wasTouchingOnLastSubStep

template<size_t N>
bool grem::physics::Contact< N >::wasTouchingOnLastSubStep = false

Whether the contact had at least one manifold during the last sub-step or not.


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