|
|
|
|
@ -1246,7 +1246,6 @@ static bool b3BuildEdgeContact( b3LocalManifold* manifold, const b3HullData* hul
|
|
|
|
|
|
|
|
|
|
// Transform a SoA point/normal stream (already split into X/Y/Z) by out = -(R*v (+t)).
|
|
|
|
|
// The inputs come straight from the hull's stored SoA arrays, so there's no transpose here.
|
|
|
|
|
// IsPoint is a template arg so the translation add is only emitted for points.
|
|
|
|
|
static inline void b3NegativeTransformFromSoA( b3Matrix3* R, b3Vec3 p, const float* inX, const float* inY, const float* inZ,
|
|
|
|
|
int n, float* outX, float* outY, float* outZ, bool isPoint )
|
|
|
|
|
{
|
|
|
|
|
@ -1352,9 +1351,88 @@ static inline void b3GetSupportWide( b3Vec3 normal, const float* vx, const float
|
|
|
|
|
*support = normal.x * vx[vi] + normal.y * vy[vi] + normal.z * vz[vi];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define NE ( B3_MAX_HULL_EDGES + 4 )
|
|
|
|
|
#define NF ( B3_MAX_HULL_FACES + 4 )
|
|
|
|
|
#define NV ( B3_MAX_HULL_VERTICES + 4 )
|
|
|
|
|
static inline float b3GetFaceSeparation( b3Vec3 direction, float planeSeparation, const float* vx, const float* vy,
|
|
|
|
|
const float* vz, int n, b3Vec3 center, b3Vec3 extents, int* vertexIndex )
|
|
|
|
|
{
|
|
|
|
|
float bias = b3Dot( direction, center ) + 1.0625f * b3Dot( b3Abs( direction ), extents );
|
|
|
|
|
float support;
|
|
|
|
|
b3GetSupportWide( direction, vx, vy, vz, n, bias, &support, vertexIndex );
|
|
|
|
|
return planeSeparation - support;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wide dot(n, d) for all face normals n of the hull, padded to the SIMD width.
|
|
|
|
|
static inline void b3GetFaceDots( const b3HullData* hull, b3Vec3 d, float* dots )
|
|
|
|
|
{
|
|
|
|
|
int soaFaceCount = ( hull->faceCount + 3 ) & ~3;
|
|
|
|
|
const float* nx = b3GetHullSoaNormals( hull );
|
|
|
|
|
const float* ny = nx + soaFaceCount;
|
|
|
|
|
const float* nz = ny + soaFaceCount;
|
|
|
|
|
|
|
|
|
|
b3FloatW dx = b3SplatW( d.x );
|
|
|
|
|
b3FloatW dy = b3SplatW( d.y );
|
|
|
|
|
b3FloatW dz = b3SplatW( d.z );
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < soaFaceCount; i += 4 )
|
|
|
|
|
{
|
|
|
|
|
// dot product per lane
|
|
|
|
|
b3FloatW m = b3Dot3W( b3LoadW( nx + i ), b3LoadW( ny + i ), b3LoadW( nz + i ), dx, dy, dz );
|
|
|
|
|
b3StoreW( dots + i, m );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define B3_PARALLEL_TOL 1e-4f
|
|
|
|
|
|
|
|
|
|
// A hull edges is bounded by two face normals. On the Gauss map the edge becomes an arc between
|
|
|
|
|
// those two face normals. This edge can only build the best separating axis if a normal on that arc
|
|
|
|
|
// can beat the best separation value seen so far. This test determines of such a normal exists.
|
|
|
|
|
// This follows the upper bound used for hull faces:
|
|
|
|
|
// separation_upper_bound = dot(axis, centerB - centerA) - innerRadiusA - innerRadiusB
|
|
|
|
|
//
|
|
|
|
|
// Inputs:
|
|
|
|
|
// d the vector connecting the hull centers
|
|
|
|
|
// a = dot(u, d)
|
|
|
|
|
// b = dot(v, d)
|
|
|
|
|
// c = dot(u, v)
|
|
|
|
|
// length = length(d)
|
|
|
|
|
// bound = max_sep + radiusBound
|
|
|
|
|
// Note: this doesn't compute the separation, it just rules out potential candidates. So if some input
|
|
|
|
|
// is degenerate it just pass the candidate onto the next stage.
|
|
|
|
|
static inline int b3ArcCanReach( float a, float b, float c, float length, float bound )
|
|
|
|
|
{
|
|
|
|
|
// c = cos(theta), the angle between the normals.
|
|
|
|
|
// s = sin(theta)^2 >= 0
|
|
|
|
|
float s = 1.0f - c * c;
|
|
|
|
|
|
|
|
|
|
// This is coincidently the law of cosines. Break out your protractor.
|
|
|
|
|
float t = a * a + b * b - 2.0f * a * b * c;
|
|
|
|
|
|
|
|
|
|
// Do either face normals beat the best separation?
|
|
|
|
|
int endpoint = b3MaxFloat( a, b ) >= bound;
|
|
|
|
|
|
|
|
|
|
// Project d into the plane that holds both u and v, call that vector g:
|
|
|
|
|
// g = x*u + y*v
|
|
|
|
|
// Note that dot(u, g) == dot(u, d) == a, and dot(v, g) == dot(v, d) == b
|
|
|
|
|
// Dot the equation with u and v:
|
|
|
|
|
// a = x + y*c
|
|
|
|
|
// b = x*c + y
|
|
|
|
|
// Solve for x and y using Cramer's Rule
|
|
|
|
|
// x = (a - b * c) / (1 - c * c)
|
|
|
|
|
// y = (b - a * c) / (1 - c * c)
|
|
|
|
|
// s = 1 - c * c is greater than 0, so x and y must be positive for n to live between u and v.
|
|
|
|
|
// The peak value along d is then dot(g, n):
|
|
|
|
|
// dot(g, n) = x*a + y*b = (a*a - a*b*c + b*b - a*b*c) / s = (a*a + b*b - 2*a*b*c) / s = t / s
|
|
|
|
|
// If that peak value beats the threshold then this edge might form the best separating axis.
|
|
|
|
|
// Using bit ops here to prevent unpredictable branches.
|
|
|
|
|
int interior = ( a >= c * b ) & ( b >= c * a ) & ( length >= bound ) &
|
|
|
|
|
( ( bound <= 0.0f ) | ( s < B3_PARALLEL_TOL ) | ( t >= bound * bound * s ) );
|
|
|
|
|
|
|
|
|
|
return endpoint | interior;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Temporary abbreviations for convenience.
|
|
|
|
|
#define NE ( B3_MAX_HULL_EDGES + B3_SIMD_WIDTH )
|
|
|
|
|
#define NF ( B3_MAX_HULL_FACES + B3_SIMD_WIDTH )
|
|
|
|
|
#define NV ( B3_MAX_HULL_VERTICES + B3_SIMD_WIDTH )
|
|
|
|
|
|
|
|
|
|
// SIMD separating axis test based on an implementation developed by Cairn Overturf.
|
|
|
|
|
// See his article: https://cairno.substack.com/p/improvements-to-the-separating-axis
|
|
|
|
|
@ -1404,17 +1482,65 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
b3Vec3 cB = b3AABB_Center( hullB->aabb );
|
|
|
|
|
b3Vec3 hB = b3AABB_Extents( hullB->aabb );
|
|
|
|
|
|
|
|
|
|
// The hulls have a precomputed inner radius and centroid.
|
|
|
|
|
// A give axis cannot achieve a separation larger than:
|
|
|
|
|
// dot(axis, centerB - centerA) - innerRadiusA - innerRadiusB
|
|
|
|
|
// So this is the upper bound for the separation of a candidate axis.
|
|
|
|
|
// An axis can be skipped if it has an upper bound that is less than the current
|
|
|
|
|
// best separation. This lets me skip many of the candidates without computing
|
|
|
|
|
// support points.
|
|
|
|
|
|
|
|
|
|
b3Vec3 deltaCenter = b3Sub( b3Add( b3MulMV( R, hullB->center ), xfB.p ), hullA->center );
|
|
|
|
|
float centerDistance = b3Length( deltaCenter );
|
|
|
|
|
float radius = hullA->innerRadius + hullB->innerRadius;
|
|
|
|
|
|
|
|
|
|
// Adjust the radius to ensure the best axis isn't skipped.
|
|
|
|
|
float radiusBound = radius - ( B3_LINEAR_SLOP + 0.001f * ( centerDistance + radius ) );
|
|
|
|
|
|
|
|
|
|
// Compute dot(normalA, centerDelta) for all face normals of hullA.
|
|
|
|
|
_Alignas( 16 ) float dotA[NF];
|
|
|
|
|
b3GetFaceDots( hullA, deltaCenter, dotA );
|
|
|
|
|
|
|
|
|
|
// Find the face of hullA that most aligns with centerDelta.
|
|
|
|
|
int seedIndexA = 0;
|
|
|
|
|
float maxDotA = dotA[0];
|
|
|
|
|
for ( int i = 1; i < faceCountA; ++i )
|
|
|
|
|
{
|
|
|
|
|
if ( dotA[i] > maxDotA )
|
|
|
|
|
{
|
|
|
|
|
maxDotA = dotA[i];
|
|
|
|
|
seedIndexA = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use the seed to get a lower bound on the separation for the faces of hullA.
|
|
|
|
|
float floorA = -INFINITY;
|
|
|
|
|
if ( earlyReturn )
|
|
|
|
|
{
|
|
|
|
|
b3Plane plane = planesA[seedIndexA];
|
|
|
|
|
b3Vec3 direction = b3Neg( b3MulMV( invR, plane.normal ) );
|
|
|
|
|
float planeSeparation = b3Dot( plane.normal, xfB.p ) - plane.offset;
|
|
|
|
|
int vertexIndex;
|
|
|
|
|
float separation =
|
|
|
|
|
b3GetFaceSeparation( direction, planeSeparation, vxB, vyB, vzB, soaVertexCountB, cB, hB, &vertexIndex );
|
|
|
|
|
floorA = b3MinFloat( separation, speculativeDistance );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test A's face planes against B's vertices.
|
|
|
|
|
for ( int i = 0; i < faceCountA; ++i )
|
|
|
|
|
{
|
|
|
|
|
// The bound offset ensures the seed will be evaluated.
|
|
|
|
|
if ( dotA[i] - radiusBound < b3MaxFloat( floorA, res.faceA.separation ) )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b3Plane plane = planesA[i];
|
|
|
|
|
b3Vec3 direction = b3Neg( b3MulMV( invR, plane.normal ) );
|
|
|
|
|
float planeSeparation = b3Dot( plane.normal, xfB.p ) - plane.offset;
|
|
|
|
|
float biasB = b3Dot( direction, cB ) + 1.0625f * b3Dot( b3Abs( direction ), hB );
|
|
|
|
|
float support;
|
|
|
|
|
int vertexIndex;
|
|
|
|
|
b3GetSupportWide( direction, vxB, vyB, vzB, soaVertexCountB, biasB, &support, &vertexIndex );
|
|
|
|
|
float separation = planeSeparation - support;
|
|
|
|
|
float separation =
|
|
|
|
|
b3GetFaceSeparation( direction, planeSeparation, vxB, vyB, vzB, soaVertexCountB, cB, hB, &vertexIndex );
|
|
|
|
|
if ( separation > res.faceA.separation )
|
|
|
|
|
{
|
|
|
|
|
res.faceA.normal = plane.normal;
|
|
|
|
|
@ -1429,6 +1555,8 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
B3_VALIDATE( res.faceA.indexA != B3_NULL_INDEX );
|
|
|
|
|
|
|
|
|
|
int faceCountB = hullB->faceCount;
|
|
|
|
|
const b3Plane* planesB = b3GetHullPlanes( hullB );
|
|
|
|
|
|
|
|
|
|
@ -1440,17 +1568,51 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
b3Vec3 cA = b3AABB_Center( hullA->aabb );
|
|
|
|
|
b3Vec3 hA = b3AABB_Extents( hullA->aabb );
|
|
|
|
|
|
|
|
|
|
// Similarly, find the face of hullB that most aligns with the vector pointing from centerB to centerA.
|
|
|
|
|
_Alignas( 16 ) float dotB[NF];
|
|
|
|
|
b3GetFaceDots( hullB, b3Neg( b3MulMV( invR, deltaCenter ) ), dotB );
|
|
|
|
|
|
|
|
|
|
int seedIndexB = 0;
|
|
|
|
|
float maxDotB = dotB[0];
|
|
|
|
|
for ( int i = 1; i < faceCountB; ++i )
|
|
|
|
|
{
|
|
|
|
|
if ( dotB[i] > maxDotB )
|
|
|
|
|
{
|
|
|
|
|
maxDotB = dotB[i];
|
|
|
|
|
seedIndexB = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get a lower bound on the separation for the faces of hullB.
|
|
|
|
|
float floorB = -INFINITY;
|
|
|
|
|
if ( earlyReturn )
|
|
|
|
|
{
|
|
|
|
|
b3Plane plane = planesB[seedIndexB];
|
|
|
|
|
b3Vec3 direction = b3Neg( b3MulMV( R, plane.normal ) );
|
|
|
|
|
float planeSeparation = b3Dot( direction, xfB.p ) - plane.offset;
|
|
|
|
|
int vertexIndex;
|
|
|
|
|
float separation =
|
|
|
|
|
b3GetFaceSeparation( direction, planeSeparation, vxA, vyA, vzA, soaVertexCountA, cA, hA, &vertexIndex );
|
|
|
|
|
|
|
|
|
|
// Include the floor set by hull A faces.
|
|
|
|
|
floorB = b3MaxFloat( separation, res.faceA.separation );
|
|
|
|
|
floorB = b3MinFloat( floorB, speculativeDistance );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test B's face planes against A's vertices.
|
|
|
|
|
for ( int i = 0; i < faceCountB; ++i )
|
|
|
|
|
{
|
|
|
|
|
if ( dotB[i] - radiusBound < b3MaxFloat( floorB, res.faceB.separation ) )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b3Plane plane = planesB[i];
|
|
|
|
|
b3Vec3 direction = b3Neg( b3MulMV( R, plane.normal ) );
|
|
|
|
|
float planeSeparation = b3Dot( direction, xfB.p ) - plane.offset;
|
|
|
|
|
float biasA = b3Dot( direction, cA ) + 1.0625f * b3Dot( b3Abs( direction ), hA );
|
|
|
|
|
float support;
|
|
|
|
|
int vertexIndex;
|
|
|
|
|
b3GetSupportWide( direction, vxA, vyA, vzA, soaVertexCountA, biasA, &support, &vertexIndex );
|
|
|
|
|
float separation = planeSeparation - support;
|
|
|
|
|
float separation =
|
|
|
|
|
b3GetFaceSeparation( direction, planeSeparation, vxA, vyA, vzA, soaVertexCountA, cA, hA, &vertexIndex );
|
|
|
|
|
if ( separation > res.faceB.separation )
|
|
|
|
|
{
|
|
|
|
|
res.faceB.normal = direction;
|
|
|
|
|
@ -1466,11 +1628,48 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Transform B into A's space once, into SoA arrays. Extra space so
|
|
|
|
|
// tail can be set to zero in all cases.
|
|
|
|
|
_Static_assert( ( B3_MAX_HULL_EDGES & 3 ) == 0, "must be multiple of 4" );
|
|
|
|
|
_Static_assert( ( B3_MAX_HULL_FACES & 3 ) == 0, "must be multiple of 4" );
|
|
|
|
|
_Static_assert( ( B3_MAX_HULL_VERTICES & 3 ) == 0, "must be multiple of 4" );
|
|
|
|
|
// Transform B into A's space once, into SoA arrays. Extra space so tail can be set to zero.
|
|
|
|
|
_Static_assert( ( B3_MAX_HULL_EDGES & ( B3_SIMD_WIDTH - 1 ) ) == 0, "must be multiple of SIMD width" );
|
|
|
|
|
_Static_assert( ( B3_MAX_HULL_FACES & ( B3_SIMD_WIDTH - 1 ) ) == 0, "must be multiple of SIMD width" );
|
|
|
|
|
_Static_assert( ( B3_MAX_HULL_VERTICES & ( B3_SIMD_WIDTH - 1 ) ) == 0, "must be multiple of SIMD width" );
|
|
|
|
|
|
|
|
|
|
// Bound to skip edge tests. Derived from:
|
|
|
|
|
// dot(edgeNormal, deltaCenter) - radiusBound > maxSep
|
|
|
|
|
float edgeBound = earlyReturn ? b3MaxFloat( res.faceA.separation, res.faceB.separation ) + radiusBound : -INFINITY;
|
|
|
|
|
|
|
|
|
|
// Gather edges of A that can feasibly create a winning separating axis.
|
|
|
|
|
int halfEdgeCountA = hullA->edgeCount;
|
|
|
|
|
const b3HullHalfEdge* halfEdgesA = b3GetHullEdges( hullA );
|
|
|
|
|
int edgeIndicesA[NE];
|
|
|
|
|
int na = 0;
|
|
|
|
|
for ( int i = 0; i < halfEdgeCountA; i += 2 )
|
|
|
|
|
{
|
|
|
|
|
int i1 = halfEdgesA[i].face;
|
|
|
|
|
int i2 = halfEdgesA[i + 1].face;
|
|
|
|
|
float c = b3Dot( planesA[i1].normal, planesA[i2].normal );
|
|
|
|
|
edgeIndicesA[na] = i;
|
|
|
|
|
na += b3ArcCanReach( dotA[i1], dotA[i2], c, centerDistance, edgeBound );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gather edges of B that can feasibly create a winning separating axis.
|
|
|
|
|
int halfEdgeCountB = hullB->edgeCount;
|
|
|
|
|
const b3HullHalfEdge* halfEdgesB = b3GetHullEdges( hullB );
|
|
|
|
|
int edgeIndicesB[B3_MAX_HULL_EDGES];
|
|
|
|
|
int nb = 0;
|
|
|
|
|
for ( int i = 0; i < halfEdgeCountB; i += 2 )
|
|
|
|
|
{
|
|
|
|
|
int i1 = halfEdgesB[i].face;
|
|
|
|
|
int i2 = halfEdgesB[i + 1].face;
|
|
|
|
|
float c = b3Dot( planesB[i1].normal, planesB[i2].normal );
|
|
|
|
|
edgeIndicesB[nb] = i;
|
|
|
|
|
nb += b3ArcCanReach( dotB[i1], dotB[i2], c, centerDistance, edgeBound );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( na == 0 || nb == 0 )
|
|
|
|
|
{
|
|
|
|
|
// No edge candidates found.
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The alignments below are not necessary, but they don't hurt.
|
|
|
|
|
|
|
|
|
|
@ -1506,31 +1705,27 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
_Alignas( 16 ) float bDCy[NE];
|
|
|
|
|
_Alignas( 16 ) float bDCz[NE];
|
|
|
|
|
|
|
|
|
|
int halfEdgeCountB = hullB->edgeCount;
|
|
|
|
|
const b3HullHalfEdge* halfEdgesB = b3GetHullEdges( hullB );
|
|
|
|
|
int nb = 0;
|
|
|
|
|
for ( int i = 0; i < halfEdgeCountB; i += 2 )
|
|
|
|
|
for ( int k = 0; k < nb; ++k )
|
|
|
|
|
{
|
|
|
|
|
const b3HullHalfEdge* edge = halfEdgesB + i;
|
|
|
|
|
const b3HullHalfEdge* edge = halfEdgesB + edgeIndicesB[k];
|
|
|
|
|
const b3HullHalfEdge* twin = edge + 1;
|
|
|
|
|
int f0 = edge->face;
|
|
|
|
|
int f1 = twin->face;
|
|
|
|
|
int v0 = edge->origin;
|
|
|
|
|
int v1 = twin->origin;
|
|
|
|
|
|
|
|
|
|
bCx[nb] = bFNx[f0];
|
|
|
|
|
bCy[nb] = bFNy[f0];
|
|
|
|
|
bCz[nb] = bFNz[f0];
|
|
|
|
|
bDx[nb] = bFNx[f1];
|
|
|
|
|
bDy[nb] = bFNy[f1];
|
|
|
|
|
bDz[nb] = bFNz[f1];
|
|
|
|
|
bV0x[nb] = bWx[v0];
|
|
|
|
|
bV0y[nb] = bWy[v0];
|
|
|
|
|
bV0z[nb] = bWz[v0];
|
|
|
|
|
bDCx[nb] = bWx[v1] - bWx[v0];
|
|
|
|
|
bDCy[nb] = bWy[v1] - bWy[v0];
|
|
|
|
|
bDCz[nb] = bWz[v1] - bWz[v0];
|
|
|
|
|
nb += 1;
|
|
|
|
|
bCx[k] = bFNx[f0];
|
|
|
|
|
bCy[k] = bFNy[f0];
|
|
|
|
|
bCz[k] = bFNz[f0];
|
|
|
|
|
bDx[k] = bFNx[f1];
|
|
|
|
|
bDy[k] = bFNy[f1];
|
|
|
|
|
bDz[k] = bFNz[f1];
|
|
|
|
|
bV0x[k] = bWx[v0];
|
|
|
|
|
bV0y[k] = bWy[v0];
|
|
|
|
|
bV0z[k] = bWz[v0];
|
|
|
|
|
bDCx[k] = bWx[v1] - bWx[v0];
|
|
|
|
|
bDCy[k] = bWy[v1] - bWy[v0];
|
|
|
|
|
bDCz[k] = bWz[v1] - bWz[v0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Per A edge data, already in A's space so just gathered. n0 and n1 are the two face
|
|
|
|
|
@ -1551,37 +1746,32 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
_Alignas( 16 ) float aV0z[NE];
|
|
|
|
|
_Alignas( 16 ) float aTol[NE];
|
|
|
|
|
|
|
|
|
|
int halfEdgeCountA = hullA->edgeCount;
|
|
|
|
|
const b3HullHalfEdge* halfEdgesA = b3GetHullEdges( hullA );
|
|
|
|
|
int na = 0;
|
|
|
|
|
|
|
|
|
|
float squaredTol = B3_PARALLEL_EDGE_TOL * B3_PARALLEL_EDGE_TOL;
|
|
|
|
|
for ( int i = 0; i < halfEdgeCountA; i += 2 )
|
|
|
|
|
for ( int k = 0; k < na; ++k )
|
|
|
|
|
{
|
|
|
|
|
const b3HullHalfEdge* edge = halfEdgesA + i;
|
|
|
|
|
const b3HullHalfEdge* edge = halfEdgesA + edgeIndicesA[k];
|
|
|
|
|
const b3HullHalfEdge* twin = edge + 1;
|
|
|
|
|
|
|
|
|
|
b3Vec3 A = planesA[edge->face].normal;
|
|
|
|
|
b3Vec3 B = planesA[twin->face].normal;
|
|
|
|
|
aN0x[na] = A.x;
|
|
|
|
|
aN0y[na] = A.y;
|
|
|
|
|
aN0z[na] = A.z;
|
|
|
|
|
aN1x[na] = B.x;
|
|
|
|
|
aN1y[na] = B.y;
|
|
|
|
|
aN1z[na] = B.z;
|
|
|
|
|
aN0x[k] = A.x;
|
|
|
|
|
aN0y[k] = A.y;
|
|
|
|
|
aN0z[k] = A.z;
|
|
|
|
|
aN1x[k] = B.x;
|
|
|
|
|
aN1y[k] = B.y;
|
|
|
|
|
aN1z[k] = B.z;
|
|
|
|
|
|
|
|
|
|
int v0 = edge->origin;
|
|
|
|
|
int v1 = twin->origin;
|
|
|
|
|
|
|
|
|
|
aDx[na] = vxA[v1] - vxA[v0];
|
|
|
|
|
aDy[na] = vyA[v1] - vyA[v0];
|
|
|
|
|
aDz[na] = vzA[v1] - vzA[v0];
|
|
|
|
|
aV0x[na] = vxA[v0];
|
|
|
|
|
aV0y[na] = vyA[v0];
|
|
|
|
|
aV0z[na] = vzA[v0];
|
|
|
|
|
aDx[k] = vxA[v1] - vxA[v0];
|
|
|
|
|
aDy[k] = vyA[v1] - vyA[v0];
|
|
|
|
|
aDz[k] = vzA[v1] - vzA[v0];
|
|
|
|
|
aV0x[k] = vxA[v0];
|
|
|
|
|
aV0y[k] = vyA[v0];
|
|
|
|
|
aV0z[k] = vzA[v0];
|
|
|
|
|
|
|
|
|
|
aTol[na] = squaredTol * ( aDx[na] * aDx[na] + aDy[na] * aDy[na] + aDz[na] * aDz[na] );
|
|
|
|
|
na += 1;
|
|
|
|
|
aTol[k] = squaredTol * ( aDx[k] * aDx[k] + aDy[k] * aDy[k] + aDz[k] * aDz[k] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Zero the tail lanes.
|
|
|
|
|
@ -1600,8 +1790,6 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
b3StoreW( aV0z + na, zero );
|
|
|
|
|
b3StoreW( aTol + na, zero );
|
|
|
|
|
|
|
|
|
|
int edgeCountB = halfEdgeCountB / 2;
|
|
|
|
|
|
|
|
|
|
#if defined( B3_SIMD_NONE )
|
|
|
|
|
|
|
|
|
|
// The SIMD emulated version of this code is very slow. This is a purely scalar version
|
|
|
|
|
@ -1610,7 +1798,7 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
|
|
|
|
|
const float EPS = -0.0001f;
|
|
|
|
|
|
|
|
|
|
for ( int j = 0; j < edgeCountB; ++j )
|
|
|
|
|
for ( int j = 0; j < nb; ++j )
|
|
|
|
|
{
|
|
|
|
|
float Cx = bCx[j];
|
|
|
|
|
float Cy = bCy[j];
|
|
|
|
|
@ -1675,8 +1863,8 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
res.edge.separation = separation;
|
|
|
|
|
|
|
|
|
|
// Half edge index
|
|
|
|
|
res.edge.indexA = 2 * i;
|
|
|
|
|
res.edge.indexB = 2 * j;
|
|
|
|
|
res.edge.indexA = edgeIndicesA[i];
|
|
|
|
|
res.edge.indexB = edgeIndicesB[j];
|
|
|
|
|
|
|
|
|
|
if ( separation > speculativeDistance && earlyReturn )
|
|
|
|
|
{
|
|
|
|
|
@ -1693,7 +1881,7 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
const b3FloatW EPS = b3SplatW( -0.0001f );
|
|
|
|
|
const b3FloatW INF = b3SplatW( INFINITY );
|
|
|
|
|
|
|
|
|
|
for ( int j = 0; j < edgeCountB; ++j )
|
|
|
|
|
for ( int j = 0; j < nb; ++j )
|
|
|
|
|
{
|
|
|
|
|
const b3FloatW Cx = b3SplatW( bCx[j] );
|
|
|
|
|
const b3FloatW Cy = b3SplatW( bCy[j] );
|
|
|
|
|
@ -1805,8 +1993,8 @@ b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData*
|
|
|
|
|
res.edge.separation = s;
|
|
|
|
|
|
|
|
|
|
// Half edge index
|
|
|
|
|
res.edge.indexA = 2 * ei;
|
|
|
|
|
res.edge.indexB = 2 * j;
|
|
|
|
|
res.edge.indexA = edgeIndicesA[ei];
|
|
|
|
|
res.edge.indexB = edgeIndicesB[j];
|
|
|
|
|
|
|
|
|
|
if ( s > speculativeDistance && earlyReturn )
|
|
|
|
|
{
|
|
|
|
|
@ -1868,7 +2056,6 @@ void b3CollideHulls( b3LocalManifold* manifold, int capacity, const b3HullData*
|
|
|
|
|
b3Plane plane = planesA[cache->indexA];
|
|
|
|
|
b3Vec3 searchDirectionInB = b3Neg( b3InvRotateVector( transformBtoA.q, plane.normal ) );
|
|
|
|
|
|
|
|
|
|
// todo use b3GetSupportWide
|
|
|
|
|
int vertexIndex = b3FindHullSupportVertex( hullB, searchDirectionInB );
|
|
|
|
|
b3Vec3 support = b3TransformPoint( transformBtoA, pointsB[vertexIndex] );
|
|
|
|
|
float separation = b3PlaneSeparation( plane, support );
|
|
|
|
|
@ -2116,6 +2303,13 @@ void b3CollideHulls( b3LocalManifold* manifold, int capacity, const b3HullData*
|
|
|
|
|
|
|
|
|
|
b3SeparatingAxis edgeQuery = axisQuery.edge;
|
|
|
|
|
|
|
|
|
|
// If face clipping yields no points then I need to run a full SAT to get the best edge pair.
|
|
|
|
|
if ( manifold->pointCount == 0 &&
|
|
|
|
|
edgeQuery.separation < b3MaxFloat( axisQuery.faceA.separation, axisQuery.faceB.separation ) )
|
|
|
|
|
{
|
|
|
|
|
edgeQuery = b3ComputeSeparatingAxis( hullA, hullB, transformBtoA, false ).edge;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( edgeQuery.indexA == B3_NULL_INDEX )
|
|
|
|
|
{
|
|
|
|
|
// There are no valid edge pairs (all edges parallel)
|
|
|
|
|
|