SAT samples (#173)
This commit is contained in:
parent
5643cd81ff
commit
9f998c862d
9 changed files with 1282 additions and 890 deletions
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
* @erincatto
|
||||
|
|
@ -201,7 +201,7 @@ B3_INLINE const float* b3GetHullSoaVertices( const b3HullData* hull )
|
|||
|
||||
/// Get read only SOA unit normal vectors. This is an array of normals with all x values,
|
||||
/// y values, and z values as separate arrays. The array lengths are padded to
|
||||
/// a multiple of 4. The padded values are repeats of the first value.
|
||||
/// a multiple of 4. The padded values are 0.
|
||||
B3_INLINE const float* b3GetHullSoaNormals( const b3HullData* hull )
|
||||
{
|
||||
if ( hull->soaNormalOffset == 0 )
|
||||
|
|
@ -221,6 +221,9 @@ B3_API b3HullData* b3CreateCone( float height, float radius1, float radius2, int
|
|||
/// Create a rock shaped hull.
|
||||
B3_API b3HullData* b3CreateRock( float radius );
|
||||
|
||||
// Hull of 32 pseudo random points on a sphere. From the convex pile hull in PEEL.
|
||||
B3_API b3HullData* b3CreateComplexHull( float radius );
|
||||
|
||||
/// Create a generic convex hull. This can fail if B3_MAX_HULL_VERTICES, B3_MAX_HULL_FACES,
|
||||
/// or B3_MAX_HULL_EDGES is exceeded.
|
||||
B3_API b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCount );
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -908,44 +908,10 @@ void GetConvexPileCapacity( b3Capacity* capacity )
|
|||
#ifdef NDEBUG
|
||||
capacity->dynamicShapeCount = 5120;
|
||||
capacity->dynamicBodyCount = 5120;
|
||||
capacity->contactCount = 60 * 1024;
|
||||
capacity->contactCount = 64 * 1024;
|
||||
#endif
|
||||
}
|
||||
|
||||
// PEEL's BasicRandom, kept verbatim so the point set matches the original
|
||||
typedef struct ConvexPileRandom
|
||||
{
|
||||
unsigned int state;
|
||||
} ConvexPileRandom;
|
||||
|
||||
static unsigned int NextConvexPileRandom( ConvexPileRandom* rng )
|
||||
{
|
||||
rng->state = rng->state * 2147001325u + 715136305u;
|
||||
return rng->state;
|
||||
}
|
||||
|
||||
// Float in [-0.5, 0.5]
|
||||
static float ConvexPileRandomFloat( ConvexPileRandom* rng )
|
||||
{
|
||||
return (float)( NextConvexPileRandom( rng ) & 0xffff ) / 65535.0f - 0.5f;
|
||||
}
|
||||
|
||||
// Uniform random direction, rejection sampled inside the unit sphere then pushed to the surface
|
||||
static b3Vec3 UnitRandomPoint( ConvexPileRandom* rng )
|
||||
{
|
||||
b3Vec3 point;
|
||||
float lengthSq;
|
||||
do
|
||||
{
|
||||
point.x = ConvexPileRandomFloat( rng );
|
||||
point.y = ConvexPileRandomFloat( rng );
|
||||
point.z = ConvexPileRandomFloat( rng );
|
||||
lengthSq = b3Dot( point, point );
|
||||
} while ( lengthSq > 0.25f );
|
||||
|
||||
return b3Normalize( point );
|
||||
}
|
||||
|
||||
void CreateConvexPile( b3WorldId worldId )
|
||||
{
|
||||
{
|
||||
|
|
@ -962,19 +928,9 @@ void CreateConvexPile( b3WorldId worldId )
|
|||
int countZ = 8;
|
||||
int layers = BENCHMARK_DEBUG ? 10 : 80;
|
||||
float amplitude = 2.0f;
|
||||
int pointCount = 32;
|
||||
float scatter = 2.0f * amplitude;
|
||||
|
||||
// Hull around random points on a sphere of radius amplitude
|
||||
assert( pointCount <= 64 );
|
||||
b3Vec3 points[64];
|
||||
ConvexPileRandom rng = { 42 };
|
||||
for ( int i = 0; i < pointCount; ++i )
|
||||
{
|
||||
points[i] = b3MulSV( amplitude, UnitRandomPoint( &rng ) );
|
||||
}
|
||||
|
||||
b3HullData* convex = b3CreateHull( points, pointCount, pointCount );
|
||||
b3HullData* convex = b3CreateComplexHull( amplitude );
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
|
|
|
|||
|
|
@ -936,12 +936,6 @@ typedef struct b3Vec2W
|
|||
b3FloatW x, y;
|
||||
} b3Vec2W;
|
||||
|
||||
// Wide vec3
|
||||
typedef struct b3Vec3W
|
||||
{
|
||||
b3FloatW X, Y, Z;
|
||||
} b3Vec3W;
|
||||
|
||||
// Wide quaternion
|
||||
typedef struct b3QuatW
|
||||
{
|
||||
|
|
@ -966,24 +960,6 @@ typedef struct b3Matrix3W
|
|||
b3Vec3W cx, cy, cz;
|
||||
} b3Matrix3W;
|
||||
|
||||
// s * a
|
||||
static inline b3Vec3W b3MulSVW( b3FloatW s, b3Vec3W a )
|
||||
{
|
||||
return (b3Vec3W){ b3MulW( s, a.X ), b3MulW( s, a.Y ), b3MulW( s, a.Z ) };
|
||||
}
|
||||
|
||||
// a - s * b
|
||||
static inline b3Vec3W b3MulSubSVW( b3Vec3W a, b3FloatW s, b3Vec3W b )
|
||||
{
|
||||
return (b3Vec3W){ b3SubW( a.X, b3MulW( s, b.X ) ), b3SubW( a.Y, b3MulW( s, b.Y ) ), b3SubW( a.Z, b3MulW( s, b.Z ) ) };
|
||||
}
|
||||
|
||||
// a + s * b
|
||||
static inline b3Vec3W b3MulAddSVW( b3Vec3W a, b3FloatW s, b3Vec3W b )
|
||||
{
|
||||
return (b3Vec3W){ b3AddW( a.X, b3MulW( s, b.X ) ), b3AddW( a.Y, b3MulW( s, b.Y ) ), b3AddW( a.Z, b3MulW( s, b.Z ) ) };
|
||||
}
|
||||
|
||||
// a + b
|
||||
static inline b3Vec2W b3AddV2W( b3Vec2W a, b3Vec2W b )
|
||||
{
|
||||
|
|
@ -993,26 +969,6 @@ static inline b3Vec2W b3AddV2W( b3Vec2W a, b3Vec2W b )
|
|||
};
|
||||
}
|
||||
|
||||
// a - b
|
||||
static inline b3Vec3W b3SubVW( b3Vec3W a, b3Vec3W b )
|
||||
{
|
||||
return (b3Vec3W){
|
||||
b3SubW( a.X, b.X ),
|
||||
b3SubW( a.Y, b.Y ),
|
||||
b3SubW( a.Z, b.Z ),
|
||||
};
|
||||
}
|
||||
|
||||
// a + b
|
||||
static inline b3Vec3W b3AddVW( b3Vec3W a, b3Vec3W b )
|
||||
{
|
||||
return (b3Vec3W){
|
||||
b3AddW( a.X, b.X ),
|
||||
b3AddW( a.Y, b.Y ),
|
||||
b3AddW( a.Z, b.Z ),
|
||||
};
|
||||
}
|
||||
|
||||
// m * a
|
||||
static inline b3Vec2W b3MulMV2W( b3SymMatrix2W m, b3Vec2W a )
|
||||
{
|
||||
|
|
@ -1060,20 +1016,6 @@ static inline b3Vec3W b3MulAddMVW( b3Vec3W a, b3SymMatrix3W m, b3Vec3W b )
|
|||
return (b3Vec3W){ b3AddW( a.X, c.X ), b3AddW( a.Y, c.Y ), b3AddW( a.Z, c.Z ) };
|
||||
}
|
||||
|
||||
static inline b3FloatW b3DotW( b3Vec3W a, b3Vec3W b )
|
||||
{
|
||||
return b3AddW( b3AddW( b3MulW( a.X, b.X ), b3MulW( a.Y, b.Y ) ), b3MulW( a.Z, b.Z ) );
|
||||
}
|
||||
|
||||
static inline b3Vec3W b3CrossW( b3Vec3W a, b3Vec3W b )
|
||||
{
|
||||
b3Vec3W c;
|
||||
c.X = b3SubW( b3MulW( a.Y, b.Z ), b3MulW( a.Z, b.Y ) );
|
||||
c.Y = b3SubW( b3MulW( a.Z, b.X ), b3MulW( a.X, b.Z ) );
|
||||
c.Z = b3SubW( b3MulW( a.X, b.Y ), b3MulW( a.Y, b.X ) );
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline b3Matrix3W b3MakeMatrixFromQuatW( b3QuatW q )
|
||||
{
|
||||
b3FloatW x2 = b3AddW( q.V.X, q.V.X );
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
45
src/hull.c
45
src/hull.c
|
|
@ -1920,6 +1920,51 @@ b3HullData* b3CreateRock( float radius )
|
|||
return b3CreateHull( points, pointCount, pointCount );
|
||||
}
|
||||
|
||||
// PEEL's BasicRandom. This is just for testing.
|
||||
static uint32_t b3NextComplexHullRandom( uint32_t* state )
|
||||
{
|
||||
*state = *state * 2147001325u + 715136305u;
|
||||
return *state;
|
||||
}
|
||||
|
||||
static float b3ComplexHullRandomFloat( uint32_t* state )
|
||||
{
|
||||
return (float)( b3NextComplexHullRandom( state ) & 0xffff ) / 65535.0f - 0.5f;
|
||||
}
|
||||
|
||||
static b3Vec3 b3ComplexHullRandomDirection( uint32_t* state )
|
||||
{
|
||||
b3Vec3 point;
|
||||
float lengthSquared;
|
||||
do
|
||||
{
|
||||
point.x = b3ComplexHullRandomFloat( state );
|
||||
point.y = b3ComplexHullRandomFloat( state );
|
||||
point.z = b3ComplexHullRandomFloat( state );
|
||||
lengthSquared = b3Dot( point, point );
|
||||
}
|
||||
while ( lengthSquared > 0.25f );
|
||||
|
||||
return b3Normalize( point );
|
||||
}
|
||||
|
||||
b3HullData* b3CreateComplexHull( float radius )
|
||||
{
|
||||
enum
|
||||
{
|
||||
pointCount = 32
|
||||
};
|
||||
|
||||
b3Vec3 points[pointCount];
|
||||
uint32_t state = 42;
|
||||
for ( int i = 0; i < pointCount; ++i )
|
||||
{
|
||||
points[i] = b3MulSV( radius, b3ComplexHullRandomDirection( &state ) );
|
||||
}
|
||||
|
||||
return b3CreateHull( points, pointCount, pointCount );
|
||||
}
|
||||
|
||||
static void b3UpdateHullBounds( b3HullData* hull )
|
||||
{
|
||||
const b3Vec3* points = b3GetHullPoints( hull );
|
||||
|
|
|
|||
100
src/simd.h
100
src/simd.h
|
|
@ -554,11 +554,6 @@ static inline b3FloatW b3BlendW( b3FloatW a, b3FloatW b, b3FloatW mask )
|
|||
return vbslq_f32( mask32, b, a );
|
||||
}
|
||||
|
||||
static inline b3FloatW b3Dot3W( b3FloatW ax, b3FloatW ay, b3FloatW az, b3FloatW bx, b3FloatW by, b3FloatW bz )
|
||||
{
|
||||
return vaddq_f32( vmulq_f32( ax, bx ), vaddq_f32( vmulq_f32( ay, by ), vmulq_f32( az, bz ) ) );
|
||||
}
|
||||
|
||||
static inline b3FloatW b3EmbedIndexW( b3FloatW value, int baseIndex, int bitCount )
|
||||
{
|
||||
uint32_t mask = ( 1u << bitCount ) - 1;
|
||||
|
|
@ -749,11 +744,6 @@ static inline b3FloatW b3BlendW( b3FloatW a, b3FloatW b, b3FloatW mask )
|
|||
return _mm_or_ps( _mm_and_ps( mask, b ), _mm_andnot_ps( mask, a ) );
|
||||
}
|
||||
|
||||
static inline b3FloatW b3Dot3W( b3FloatW ax, b3FloatW ay, b3FloatW az, b3FloatW bx, b3FloatW by, b3FloatW bz )
|
||||
{
|
||||
return _mm_add_ps( _mm_mul_ps( ax, bx ), _mm_add_ps( _mm_mul_ps( ay, by ), _mm_mul_ps( az, bz ) ) );
|
||||
}
|
||||
|
||||
// Replace the low bitCount mantissa bits of each lane with baseIndex + lane. The value must be
|
||||
// positive so the embedded index sorts with the value, and ties fall to the lower index.
|
||||
static inline b3FloatW b3EmbedIndexW( b3FloatW value, int baseIndex, int bitCount )
|
||||
|
|
@ -981,16 +971,6 @@ static inline b3FloatW b3BlendW( b3FloatW a, b3FloatW b, b3FloatW mask )
|
|||
return r;
|
||||
}
|
||||
|
||||
static inline b3FloatW b3Dot3W( b3FloatW ax, b3FloatW ay, b3FloatW az, b3FloatW bx, b3FloatW by, b3FloatW bz )
|
||||
{
|
||||
b3FloatW r;
|
||||
r.x = ax.x * bx.x + ( ay.x * by.x + az.x * bz.x );
|
||||
r.y = ax.y * bx.y + ( ay.y * by.y + az.y * bz.y );
|
||||
r.z = ax.z * bx.z + ( ay.z * by.z + az.z * bz.z );
|
||||
r.w = ax.w * bx.w + ( ay.w * by.w + az.w * bz.w );
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline b3FloatW b3EmbedIndexW( b3FloatW value, int baseIndex, int bitCount )
|
||||
{
|
||||
uint32_t mask = ( 1u << bitCount ) - 1;
|
||||
|
|
@ -1034,6 +1014,86 @@ static inline void b3TransposeW( b3FloatW r0, b3FloatW r1, b3FloatW r2, b3FloatW
|
|||
*c3 = b3UnpackHiW( t2, t3 );
|
||||
}
|
||||
|
||||
// Wide vec3
|
||||
typedef struct b3Vec3W
|
||||
{
|
||||
b3FloatW X, Y, Z;
|
||||
} b3Vec3W;
|
||||
|
||||
static inline b3Vec3W b3LoadVW( const float* x, const float* y, const float* z )
|
||||
{
|
||||
return (b3Vec3W){ b3LoadW( x ), b3LoadW( y ), b3LoadW( z ) };
|
||||
}
|
||||
|
||||
static inline void b3StoreVW( float* x, float* y, float* z, b3Vec3W v )
|
||||
{
|
||||
b3StoreW( x, v.X );
|
||||
b3StoreW( y, v.Y );
|
||||
b3StoreW( z, v.Z );
|
||||
}
|
||||
|
||||
static inline b3Vec3W b3SplatVW( b3Vec3 v )
|
||||
{
|
||||
return (b3Vec3W){ b3SplatW( v.x ), b3SplatW( v.y ), b3SplatW( v.z ) };
|
||||
}
|
||||
|
||||
static inline b3Vec3W b3NegVW( b3Vec3W a )
|
||||
{
|
||||
return (b3Vec3W){ b3NegW( a.X ), b3NegW( a.Y ), b3NegW( a.Z ) };
|
||||
}
|
||||
|
||||
// s * a
|
||||
static inline b3Vec3W b3MulSVW( b3FloatW s, b3Vec3W a )
|
||||
{
|
||||
return (b3Vec3W){ b3MulW( s, a.X ), b3MulW( s, a.Y ), b3MulW( s, a.Z ) };
|
||||
}
|
||||
|
||||
// a - s * b
|
||||
static inline b3Vec3W b3MulSubSVW( b3Vec3W a, b3FloatW s, b3Vec3W b )
|
||||
{
|
||||
return (b3Vec3W){ b3SubW( a.X, b3MulW( s, b.X ) ), b3SubW( a.Y, b3MulW( s, b.Y ) ), b3SubW( a.Z, b3MulW( s, b.Z ) ) };
|
||||
}
|
||||
|
||||
// a + s * b
|
||||
static inline b3Vec3W b3MulAddSVW( b3Vec3W a, b3FloatW s, b3Vec3W b )
|
||||
{
|
||||
return (b3Vec3W){ b3AddW( a.X, b3MulW( s, b.X ) ), b3AddW( a.Y, b3MulW( s, b.Y ) ), b3AddW( a.Z, b3MulW( s, b.Z ) ) };
|
||||
}
|
||||
|
||||
// a - b
|
||||
static inline b3Vec3W b3SubVW( b3Vec3W a, b3Vec3W b )
|
||||
{
|
||||
return (b3Vec3W){
|
||||
b3SubW( a.X, b.X ),
|
||||
b3SubW( a.Y, b.Y ),
|
||||
b3SubW( a.Z, b.Z ),
|
||||
};
|
||||
}
|
||||
|
||||
// a + b
|
||||
static inline b3Vec3W b3AddVW( b3Vec3W a, b3Vec3W b )
|
||||
{
|
||||
return (b3Vec3W){
|
||||
b3AddW( a.X, b.X ),
|
||||
b3AddW( a.Y, b.Y ),
|
||||
b3AddW( a.Z, b.Z ),
|
||||
};
|
||||
}
|
||||
|
||||
static inline b3FloatW b3DotW( b3Vec3W a, b3Vec3W b )
|
||||
{
|
||||
return b3AddW( b3AddW( b3MulW( a.X, b.X ), b3MulW( a.Y, b.Y ) ), b3MulW( a.Z, b.Z ) );
|
||||
}
|
||||
|
||||
static inline b3Vec3W b3CrossW( b3Vec3W a, b3Vec3W b )
|
||||
{
|
||||
b3Vec3W c;
|
||||
c.X = b3SubW( b3MulW( a.Y, b.Z ), b3MulW( a.Z, b.Y ) );
|
||||
c.Y = b3SubW( b3MulW( a.Z, b.X ), b3MulW( a.X, b.Z ) );
|
||||
c.Z = b3SubW( b3MulW( a.X, b.Y ), b3MulW( a.Y, b.X ) );
|
||||
return c;
|
||||
}
|
||||
|
||||
#if defined( B3_SIMD_NEON )
|
||||
|
||||
typedef struct b3AABBV
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#define RAGDOLL_SLEEP_STEP 273
|
||||
#define RAGDOLL_HASH 0x0F4DD1EB
|
||||
#define WAVE_PILE_SLEEP_STEP 314
|
||||
#define WAVE_PILE_HASH 0xD9B88124
|
||||
#define WAVE_PILE_HASH 0x03B509B6
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0x9B96A098
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
|
|
@ -31,8 +31,8 @@
|
|||
#else
|
||||
#define RAGDOLL_SLEEP_STEP 274
|
||||
#define RAGDOLL_HASH 0x773AB8ED
|
||||
#define WAVE_PILE_SLEEP_STEP 330
|
||||
#define WAVE_PILE_HASH 0x205D6055
|
||||
#define WAVE_PILE_SLEEP_STEP 314
|
||||
#define WAVE_PILE_HASH 0x8CB8F656
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0xF1EDEF47
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
|
|
|
|||
Loading…
Reference in a new issue