Box3D 0.1.0
A 3D physics engine for games
Loading...
Searching...
No Matches
collision.h
1// SPDX-FileCopyrightText: 2025 Erin Catto
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include "base.h"
7#include "math_functions.h"
8#include "types.h"
9
10#include <stdbool.h>
11#include <stddef.h>
12
17
19B3_API b3DynamicTree b3DynamicTree_Create( int proxyCapacity );
20
23
25B3_API int b3DynamicTree_CreateProxy( b3DynamicTree* tree, b3AABB aabb, uint64_t categoryBits, uint64_t userData );
26
28B3_API void b3DynamicTree_DestroyProxy( b3DynamicTree* tree, int proxyId );
29
31B3_API void b3DynamicTree_MoveProxy( b3DynamicTree* tree, int proxyId, b3AABB aabb );
32
34B3_API void b3DynamicTree_EnlargeProxy( b3DynamicTree* tree, int proxyId, b3AABB aabb );
35
37B3_API void b3DynamicTree_SetCategoryBits( b3DynamicTree* tree, int proxyId, uint64_t categoryBits );
38
40B3_API uint64_t b3DynamicTree_GetCategoryBits( b3DynamicTree* tree, int proxyId );
41
44B3_API b3TreeStats b3DynamicTree_Query( const b3DynamicTree* tree, b3AABB aabb, uint64_t maskBits, bool requireAllBits,
45 b3TreeQueryCallbackFcn* callback, void* context );
46
58B3_API b3TreeStats b3DynamicTree_QueryClosest( const b3DynamicTree* tree, b3Vec3 point, uint64_t maskBits, bool requireAllBits,
59 b3TreeQueryClosestCallbackFcn* callback, void* context, float* minDistanceSqr );
60
75B3_API b3TreeStats b3DynamicTree_RayCast( const b3DynamicTree* tree, const b3RayCastInput* input, uint64_t maskBits,
76 bool requireAllBits, b3TreeRayCastCallbackFcn* callback, void* context );
77
81B3_API b3TreeStats b3DynamicTree_BoxCast( const b3DynamicTree* tree, const b3BoxCastInput* input, uint64_t maskBits,
82 bool requireAllBits, b3TreeBoxCastCallbackFcn* callback, void* context );
83
85B3_API int b3DynamicTree_GetHeight( const b3DynamicTree* tree );
86
88B3_API float b3DynamicTree_GetAreaRatio( const b3DynamicTree* tree );
89
92
95
97B3_API int b3DynamicTree_Rebuild( b3DynamicTree* tree, bool fullBuild );
98
101
103B3_API void b3DynamicTree_Validate( const b3DynamicTree* tree );
104
107
109B3_API void b3DynamicTree_Save( const b3DynamicTree* tree, const char* fileName );
110
112B3_API b3DynamicTree b3DynamicTree_Load( const char* fileName, float scale );
113
115B3_INLINE uint64_t b3DynamicTree_GetUserData( const b3DynamicTree* tree, int proxyId )
116{
117 return tree->nodes[proxyId].userData;
118}
119
121B3_INLINE b3AABB b3DynamicTree_GetAABB( const b3DynamicTree* tree, int proxyId )
122{
123 return tree->nodes[proxyId].aabb;
124}
125 // tree
127
132
134B3_INLINE const b3HullVertex* b3GetHullVertices( const b3HullData* hull )
135{
136 if ( hull->vertexOffset == 0 )
137 {
138 return NULL;
139 }
140
141 return (const b3HullVertex*)( (intptr_t)hull + hull->vertexOffset );
142}
143
145B3_INLINE const b3Vec3* b3GetHullPoints( const b3HullData* hull )
146{
147 if ( hull->pointOffset == 0 )
148 {
149 return NULL;
150 }
151
152 return (const b3Vec3*)( (intptr_t)hull + hull->pointOffset );
153}
154
156B3_INLINE const b3HullHalfEdge* b3GetHullEdges( const b3HullData* hull )
157{
158 if ( hull->edgeOffset == 0 )
159 {
160 return NULL;
161 }
162
163 return (const b3HullHalfEdge*)( (intptr_t)hull + hull->edgeOffset );
164}
165
167B3_INLINE const b3HullFace* b3GetHullFaces( const b3HullData* hull )
168{
169 if ( hull->faceOffset == 0 )
170 {
171 return NULL;
172 }
173
174 return (const b3HullFace*)( (intptr_t)hull + hull->faceOffset );
175}
176
178B3_INLINE const b3Plane* b3GetHullPlanes( const b3HullData* hull )
179{
180 if ( hull->planeOffset == 0 )
181 {
182 return NULL;
183 }
184
185 return (const b3Plane*)( (intptr_t)hull + hull->planeOffset );
186}
187
189B3_API b3HullData* b3CreateCylinder( float height, float radius, float yOffset, int sides );
190
192B3_API b3HullData* b3CreateCone( float height, float radius1, float radius2, int slices );
193
195B3_API b3HullData* b3CreateRock( float radius );
196
198B3_API b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCount );
199
201B3_API b3HullData* b3CloneHull( const b3HullData* hull );
202
204B3_API b3HullData* b3CloneAndTransformHull( const b3HullData* original, b3Transform transform, b3Vec3 scale );
205
207B3_API void b3DestroyHull( b3HullData* hull );
208
210B3_API b3BoxHull b3MakeCubeHull( float halfWidth );
211
213B3_API b3BoxHull b3MakeBoxHull( float hx, float hy, float hz );
214
216B3_API b3BoxHull b3MakeOffsetBoxHull( float hx, float hy, float hz, b3Vec3 offset );
217
221B3_API b3BoxHull b3MakeTransformedBoxHull( float hx, float hy, float hz, b3Transform transform );
222
230B3_API b3BoxHull b3MakeScaledBoxHull( b3Vec3 halfWidths, b3Transform transform, b3Vec3 postScale );
231
239B3_API void b3ScaleBox( b3Vec3* halfWidths, b3Transform* transform, b3Vec3 postScale, float minHalfWidth );
240 // hull
242
247
249B3_INLINE const b3MeshNode* b3GetMeshNodes( const b3MeshData* mesh )
250{
251 if ( mesh->nodeOffset == 0 )
252 {
253 return NULL;
254 }
255
256 return (const b3MeshNode*)( (intptr_t)mesh + mesh->nodeOffset );
257}
258
260B3_INLINE const b3Vec3* b3GetMeshVertices( const b3MeshData* mesh )
261{
262 if ( mesh->vertexOffset == 0 )
263 {
264 return NULL;
265 }
266
267 return (const b3Vec3*)( (intptr_t)mesh + mesh->vertexOffset );
268}
269
271B3_INLINE const b3MeshTriangle* b3GetMeshTriangles( const b3MeshData* mesh )
272{
273 if ( mesh->triangleOffset == 0 )
274 {
275 return NULL;
276 }
277
278 return (const b3MeshTriangle*)( (intptr_t)mesh + mesh->triangleOffset );
279}
280
282B3_INLINE const uint8_t* b3GetMeshMaterialIndices( const b3MeshData* mesh )
283{
284 if ( mesh->materialOffset == 0 )
285 {
286 return NULL;
287 }
288
289 return (const uint8_t*)( (intptr_t)mesh + mesh->materialOffset );
290}
291
293B3_INLINE const uint8_t* b3GetMeshFlags( const b3MeshData* mesh )
294{
295 if ( mesh->flagsOffset == 0 )
296 {
297 return NULL;
298 }
299
300 return (const uint8_t*)( (intptr_t)mesh + mesh->flagsOffset );
301}
302
309B3_API b3MeshData* b3CreateGridMesh( int xCount, int zCount, float cellWidth, int materialCount, bool identifyEdges );
310
312B3_API b3MeshData* b3CreateWaveMesh( int xCount, int zCount, float cellWidth, float amplitude, float rowFrequency,
313 float columnFrequency );
314
316B3_API b3MeshData* b3CreateTorusMesh( int radialResolution, int tubularResolution, float radius, float thickness );
317
319B3_API b3MeshData* b3CreateBoxMesh( b3Vec3 center, b3Vec3 extent, bool identifyEdges );
320
323
325B3_API b3MeshData* b3CreatePlatformMesh( b3Vec3 center, float height, float topWidth, float bottomWidth );
326
328B3_API b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, int degenerateCapacity );
329
331B3_API void b3DestroyMesh( b3MeshData* mesh );
332
334B3_API int b3GetHeight( const b3MeshData* mesh );
335 // mesh
337
342
344B3_INLINE const uint16_t* b3GetHeightFieldCompressedHeights( const b3HeightFieldData* hf )
345{
346 if ( hf->heightsOffset == 0 )
347 {
348 return NULL;
349 }
350
351 return (const uint16_t*)( (intptr_t)hf + hf->heightsOffset );
352}
353
355B3_INLINE const uint8_t* b3GetHeightFieldMaterialIndices( const b3HeightFieldData* hf )
356{
357 if ( hf->materialOffset == 0 )
358 {
359 return NULL;
360 }
361
362 return (const uint8_t*)( (intptr_t)hf + hf->materialOffset );
363}
364
366B3_INLINE const uint8_t* b3GetHeightFieldFlags( const b3HeightFieldData* hf )
367{
368 if ( hf->flagsOffset == 0 )
369 {
370 return NULL;
371 }
372
373 return (const uint8_t*)( (intptr_t)hf + hf->flagsOffset );
374}
375
378
380B3_API b3HeightFieldData* b3CreateGrid( int rowCount, int columnCount, b3Vec3 scale, bool makeHoles );
381
383B3_API b3HeightFieldData* b3CreateWave( int rowCount, int columnCount, b3Vec3 scale, float rowFrequency, float columnFrequency,
384 bool makeHoles );
385
387B3_API void b3DestroyHeightField( b3HeightFieldData* heightField );
388
390B3_API void b3DumpHeightData( const b3HeightFieldDef* data, const char* fileName );
391
393B3_API b3HeightFieldData* b3LoadHeightField( const char* fileName );
394 // height_field
396
401
403B3_API b3ChildShape b3GetCompoundChild( const b3CompoundData* compound, int childIndex );
404
406B3_API void b3QueryCompound( const b3CompoundData* compound, b3AABB aabb, b3CompoundQueryFcn* fcn, void* context );
407
409B3_API b3CompoundCapsule b3GetCompoundCapsule( const b3CompoundData* compound, int index );
410
412B3_API b3CompoundHull b3GetCompoundHull( const b3CompoundData* compound, int index );
413
415B3_API b3CompoundMesh b3GetCompoundMesh( const b3CompoundData* compound, int index );
416
418B3_API b3CompoundSphere b3GetCompoundSphere( const b3CompoundData* compound, int index );
419
422
425
427B3_API void b3DestroyCompound( b3CompoundData* compound );
428
432B3_API uint8_t* b3ConvertCompoundToBytes( b3CompoundData* compound );
433
437B3_API b3CompoundData* b3ConvertBytesToCompound( uint8_t* bytes, int byteCount );
438 // compound
440
445
447B3_API b3MassData b3ComputeSphereMass( const b3Sphere* shape, float density );
448
450B3_API b3MassData b3ComputeCapsuleMass( const b3Capsule* shape, float density );
451
453B3_API b3MassData b3ComputeHullMass( const b3HullData* shape, float density );
454
456B3_API b3AABB b3ComputeSphereAABB( const b3Sphere* shape, b3Transform transform );
457
459B3_API b3AABB b3ComputeCapsuleAABB( const b3Capsule* shape, b3Transform transform );
460
462B3_API b3AABB b3ComputeHullAABB( const b3HullData* shape, b3Transform transform );
463
465B3_API b3AABB b3ComputeMeshAABB( const b3MeshData* shape, b3Transform transform, b3Vec3 scale );
466
469
471B3_API b3AABB b3ComputeCompoundAABB( const b3CompoundData* shape, b3Transform transform );
472 // geometry
474
479
481B3_API bool b3IsValidRay( const b3RayCastInput* input );
482
484B3_API bool b3OverlapCapsule( const b3Capsule* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
485
487B3_API bool b3OverlapCompound( const b3CompoundData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
488
490B3_API bool b3OverlapHeightField( const b3HeightFieldData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
491
493B3_API bool b3OverlapHull( const b3HullData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
494
496B3_API bool b3OverlapMesh( const b3Mesh* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
497
499B3_API bool b3OverlapSphere( const b3Sphere* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
500
503B3_API b3CastOutput b3RayCastSphere( const b3Sphere* shape, const b3RayCastInput* input );
504
507B3_API b3CastOutput b3RayCastHollowSphere( const b3Sphere* shape, const b3RayCastInput* input );
508
511B3_API b3CastOutput b3RayCastCapsule( const b3Capsule* shape, const b3RayCastInput* input );
512
515B3_API b3CastOutput b3RayCastCompound( const b3CompoundData* shape, const b3RayCastInput* input );
516
519B3_API b3CastOutput b3RayCastHull( const b3HullData* shape, const b3RayCastInput* input );
520
522B3_API b3CastOutput b3RayCastMesh( const b3Mesh* shape, const b3RayCastInput* input );
523
526
528B3_API b3CastOutput b3ShapeCastSphere( const b3Sphere* shape, const b3ShapeCastInput* input );
529
531B3_API b3CastOutput b3ShapeCastCapsule( const b3Capsule* shape, const b3ShapeCastInput* input );
532
535
537B3_API b3CastOutput b3ShapeCastHull( const b3HullData* shape, const b3ShapeCastInput* input );
538
540B3_API b3CastOutput b3ShapeCastMesh( const b3Mesh* shape, const b3ShapeCastInput* input );
541
544
546typedef bool b3MeshQueryFcn( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context );
547
553B3_API void b3QueryMesh( const b3Mesh* mesh, const b3AABB bounds, b3MeshQueryFcn* fcn, void* context );
554
560B3_API void b3QueryHeightField( const b3HeightFieldData* heightField, b3AABB bounds, b3MeshQueryFcn* fcn, void* context );
561
567 int simplexCapacity );
568
572
574B3_API b3Transform b3GetSweepTransform( const b3Sweep* sweep, float time );
575
580B3_API b3TOIOutput b3TimeOfImpact( const b3TOIInput* input );
581 // query
583
588
590B3_API void b3CollideSpheres( b3LocalManifold* manifold, int capacity, const b3Sphere* sphereA, const b3Sphere* sphereB,
591 b3Transform transformBtoA );
592
594B3_API void b3CollideCapsuleAndSphere( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA,
595 const b3Sphere* sphereB, b3Transform transformBtoA );
596
598B3_API void b3CollideHullAndSphere( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3Sphere* sphereB,
599 b3Transform transformBtoA, b3SimplexCache* cache );
600
602B3_API void b3CollideCapsules( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA, const b3Capsule* capsuleB,
603 b3Transform transformBtoA );
604
606B3_API void b3CollideHullAndCapsule( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3Capsule* capsuleB,
607 b3Transform transformBtoA, b3SimplexCache* cache );
608
610B3_API void b3CollideHulls( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB,
611 b3Transform transformBtoA, b3SATCache* cache );
612
614B3_API void b3CollideCapsuleAndTriangle( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA,
615 const b3Vec3* triangleB, b3SimplexCache* cache );
616
618B3_API void b3CollideHullAndTriangle( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, b3Vec3 v1, b3Vec3 v2,
619 b3Vec3 v3, int triangleFlags, b3SATCache* cache );
620
622B3_API void b3CollideSphereAndTriangle( b3LocalManifold* manifold, int capacity, const b3Sphere* sphereA,
623 const b3Vec3* triangleB );
624 // collision
626
631
636B3_API b3PlaneSolverResult b3SolvePlanes( b3Vec3 targetDelta, b3CollisionPlane* planes, int count );
637
640B3_API b3Vec3 b3ClipVector( b3Vec3 vector, const b3CollisionPlane* planes, int count );
641 // character
A solid capsule can be viewed as two hemispheres connected by a rectangle.
Definition types.h:1906
b3PlaneSolverResult b3SolvePlanes(b3Vec3 targetDelta, b3CollisionPlane *planes, int count)
Solves the position of a mover that satisfies the given collision planes.
b3Vec3 b3ClipVector(b3Vec3 vector, const b3CollisionPlane *planes, int count)
Clips the velocity against the given collision planes.
These are collision planes that can be fed to b3SolvePlanes.
Definition types.h:1813
Result returned by b3SolvePlanes.
Definition types.h:1830
void b3CollideCapsuleAndTriangle(b3LocalManifold *manifold, int capacity, const b3Capsule *capsuleA, const b3Vec3 *triangleB, b3SimplexCache *cache)
Collide a capsule and a triangle.
void b3CollideSphereAndTriangle(b3LocalManifold *manifold, int capacity, const b3Sphere *sphereA, const b3Vec3 *triangleB)
Collide a sphere and a triangle.
void b3CollideSpheres(b3LocalManifold *manifold, int capacity, const b3Sphere *sphereA, const b3Sphere *sphereB, b3Transform transformBtoA)
Collide two spheres.
void b3CollideHullAndSphere(b3LocalManifold *manifold, int capacity, const b3HullData *hullA, const b3Sphere *sphereB, b3Transform transformBtoA, b3SimplexCache *cache)
Collide a hull and a sphere.
void b3CollideCapsules(b3LocalManifold *manifold, int capacity, const b3Capsule *capsuleA, const b3Capsule *capsuleB, b3Transform transformBtoA)
Collide two capsules.
void b3CollideHulls(b3LocalManifold *manifold, int capacity, const b3HullData *hullA, const b3HullData *hullB, b3Transform transformBtoA, b3SATCache *cache)
Collide two hulls.
void b3CollideCapsuleAndSphere(b3LocalManifold *manifold, int capacity, const b3Capsule *capsuleA, const b3Sphere *sphereB, b3Transform transformBtoA)
Collide a capsule and a sphere.
void b3CollideHullAndTriangle(b3LocalManifold *manifold, int capacity, const b3HullData *hullA, b3Vec3 v1, b3Vec3 v2, b3Vec3 v3, int triangleFlags, b3SATCache *cache)
Collide a hull and a triangle.
void b3CollideHullAndCapsule(b3LocalManifold *manifold, int capacity, const b3HullData *hullA, const b3Capsule *capsuleB, b3Transform transformBtoA, b3SimplexCache *cache)
Collide a hull and a capsule.
A local manifold with no dynamic information. Used by b3Collide functions.
Definition types.h:2707
Separating axis test cache. Provides temporal acceleration of collision routines.
Definition types.h:2654
b3CompoundCapsule b3GetCompoundCapsule(const b3CompoundData *compound, int index)
Access a child capsule by index.
bool b3CompoundQueryFcn(const b3CompoundData *compound, int childIndex, void *context)
Callback for compound overlap queries.
Definition types.h:2541
b3CompoundSphere b3GetCompoundSphere(const b3CompoundData *compound, int index)
Access a child sphere by index.
void b3QueryCompound(const b3CompoundData *compound, b3AABB aabb, b3CompoundQueryFcn *fcn, void *context)
Query a compound shape for children that overlap an AABB.
b3CompoundData * b3ConvertBytesToCompound(uint8_t *bytes, int byteCount)
Convert bytes to compound.
void b3DestroyCompound(b3CompoundData *compound)
Destroy a compound shape.
uint8_t * b3ConvertCompoundToBytes(b3CompoundData *compound)
If bytes is null then this returns the number of required bytes.
const b3SurfaceMaterial * b3GetCompoundMaterials(const b3CompoundData *compound)
Access the compound material array.
b3CompoundHull b3GetCompoundHull(const b3CompoundData *compound, int index)
Access a child hull by index.
b3ChildShape b3GetCompoundChild(const b3CompoundData *compound, int childIndex)
Get a child shape of a compound.
b3CompoundMesh b3GetCompoundMesh(const b3CompoundData *compound, int index)
Access a child mesh by index.
b3CompoundData * b3CreateCompound(const b3CompoundDef *def)
Create a compound shape. All input data in the definition is cloned into the resulting compound.
A capsule that lives in a compound.
Definition types.h:2467
The runtime data for a compound shape.
Definition types.h:2415
Definition for creating a compound shape.
Definition types.h:2376
A hull that lives in a compound.
Definition types.h:2477
A mesh with non-uniform scale that lives in a compound.
Definition types.h:2490
A sphere that lives in a compound.
Definition types.h:2509
b3MassData b3ComputeSphereMass(const b3Sphere *shape, float density)
Compute mass properties of a sphere.
b3MassData b3ComputeHullMass(const b3HullData *shape, float density)
Compute mass properties of a hull.
b3AABB b3ComputeCompoundAABB(const b3CompoundData *shape, b3Transform transform)
Compute the bounding box of a compound.
b3AABB b3ComputeSphereAABB(const b3Sphere *shape, b3Transform transform)
Compute the bounding box of a transformed sphere.
b3AABB b3ComputeHullAABB(const b3HullData *shape, b3Transform transform)
Compute the bounding box of a transformed hull.
b3MassData b3ComputeCapsuleMass(const b3Capsule *shape, float density)
Compute mass properties of a capsule.
b3AABB b3ComputeHeightFieldAABB(const b3HeightFieldData *shape, b3Transform transform)
Compute the bounding box of a transformed height-field.
b3AABB b3ComputeCapsuleAABB(const b3Capsule *shape, b3Transform transform)
Compute the bounding box of a transformed capsule.
b3AABB b3ComputeMeshAABB(const b3MeshData *shape, b3Transform transform, b3Vec3 scale)
Compute the bounding box of a transformed mesh. Scale may be non-uniform and have negative components...
This holds the mass data computed for a shape.
Definition types.h:1868
int flagsOffset
Offset of the flag array in bytes from the struct address.
Definition types.h:2302
int heightsOffset
Offset of the compressed height array in bytes from the struct address.
Definition types.h:2294
int materialOffset
Offset of the material index array in bytes from the struct address.
Definition types.h:2298
void b3DumpHeightData(const b3HeightFieldDef *data, const char *fileName)
Save input height data to a file.
void b3DestroyHeightField(b3HeightFieldData *heightField)
Destroy a height field.
b3HeightFieldData * b3CreateWave(int rowCount, int columnCount, b3Vec3 scale, float rowFrequency, float columnFrequency, bool makeHoles)
Create a wave grid as a height field.
const uint8_t * b3GetHeightFieldFlags(const b3HeightFieldData *hf)
Get read only triangle flags. One uint8_t per triangle.
Definition collision.h:366
const uint16_t * b3GetHeightFieldCompressedHeights(const b3HeightFieldData *hf)
Get read only compressed heights. One uint16_t per grid point.
Definition collision.h:344
const uint8_t * b3GetHeightFieldMaterialIndices(const b3HeightFieldData *hf)
Get read only material indices. One uint8_t per cell.
Definition collision.h:355
b3HeightFieldData * b3CreateHeightField(const b3HeightFieldDef *data)
Create a generic height field.
b3HeightFieldData * b3LoadHeightField(const char *fileName)
Create a height field by loading a previously saved height data.
b3HeightFieldData * b3CreateGrid(int rowCount, int columnCount, b3Vec3 scale, bool makeHoles)
Create a grid as a height field.
A height field with compressed storage.
Definition types.h:2261
Data used to create a height field.
Definition types.h:2219
int planeOffset
Offset of the face plane array in bytes from the struct address.
Definition types.h:2015
int pointOffset
Offset of the point array in bytes from the struct address.
Definition types.h:2000
int faceOffset
Offset of the face array in bytes from the struct address.
Definition types.h:2012
int vertexOffset
Offset of the vertex array in bytes from the struct address.
Definition types.h:1997
int edgeOffset
Offset of the edge array in bytes from the struct address.
Definition types.h:2006
const b3Vec3 * b3GetHullPoints(const b3HullData *hull)
Get read only hull points.
Definition collision.h:145
b3HullData * b3CreateCone(float height, float radius1, float radius2, int slices)
Create a tessellated cone as a hull.
b3HullData * b3CreateRock(float radius)
Create a rock shaped hull.
void b3ScaleBox(b3Vec3 *halfWidths, b3Transform *transform, b3Vec3 postScale, float minHalfWidth)
This takes a box with a transform and post scale and converts it into a box with the post scale resol...
b3HullData * b3CreateCylinder(float height, float radius, float yOffset, int sides)
Create a tessellated cylinder as a hull.
b3HullData * b3CloneHull(const b3HullData *hull)
Deep clone a hull.
b3BoxHull b3MakeScaledBoxHull(b3Vec3 halfWidths, b3Transform transform, b3Vec3 postScale)
This makes a transformed box hull with post scaling.
const b3HullFace * b3GetHullFaces(const b3HullData *hull)
Get read only hull faces.
Definition collision.h:167
const b3HullHalfEdge * b3GetHullEdges(const b3HullData *hull)
Get read only hull half edges.
Definition collision.h:156
const b3HullVertex * b3GetHullVertices(const b3HullData *hull)
Get read only hull vertices.
Definition collision.h:134
b3BoxHull b3MakeOffsetBoxHull(float hx, float hy, float hz, b3Vec3 offset)
Make an offset box as a hull. Do not call b3DestroyHull on this.
b3HullData * b3CreateHull(const b3Vec3 *points, int pointCount, int maxVertexCount)
Create a generic convex hull.
b3BoxHull b3MakeTransformedBoxHull(float hx, float hy, float hz, b3Transform transform)
Make a transformed box as a hull.
void b3DestroyHull(b3HullData *hull)
Destroy a hull.
b3HullData * b3CloneAndTransformHull(const b3HullData *original, b3Transform transform, b3Vec3 scale)
Clone and transform a hull. Supports non-uniform and mirroring scale.
const b3Plane * b3GetHullPlanes(const b3HullData *hull)
Get read only hull planes.
Definition collision.h:178
b3BoxHull b3MakeBoxHull(float hx, float hy, float hz)
Make a box as a hull. Do not call b3DestroyHull on this.
b3BoxHull b3MakeCubeHull(float halfWidth)
Make a cube as a hull. Do not call b3DestroyHull on this.
Efficient box hull.
Definition types.h:2024
A convex hull.
Definition types.h:1965
A hull face.
Definition types.h:1954
Half-edge for hull data structure.
Definition types.h:1937
A hull vertex.
Definition types.h:1928
Axis aligned bounding box.
Definition math_functions.h:105
A plane.
Definition math_functions.h:113
A rigid transform.
Definition math_functions.h:65
A 3D vector.
Definition math_functions.h:41
int materialOffset
Offset of the material array in bytes from the struct address.
Definition types.h:2189
int vertexOffset
Offset of the vertex array in bytes from the struct address.
Definition types.h:2177
int nodeOffset
Offset of the node array in bytes from the struct address.
Definition types.h:2171
int flagsOffset
Offset of the triangle flag array in bytes from the struct address.
Definition types.h:2195
int triangleOffset
Offset of the triangle array in bytes from the struct address.
Definition types.h:2183
b3MeshData * b3CreateBoxMesh(b3Vec3 center, b3Vec3 extent, bool identifyEdges)
Create a box mesh.
const uint8_t * b3GetMeshMaterialIndices(const b3MeshData *mesh)
Get read only mesh materials. The count is equal to the triangle count.
Definition collision.h:282
b3MeshData * b3CreateHollowBoxMesh(b3Vec3 center, b3Vec3 extent)
Create a hollow box mesh.
const b3Vec3 * b3GetMeshVertices(const b3MeshData *mesh)
Get read only mesh vertices.
Definition collision.h:260
void b3DestroyMesh(b3MeshData *mesh)
Destroy a mesh.
const b3MeshTriangle * b3GetMeshTriangles(const b3MeshData *mesh)
Get read only mesh triangles.
Definition collision.h:271
int b3GetHeight(const b3MeshData *mesh)
Get the height of the mesh BVH.
const b3MeshNode * b3GetMeshNodes(const b3MeshData *mesh)
Get read only mesh BVH nodes.
Definition collision.h:249
b3MeshData * b3CreateGridMesh(int xCount, int zCount, float cellWidth, int materialCount, bool identifyEdges)
Create a grid mesh along the x and z axes.
b3MeshData * b3CreateWaveMesh(int xCount, int zCount, float cellWidth, float amplitude, float rowFrequency, float columnFrequency)
Create a wave mesh along the x and z axes.
b3MeshData * b3CreatePlatformMesh(b3Vec3 center, float height, float topWidth, float bottomWidth)
Create a platform mesh. A truncated pyramid.
b3MeshData * b3CreateMesh(const b3MeshDef *def, int *degenerateTriangleIndices, int degenerateCapacity)
Create a generic mesh.
const uint8_t * b3GetMeshFlags(const b3MeshData *mesh)
Get read only mesh flags. The count is equal to the triangle count.
Definition collision.h:293
b3MeshData * b3CreateTorusMesh(int radialResolution, int tubularResolution, float radius, float thickness)
Create a torus mesh.
This allows mesh data to be re-used with different scales.
Definition types.h:2200
This is a sorted triangle collision bounding volume hierarchy.
Definition types.h:2148
This is used to create a re-usable collision mesh.
Definition types.h:2045
A mesh triangle.
Definition types.h:2103
b3CastOutput b3ShapeCastSphere(const b3Sphere *shape, const b3ShapeCastInput *input)
Shape cast versus a sphere. Initial overlap is treated as a miss.
b3CastOutput b3RayCastMesh(const b3Mesh *shape, const b3RayCastInput *input)
Ray cast versus mesh in local space. A thin surface with no interior, so there is no overlap case.
bool b3IsValidRay(const b3RayCastInput *input)
Use this to ensure your ray cast input is valid and avoid internal assertions.
void b3QueryMesh(const b3Mesh *mesh, const b3AABB bounds, b3MeshQueryFcn *fcn, void *context)
Query a mesh for triangles overlapping a bounding box in local space.
b3CastOutput b3ShapeCastCapsule(const b3Capsule *shape, const b3ShapeCastInput *input)
Shape cast versus a capsule. Initial overlap is treated as a miss.
b3CastOutput b3RayCastCompound(const b3CompoundData *shape, const b3RayCastInput *input)
Ray cast versus compound in local space.
bool b3OverlapSphere(const b3Sphere *shape, b3Transform shapeTransform, const b3ShapeProxy *proxy)
Overlap shape versus sphere.
b3CastOutput b3RayCastSphere(const b3Sphere *shape, const b3RayCastInput *input)
Ray cast versus sphere in local space.
bool b3OverlapHeightField(const b3HeightFieldData *shape, b3Transform shapeTransform, const b3ShapeProxy *proxy)
Overlap shape versus height field.
bool b3OverlapCapsule(const b3Capsule *shape, b3Transform shapeTransform, const b3ShapeProxy *proxy)
Overlap shape versus capsule.
b3CastOutput b3RayCastHollowSphere(const b3Sphere *shape, const b3RayCastInput *input)
Ray cast versus a hollow sphere shell in local space.
bool b3OverlapHull(const b3HullData *shape, b3Transform shapeTransform, const b3ShapeProxy *proxy)
Overlap shape versus hull.
b3CastOutput b3RayCastHull(const b3HullData *shape, const b3RayCastInput *input)
Ray cast versus hull shape in local space.
b3CastOutput b3RayCastCapsule(const b3Capsule *shape, const b3RayCastInput *input)
Ray cast versus capsule in local space.
b3Transform b3GetSweepTransform(const b3Sweep *sweep, float time)
Evaluate the transform sweep at a specific time.
bool b3OverlapCompound(const b3CompoundData *shape, b3Transform shapeTransform, const b3ShapeProxy *proxy)
Overlap shape versus compound.
b3CastOutput b3RayCastHeightField(const b3HeightFieldData *shape, const b3RayCastInput *input)
Ray cast versus height field in local space. A thin surface with no interior, so there is no overlap ...
b3CastOutput b3ShapeCastCompound(const b3CompoundData *shape, const b3ShapeCastInput *input)
Shape cast versus compound. Initial overlap is treated as a miss.
b3CastOutput b3ShapeCastMesh(const b3Mesh *shape, const b3ShapeCastInput *input)
Shape cast versus a mesh. Initial overlap is treated as a miss.
b3CastOutput b3ShapeCastHull(const b3HullData *shape, const b3ShapeCastInput *input)
Shape cast versus a hull. Initial overlap is treated as a miss.
bool b3OverlapMesh(const b3Mesh *shape, b3Transform shapeTransform, const b3ShapeProxy *proxy)
Overlap shape versus mesh.
b3CastOutput b3ShapeCast(const b3ShapeCastPairInput *input)
Perform a linear shape cast of shape B moving and shape A fixed.
b3CastOutput b3ShapeCastHeightField(const b3HeightFieldData *shape, const b3ShapeCastInput *input)
Shape cast versus a height field. Initial overlap is treated as a miss.
bool b3MeshQueryFcn(b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void *context)
Query callback.
Definition collision.h:546
b3DistanceOutput b3ShapeDistance(const b3DistanceInput *input, b3SimplexCache *cache, b3Simplex *simplexes, int simplexCapacity)
Compute the closest points between two shapes represented as point clouds.
void b3QueryHeightField(const b3HeightFieldData *heightField, b3AABB bounds, b3MeshQueryFcn *fcn, void *context)
Query a height field for triangles overlapping a bounding box in local space.
b3TOIOutput b3TimeOfImpact(const b3TOIInput *input)
Compute the upper bound on time before two shapes penetrate.
Input for sweeping an AABB through a dynamic tree.
Definition types.h:1392
Low level ray cast or shape-cast output data.
Definition types.h:1405
Input for b3ShapeDistance.
Definition types.h:1535
Output for b3ShapeDistance.
Definition types.h:1552
Low level ray cast input data.
Definition types.h:1309
Low level shape cast input in generic form.
Definition types.h:1374
Input parameters for b3ShapeCast.
Definition types.h:1524
A shape proxy is used by the GJK algorithm. It can represent a convex shape.
Definition types.h:1359
Simplex from the GJK algorithm.
Definition types.h:1574
Used to warm start the GJK simplex.
Definition types.h:1504
This describes the motion of a body/shape for TOI computation.
Definition types.h:1583
Time of impact input.
Definition types.h:1593
Time of impact output.
Definition types.h:1613
Material properties supported per triangle on meshes and height fields.
Definition types.h:399
A solid sphere.
Definition types.h:1887
b3TreeNode * nodes
The tree nodes.
Definition types.h:1726
float b3TreeBoxCastCallbackFcn(const b3BoxCastInput *input, int proxyId, uint64_t userData, void *context)
This function receives clipped AABB cast input for a proxy.
Definition types.h:1782
int b3DynamicTree_Rebuild(b3DynamicTree *tree, bool fullBuild)
Rebuild the tree while retaining subtrees that haven't changed. Returns the number of boxes sorted.
uint64_t b3DynamicTree_GetUserData(const b3DynamicTree *tree, int proxyId)
Get proxy user data.
Definition collision.h:115
float b3DynamicTree_GetAreaRatio(const b3DynamicTree *tree)
Get the ratio of the sum of the node areas to the root area.
void b3DynamicTree_Validate(const b3DynamicTree *tree)
Validate this tree. For testing.
float b3TreeRayCastCallbackFcn(const b3RayCastInput *input, int proxyId, uint64_t userData, void *context)
This function receives clipped ray cast input for a proxy.
Definition types.h:1789
void b3DynamicTree_MoveProxy(b3DynamicTree *tree, int proxyId, b3AABB aabb)
Move a proxy to a new AABB by removing and reinserting into the tree.
b3TreeStats b3DynamicTree_Query(const b3DynamicTree *tree, b3AABB aabb, uint64_t maskBits, bool requireAllBits, b3TreeQueryCallbackFcn *callback, void *context)
Query an AABB for overlapping proxies.
int b3DynamicTree_CreateProxy(b3DynamicTree *tree, b3AABB aabb, uint64_t categoryBits, uint64_t userData)
Create a proxy. Provide an AABB and a userData value.
b3TreeStats b3DynamicTree_BoxCast(const b3DynamicTree *tree, const b3BoxCastInput *input, uint64_t maskBits, bool requireAllBits, b3TreeBoxCastCallbackFcn *callback, void *context)
Sweep an AABB through the tree.
b3TreeStats b3DynamicTree_QueryClosest(const b3DynamicTree *tree, b3Vec3 point, uint64_t maskBits, bool requireAllBits, b3TreeQueryClosestCallbackFcn *callback, void *context, float *minDistanceSqr)
Query an AABB for the closest object.
bool b3TreeQueryCallbackFcn(int proxyId, uint64_t userData, void *context)
This function receives proxies found in the AABB query.
Definition types.h:1771
void b3DynamicTree_SetCategoryBits(b3DynamicTree *tree, int proxyId, uint64_t categoryBits)
Modify the category bits on a proxy. This is an expensive operation.
b3AABB b3DynamicTree_GetAABB(const b3DynamicTree *tree, int proxyId)
Get the AABB of a proxy.
Definition collision.h:121
void b3DynamicTree_ValidateNoEnlarged(const b3DynamicTree *tree)
Validate this tree has no enlarged AABBs. For testing.
void b3DynamicTree_EnlargeProxy(b3DynamicTree *tree, int proxyId, b3AABB aabb)
Enlarge a proxy and enlarge ancestors as necessary.
b3AABB b3DynamicTree_GetRootBounds(const b3DynamicTree *tree)
Get the bounding box that contains the entire tree.
b3DynamicTree b3DynamicTree_Create(int proxyCapacity)
Constructing the tree initializes the node pool.
b3TreeStats b3DynamicTree_RayCast(const b3DynamicTree *tree, const b3RayCastInput *input, uint64_t maskBits, bool requireAllBits, b3TreeRayCastCallbackFcn *callback, void *context)
Ray cast against the proxies in the tree.
uint64_t b3DynamicTree_GetCategoryBits(b3DynamicTree *tree, int proxyId)
Get the category bits on a proxy.
b3DynamicTree b3DynamicTree_Load(const char *fileName, float scale)
Load a file for debugging.
int b3DynamicTree_GetHeight(const b3DynamicTree *tree)
Get the height of the binary tree.
int b3DynamicTree_GetByteCount(const b3DynamicTree *tree)
Get the number of bytes used by this tree.
void b3DynamicTree_DestroyProxy(b3DynamicTree *tree, int proxyId)
Destroy a proxy. This asserts if the id is invalid.
float b3TreeQueryClosestCallbackFcn(float distanceSqrMin, int proxyId, uint64_t userData, void *context)
This function receives the minimum distance squared so far and proxy to check in the closest query.
Definition types.h:1775
int b3DynamicTree_GetProxyCount(const b3DynamicTree *tree)
Get the number of proxies created.
void b3DynamicTree_Destroy(b3DynamicTree *tree)
Destroy the tree, freeing the node pool.
void b3DynamicTree_Save(const b3DynamicTree *tree, const char *fileName)
Save this tree to a file for debugging.
The dynamic tree structure.
Definition types.h:1720
These are performance results returned by dynamic tree queries.
Definition types.h:1761
Child shape of a compound.
Definition types.h:2519
A mesh BVH node.
Definition types.h:2111
b3AABB aabb
The node bounding box.
Definition types.h:1684