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 void b3DynamicTree_Validate( const b3DynamicTree* tree );
86
88B3_API int b3DynamicTree_GetHeight( const b3DynamicTree* tree );
89
91B3_API float b3DynamicTree_GetAreaRatio( const b3DynamicTree* tree );
92
95
98
100B3_API int b3DynamicTree_Rebuild( b3DynamicTree* tree, bool fullBuild );
101
104
106B3_API void b3DynamicTree_Validate( const b3DynamicTree* tree );
107
110
112B3_API void b3DynamicTree_Save( const b3DynamicTree* tree, const char* fileName );
113
115B3_API b3DynamicTree b3DynamicTree_Load( const char* fileName, float scale );
116
118B3_INLINE uint64_t b3DynamicTree_GetUserData( const b3DynamicTree* tree, int proxyId )
119{
120 return tree->nodes[proxyId].userData;
121}
122
124B3_INLINE b3AABB b3DynamicTree_GetAABB( const b3DynamicTree* tree, int proxyId )
125{
126 return tree->nodes[proxyId].aabb;
127}
128 // tree
130
135
137B3_INLINE const b3HullVertex* b3GetHullVertices( const b3HullData* hull )
138{
139 if ( hull->vertexOffset == 0 )
140 {
141 return NULL;
142 }
143
144 return (const b3HullVertex*)( (intptr_t)hull + hull->vertexOffset );
145}
146
148B3_INLINE const b3Vec3* b3GetHullPoints( const b3HullData* hull )
149{
150 if ( hull->pointOffset == 0 )
151 {
152 return NULL;
153 }
154
155 return (const b3Vec3*)( (intptr_t)hull + hull->pointOffset );
156}
157
159B3_INLINE const b3HullHalfEdge* b3GetHullEdges( const b3HullData* hull )
160{
161 if ( hull->edgeOffset == 0 )
162 {
163 return NULL;
164 }
165
166 return (const b3HullHalfEdge*)( (intptr_t)hull + hull->edgeOffset );
167}
168
170B3_INLINE const b3HullFace* b3GetHullFaces( const b3HullData* hull )
171{
172 if ( hull->faceOffset == 0 )
173 {
174 return NULL;
175 }
176
177 return (const b3HullFace*)( (intptr_t)hull + hull->faceOffset );
178}
179
181B3_INLINE const b3Plane* b3GetHullPlanes( const b3HullData* hull )
182{
183 if ( hull->planeOffset == 0 )
184 {
185 return NULL;
186 }
187
188 return (const b3Plane*)( (intptr_t)hull + hull->planeOffset );
189}
190
192B3_API b3HullData* b3CreateCylinder( float height, float radius, float yOffset, int sides );
193
195B3_API b3HullData* b3CreateCone( float height, float radius1, float radius2, int slices );
196
198B3_API b3HullData* b3CreateRock( float radius );
199
201B3_API b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCount );
202
204B3_API b3HullData* b3CloneHull( const b3HullData* hull );
205
207B3_API b3HullData* b3CloneAndTransformHull( const b3HullData* original, b3Transform transform, b3Vec3 scale );
208
210B3_API void b3DestroyHull( b3HullData* hull );
211
213B3_API b3BoxHull b3MakeCubeHull( float halfWidth );
214
216B3_API b3BoxHull b3MakeBoxHull( float hx, float hy, float hz );
217
219B3_API b3BoxHull b3MakeOffsetBoxHull( float hx, float hy, float hz, b3Vec3 offset );
220
224B3_API b3BoxHull b3MakeTransformedBoxHull( float hx, float hy, float hz, b3Transform transform );
225
233B3_API b3BoxHull b3MakeScaledBoxHull( b3Vec3 halfWidths, b3Transform transform, b3Vec3 postScale );
234
242B3_API void b3ScaleBox( b3Vec3* halfWidths, b3Transform* transform, b3Vec3 postScale, float minHalfWidth );
243 // hull
245
250
252B3_INLINE const b3MeshNode* b3GetMeshNodes( const b3MeshData* mesh )
253{
254 if ( mesh->nodeOffset == 0 )
255 {
256 return NULL;
257 }
258
259 return (const b3MeshNode*)( (intptr_t)mesh + mesh->nodeOffset );
260}
261
263B3_INLINE const b3Vec3* b3GetMeshVertices( const b3MeshData* mesh )
264{
265 if ( mesh->vertexOffset == 0 )
266 {
267 return NULL;
268 }
269
270 return (const b3Vec3*)( (intptr_t)mesh + mesh->vertexOffset );
271}
272
274B3_INLINE const b3MeshTriangle* b3GetMeshTriangles( const b3MeshData* mesh )
275{
276 if ( mesh->triangleOffset == 0 )
277 {
278 return NULL;
279 }
280
281 return (const b3MeshTriangle*)( (intptr_t)mesh + mesh->triangleOffset );
282}
283
285B3_INLINE const uint8_t* b3GetMeshMaterialIndices( const b3MeshData* mesh )
286{
287 if ( mesh->materialOffset == 0 )
288 {
289 return NULL;
290 }
291
292 return (const uint8_t*)( (intptr_t)mesh + mesh->materialOffset );
293}
294
296B3_INLINE const uint8_t* b3GetMeshFlags( const b3MeshData* mesh )
297{
298 if ( mesh->flagsOffset == 0 )
299 {
300 return NULL;
301 }
302
303 return (const uint8_t*)( (intptr_t)mesh + mesh->flagsOffset );
304}
305
312B3_API b3MeshData* b3CreateGridMesh( int xCount, int zCount, float cellWidth, int materialCount, bool identifyEdges );
313
315B3_API b3MeshData* b3CreateWaveMesh( int xCount, int zCount, float cellWidth, float amplitude, float rowFrequency,
316 float columnFrequency );
317
319B3_API b3MeshData* b3CreateTorusMesh( int radialResolution, int tubularResolution, float radius, float thickness );
320
322B3_API b3MeshData* b3CreateBoxMesh( b3Vec3 center, b3Vec3 extent, bool identifyEdges );
323
326
328B3_API b3MeshData* b3CreatePlatformMesh( b3Vec3 center, float height, float topWidth, float bottomWidth );
329
331B3_API b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, int degenerateCapacity );
332
334B3_API void b3DestroyMesh( b3MeshData* mesh );
335
337B3_API int b3GetHeight( const b3MeshData* mesh );
338 // mesh
340
345
347B3_INLINE const uint16_t* b3GetHeightFieldCompressedHeights( const b3HeightFieldData* hf )
348{
349 if ( hf->heightsOffset == 0 )
350 {
351 return NULL;
352 }
353
354 return (const uint16_t*)( (intptr_t)hf + hf->heightsOffset );
355}
356
358B3_INLINE const uint8_t* b3GetHeightFieldMaterialIndices( const b3HeightFieldData* hf )
359{
360 if ( hf->materialOffset == 0 )
361 {
362 return NULL;
363 }
364
365 return (const uint8_t*)( (intptr_t)hf + hf->materialOffset );
366}
367
369B3_INLINE const uint8_t* b3GetHeightFieldFlags( const b3HeightFieldData* hf )
370{
371 if ( hf->flagsOffset == 0 )
372 {
373 return NULL;
374 }
375
376 return (const uint8_t*)( (intptr_t)hf + hf->flagsOffset );
377}
378
381
383B3_API b3HeightFieldData* b3CreateGrid( int rowCount, int columnCount, b3Vec3 scale, bool makeHoles );
384
386B3_API b3HeightFieldData* b3CreateWave( int rowCount, int columnCount, b3Vec3 scale, float rowFrequency, float columnFrequency,
387 bool makeHoles );
388
390B3_API void b3DestroyHeightField( b3HeightFieldData* heightField );
391
393B3_API void b3DumpHeightData( const b3HeightFieldDef* data, const char* fileName );
394
396B3_API b3HeightFieldData* b3LoadHeightField( const char* fileName );
397 // height_field
399
404
406B3_API b3ChildShape b3GetCompoundChild( const b3CompoundData* compound, int childIndex );
407
409B3_API void b3QueryCompound( const b3CompoundData* compound, b3AABB aabb, b3CompoundQueryFcn* fcn, void* context );
410
412B3_API b3CompoundCapsule b3GetCompoundCapsule( const b3CompoundData* compound, int index );
413
415B3_API b3CompoundHull b3GetCompoundHull( const b3CompoundData* compound, int index );
416
418B3_API b3CompoundMesh b3GetCompoundMesh( const b3CompoundData* compound, int index );
419
421B3_API b3CompoundSphere b3GetCompoundSphere( const b3CompoundData* compound, int index );
422
425
428
430B3_API void b3DestroyCompound( b3CompoundData* compound );
431
435B3_API uint8_t* b3ConvertCompoundToBytes( b3CompoundData* compound );
436
440B3_API b3CompoundData* b3ConvertBytesToCompound( uint8_t* bytes, int byteCount );
441 // compound
443
448
450B3_API b3MassData b3ComputeSphereMass( const b3Sphere* shape, float density );
451
453B3_API b3MassData b3ComputeCapsuleMass( const b3Capsule* shape, float density );
454
456B3_API b3MassData b3ComputeHullMass( const b3HullData* shape, float density );
457
459B3_API b3AABB b3ComputeSphereAABB( const b3Sphere* shape, b3Transform transform );
460
462B3_API b3AABB b3ComputeCapsuleAABB( const b3Capsule* shape, b3Transform transform );
463
465B3_API b3AABB b3ComputeHullAABB( const b3HullData* shape, b3Transform transform );
466
468B3_API b3AABB b3ComputeMeshAABB( const b3MeshData* shape, b3Transform transform, b3Vec3 scale );
469
472
474B3_API b3AABB b3ComputeCompoundAABB( const b3CompoundData* shape, b3Transform transform );
475 // geometry
477
482
484B3_API bool b3IsValidRay( const b3RayCastInput* input );
485
487B3_API bool b3OverlapCapsule( const b3Capsule* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
488
490B3_API bool b3OverlapCompound( const b3CompoundData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
491
493B3_API bool b3OverlapHeightField( const b3HeightFieldData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
494
496B3_API bool b3OverlapHull( const b3HullData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
497
499B3_API bool b3OverlapMesh( const b3Mesh* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
500
502B3_API bool b3OverlapSphere( const b3Sphere* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
503
506B3_API b3CastOutput b3RayCastSphere( const b3Sphere* shape, const b3RayCastInput* input );
507
510B3_API b3CastOutput b3RayCastHollowSphere( const b3Sphere* shape, const b3RayCastInput* input );
511
514B3_API b3CastOutput b3RayCastCapsule( const b3Capsule* shape, const b3RayCastInput* input );
515
518B3_API b3CastOutput b3RayCastCompound( const b3CompoundData* shape, const b3RayCastInput* input );
519
522B3_API b3CastOutput b3RayCastHull( const b3HullData* shape, const b3RayCastInput* input );
523
525B3_API b3CastOutput b3RayCastMesh( const b3Mesh* shape, const b3RayCastInput* input );
526
529
531B3_API b3CastOutput b3ShapeCastSphere( const b3Sphere* shape, const b3ShapeCastInput* input );
532
534B3_API b3CastOutput b3ShapeCastCapsule( const b3Capsule* shape, const b3ShapeCastInput* input );
535
538
540B3_API b3CastOutput b3ShapeCastHull( const b3HullData* shape, const b3ShapeCastInput* input );
541
543B3_API b3CastOutput b3ShapeCastMesh( const b3Mesh* shape, const b3ShapeCastInput* input );
544
547
549typedef bool b3MeshQueryFcn( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context );
550
556B3_API void b3QueryMesh( const b3Mesh* mesh, const b3AABB bounds, b3MeshQueryFcn* fcn, void* context );
557
563B3_API void b3QueryHeightField( const b3HeightFieldData* heightField, b3AABB bounds, b3MeshQueryFcn* fcn, void* context );
564
570 int simplexCapacity );
571
575
577B3_API b3Transform b3GetSweepTransform( const b3Sweep* sweep, float time );
578
583B3_API b3TOIOutput b3TimeOfImpact( const b3TOIInput* input );
584 // query
586
591
593B3_API void b3CollideSpheres( b3LocalManifold* manifold, int capacity, const b3Sphere* sphereA, const b3Sphere* sphereB,
594 b3Transform transformBtoA );
595
597B3_API void b3CollideCapsuleAndSphere( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA,
598 const b3Sphere* sphereB, b3Transform transformBtoA );
599
601B3_API void b3CollideHullAndSphere( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3Sphere* sphereB,
602 b3Transform transformBtoA, b3SimplexCache* cache );
603
605B3_API void b3CollideCapsules( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA, const b3Capsule* capsuleB,
606 b3Transform transformBtoA );
607
609B3_API void b3CollideHullAndCapsule( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3Capsule* capsuleB,
610 b3Transform transformBtoA, b3SimplexCache* cache );
611
613B3_API void b3CollideHulls( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB,
614 b3Transform transformBtoA, b3SATCache* cache );
615
617B3_API void b3CollideCapsuleAndTriangle( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA,
618 const b3Vec3* triangleB, b3SimplexCache* cache );
619
621B3_API void b3CollideHullAndTriangle( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, b3Vec3 v1, b3Vec3 v2,
622 b3Vec3 v3, int triangleFlags, b3SATCache* cache );
623
625B3_API void b3CollideSphereAndTriangle( b3LocalManifold* manifold, int capacity, const b3Sphere* sphereA,
626 const b3Vec3* triangleB );
627 // collision
629
634
639B3_API b3PlaneSolverResult b3SolvePlanes( b3Vec3 targetDelta, b3CollisionPlane* planes, int count );
640
643B3_API b3Vec3 b3ClipVector( b3Vec3 vector, const b3CollisionPlane* planes, int count );
644 // character
A solid capsule can be viewed as two hemispheres connected by a rectangle.
Definition types.h:1905
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:1812
Result returned by b3SolvePlanes.
Definition types.h:1829
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:2706
Separating axis test cache. Provides temporal acceleration of collision routines.
Definition types.h:2653
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:2540
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:2466
The runtime data for a compound shape.
Definition types.h:2414
Definition for creating a compound shape.
Definition types.h:2375
A hull that lives in a compound.
Definition types.h:2476
A mesh with non-uniform scale that lives in a compound.
Definition types.h:2489
A sphere that lives in a compound.
Definition types.h:2508
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:1867
int flagsOffset
Offset of the flag array in bytes from the struct address.
Definition types.h:2301
int heightsOffset
Offset of the compressed height array in bytes from the struct address.
Definition types.h:2293
int materialOffset
Offset of the material index array in bytes from the struct address.
Definition types.h:2297
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:369
const uint16_t * b3GetHeightFieldCompressedHeights(const b3HeightFieldData *hf)
Get read only compressed heights. One uint16_t per grid point.
Definition collision.h:347
const uint8_t * b3GetHeightFieldMaterialIndices(const b3HeightFieldData *hf)
Get read only material indices. One uint8_t per cell.
Definition collision.h:358
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:2260
Data used to create a height field.
Definition types.h:2218
int planeOffset
Offset of the face plane array in bytes from the struct address.
Definition types.h:2014
int pointOffset
Offset of the point array in bytes from the struct address.
Definition types.h:1999
int faceOffset
Offset of the face array in bytes from the struct address.
Definition types.h:2011
int vertexOffset
Offset of the vertex array in bytes from the struct address.
Definition types.h:1996
int edgeOffset
Offset of the edge array in bytes from the struct address.
Definition types.h:2005
const b3Vec3 * b3GetHullPoints(const b3HullData *hull)
Get read only hull points.
Definition collision.h:148
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:170
const b3HullHalfEdge * b3GetHullEdges(const b3HullData *hull)
Get read only hull half edges.
Definition collision.h:159
const b3HullVertex * b3GetHullVertices(const b3HullData *hull)
Get read only hull vertices.
Definition collision.h:137
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:181
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:2023
A convex hull.
Definition types.h:1964
A hull face.
Definition types.h:1953
Half-edge for hull data structure.
Definition types.h:1936
A hull vertex.
Definition types.h:1927
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:2188
int vertexOffset
Offset of the vertex array in bytes from the struct address.
Definition types.h:2176
int nodeOffset
Offset of the node array in bytes from the struct address.
Definition types.h:2170
int flagsOffset
Offset of the triangle flag array in bytes from the struct address.
Definition types.h:2194
int triangleOffset
Offset of the triangle array in bytes from the struct address.
Definition types.h:2182
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:285
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:263
void b3DestroyMesh(b3MeshData *mesh)
Destroy a mesh.
const b3MeshTriangle * b3GetMeshTriangles(const b3MeshData *mesh)
Get read only mesh triangles.
Definition collision.h:274
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:252
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:296
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:2199
This is a sorted triangle collision bounding volume hierarchy.
Definition types.h:2147
This is used to create a re-usable collision mesh.
Definition types.h:2044
A mesh triangle.
Definition types.h:2102
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:549
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:1391
Low level ray cast or shape-cast output data.
Definition types.h:1404
Input for b3ShapeDistance.
Definition types.h:1534
Output for b3ShapeDistance.
Definition types.h:1551
Low level ray cast input data.
Definition types.h:1308
Low level shape cast input in generic form.
Definition types.h:1373
Input parameters for b3ShapeCast.
Definition types.h:1523
A shape proxy is used by the GJK algorithm. It can represent a convex shape.
Definition types.h:1358
Simplex from the GJK algorithm.
Definition types.h:1573
Used to warm start the GJK simplex.
Definition types.h:1503
This describes the motion of a body/shape for TOI computation.
Definition types.h:1582
Time of impact input.
Definition types.h:1592
Time of impact output.
Definition types.h:1612
Material properties supported per triangle on meshes and height fields.
Definition types.h:399
A solid sphere.
Definition types.h:1886
b3TreeNode * nodes
The tree nodes.
Definition types.h:1725
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:1781
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:118
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:1788
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:1770
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:124
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:1774
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:1719
These are performance results returned by dynamic tree queries.
Definition types.h:1760
Child shape of a compound.
Definition types.h:2518
A mesh BVH node.
Definition types.h:2110
b3AABB aabb
The node bounding box.
Definition types.h:1683