LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_collision_detect.c File Reference

Functions

LG_BBox lg_bbox (float min_x, float max_x, float min_y, float max_y, float min_z, float max_z)
 
LG_BBox lg_bbox_from_cuboid (LG_Cuboid *cuboid)
 
LG_Cuboid lg_cuboid_from_bbox (LG_BBox bbox, LG_Color_u c)
 
LG_BBox lg_bbox_from_mesh (LG_Mesh *mesh)
 
LG_BBox lg_bbox_transform (LG_BBox bbox, mat4_t matrix)
 
vec3_t lg_bbox_get_center (LG_BBox *bbox)
 
zboolean lg_bboxes_collide (LG_BBox *bbox1, LG_BBox *bbox2)
 
zboolean lg_bbox_sets_collide (LG_BBox *bbox1[], LG_BBox *bbox2[])
 
Lines3D_VB lg_l3d_vb_from_bbox (LG_BBox bbox, LG_Color_u c)
 
void lg_bbox_info (LG_BBox *bbox)
 
LG_BSphere lg_bsphere (float x_center, float y_center, float z_center, float radius)
 
LG_BSphere lg_bsphere_from_bbox (LG_BBox bbox)
 
LG_BSphere lg_bsphere_from_mesh (LG_Mesh *mesh)
 
zboolean lg_bspheres_collide (LG_BSphere *bsphere1, LG_BSphere *bsphere2)
 
zboolean lg_bsphere_sets_collide (LG_BSphere *bsphere1[], LG_BSphere *bsphere2[])
 
void lg_bsphere_info (LG_BSphere bsphere)
 

Detailed Description

 === 3D collision detection funcs and algos ===

 Using so far:
 - Bounding boxes
 - Bounding spheres

Function Documentation

◆ lg_bbox()

LG_BBox lg_bbox ( float  min_x,
float  max_x,
float  min_y,
float  max_y,
float  min_z,
float  max_z 
)

Create an axis-aligned bounding box (AABB)

Parameters
min_x
max_x;
min_y
max_y
min_z
max_z
Returns
A new axis-aligned LG_BBox

◆ lg_bbox_from_cuboid()

LG_BBox lg_bbox_from_cuboid ( LG_Cuboid cuboid)

Return an axis-aligned bounding box from a cuboid

y ^
|
| v[7]------v[6]
v[3]------v[2] |
| | | |
| | | |
| v[4]---|--v[5]
v[0]------v[1]------>
x
Parameters
cubPointer to a LG_Cuboid
Returns
A new axis-aligned LG_BBox

◆ lg_cuboid_from_bbox()

LG_Cuboid lg_cuboid_from_bbox ( LG_BBox  bbox,
LG_Color_u  c 
)

Return a cuboid from a bounding box and color

y ^
|
| v[7]------v[6]
v[3]------v[2] |
| | | |
| | | |
| v[4]---|--v[5]
v[0]------v[1]------>
x
Parameters
bboxA LG_BBox
cA LG_Color_u
Returns
A new colored LG_Cuboid

◆ lg_bbox_from_mesh()

LG_BBox lg_bbox_from_mesh ( LG_Mesh mesh)

Return bounding box of a mesh

(pretty dumb func, only return mesh->bbox)

Parameters
meshPointer to a LG_Mesh
Returns
A new LG_BBox

◆ lg_bbox_transform()

LG_BBox lg_bbox_transform ( LG_BBox  bbox,
mat4_t  matrix 
)

Transform bounding box with STR matrix - original bounding box is not modified

Parameters
bboxA LG_BBox
matrixA mat4_t matrix
Returns
A new LG_BBox

◆ lg_bbox_get_center()

vec3_t lg_bbox_get_center ( LG_BBox bbox)

Get center of a bounding box

Parameters
bboxPointer to a LG_BBox
Returns
Center of bounding box

◆ lg_bboxes_collide()

zboolean lg_bboxes_collide ( LG_BBox bbox1,
LG_BBox bbox2 
)

Test if 2 axis-aligned bounding boxes collide

Parameters
bbox1Pointer to an axis-aligned LG_BBox
bbox2Pointer to an axis-aligned LG_BBox
Returns
TRUE if the boxes overlap, FALSE otherwise

◆ lg_bbox_sets_collide()

zboolean lg_bbox_sets_collide ( LG_BBox bbox1[],
LG_BBox bbox2[] 
)

Test if 2 axis-aligned bounding box sets collide

Parameters
bbox1Array of pointers to axis-aligned LG_BBox, NULL terminated
bbox2Array of pointers to axis-aligned LG_BBox, NULL terminated
Returns
TRUE if the bbox sets overlap, FALSE otherwise

◆ lg_l3d_vb_from_bbox()

Lines3D_VB lg_l3d_vb_from_bbox ( LG_BBox  bbox,
LG_Color_u  c 
)

Create and fill a Lines3D_VB (line set vertex buffer and num of vertices) from a bounding box

 Draw with glDrawArrays(GL_LINE, 0, LG_CUBOID_LINES_N_VERTICES or n_vertices)
 (if n_vertices > 0)

The vertex buffer is a static one (static array)

y ^
|
| v[7]------v[6]
v[3]------v[2] |
| | | |
| | | |
| v[4]---|--v[5]
v[0]------v[1]------>
x
Parameters
bboxA LG_BBox
cA LG_Color_u
Returns
A new Lines3D_VB - n_vertices set to 0 on error

◆ lg_bbox_info()

void lg_bbox_info ( LG_BBox bbox)

Print out bbox info

Parameters
bboxPointer to a LG_BBox

◆ lg_bsphere()

LG_BSphere lg_bsphere ( float  x_center,
float  y_center,
float  z_center,
float  radius 
)

Create a bounding sphere

Parameters
x_center;
y_center;
z_center;
radius
Returns
A new LG_BSphere

◆ lg_bsphere_from_bbox()

LG_BSphere lg_bsphere_from_bbox ( LG_BBox  bbox)

Compute bounding sphere from bounding box

Parameters
bboxA LG_BBox
Returns
A new LG_BSphere

◆ lg_bsphere_from_mesh()

LG_BSphere lg_bsphere_from_mesh ( LG_Mesh mesh)

Compute bounding sphere of a mesh

Parameters
meshPointer to a LG_Mesh
Returns
A new LG_BSphere

◆ lg_bspheres_collide()

zboolean lg_bspheres_collide ( LG_BSphere bsphere1,
LG_BSphere bsphere2 
)

Test if 2 bounding spheres collide

Parameters
bsphere1Pointer to a LG_BSphere
bsphere2Pointer to a LG_BSphere
Returns
TRUE if the spheres overlap, FALSE otherwise

◆ lg_bsphere_sets_collide()

zboolean lg_bsphere_sets_collide ( LG_BSphere bsphere1[],
LG_BSphere bsphere2[] 
)

Test if 2 bounding sphere sets collide

Parameters
bsphere1Array of pointers to LG_BSphere, NULL terminated
bsphere2Array of pointers to LG_BSphere, NULL terminated
Returns
TRUE if the sphere sets overlap, FALSE otherwise

◆ lg_bsphere_info()

void lg_bsphere_info ( LG_BSphere  bsphere)

Print out bsphere info

Parameters
bsphereA LG_BSphere