7#include "math_functions.h"
120 return tree->
nodes[proxyId].userData;
303 return (
const uint8_t*)( (intptr_t)mesh + mesh->
flagsOffset );
316 float columnFrequency );
354 return (
const uint16_t*)( (intptr_t)hf + hf->
heightsOffset );
376 return (
const uint8_t*)( (intptr_t)hf + hf->
flagsOffset );
570 int simplexCapacity );
626 const b3Vec3* triangleB );
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 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.
Low level ray cast or shape-cast output data.
Definition types.h:1404
Output for b3ShapeDistance.
Definition types.h:1551
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 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