89static bool PC_process_collision_node(
MeshNode * mn,
PhysicsComponent * pc,
Mesh * m0,
MeshNode * mn0,
BVHNode * node,
CollisionData cd,
mat4 mat,
mat4 mat0,
mat4 mat_inv,
mat4 mat0_inv,
Manifold * manifold);
107static bool PC_traverse_collision_bvh(
MeshNode * mn,
PhysicsComponent * pc,
Mesh * m0,
MeshNode * mn0,
BVHNode * nodes,
CollisionData cd,
mat4 mat,
mat4 mat0,
mat4 mat_inv,
mat4 mat0_inv,
AABB tr_aabb,
Manifold * manifold);
156 static const float MAX_SPEED = 0.02f;
157 static const float ACCEL = 0.01f;
158 static const float GRAVITY = 9.8f;
159 float accel_step = ACCEL *
dt;
161 pc->
vel.
z -= GRAVITY *
dt;
174 int contact_count = 0;
181 float dist_A =
vec3_dot(world_A, hull_normal) - hull_plane_dist;
182 float dist_B =
vec3_dot(world_B, hull_normal) - hull_plane_dist;
184 float pen_A = dist_A - cap->
radius;
186 float pen_B = dist_B - cap->
radius;
193 manifold->
contacts[contact_count].
d = -pen_A;
204 manifold->
contacts[contact_count].
d = -pen_B;
208 manifold->
count = contact_count;
210 return contact_count;
218 size_t vAcnt = a_cd.
data.hull.count;
220 size_t fAcnt = a_cd.
data.hull.face_count;
222 size_t vBcnt = b_cd.
data.hull.count;
224 size_t fBcnt = b_cd.
data.hull.face_count;
230 float maximum_dotA = -INFINITY;
231 size_t largest_indexA = 0;
232 for (
int i = 0; i < vAcnt; i++)
235 if (dot > maximum_dotA)
242 float maximum_face_dotA = -INFINITY;
243 size_t largest_face_indexA = 0;
245 for (
int i = 0; i < fAcnt; i++)
249 for (
int j = 0; j < f->
count; j++)
251 if (f->
indices[j] == largest_indexA)
258 if (!found)
continue;
261 if (dot > maximum_face_dotA)
263 maximum_face_dotA = dot;
264 largest_face_indexA = i;
268 float maximum_dotB = -INFINITY;
269 size_t largest_indexB = 0;
270 for (
int i = 0; i < vBcnt; i++)
273 if (dot > maximum_dotB)
280 float maximum_face_dotB = -INFINITY;
281 size_t largest_face_indexB = 0;
283 for (
int i = 0; i < fBcnt; i++)
287 for (
int j = 0; j < f->
count; j++)
289 if (f->
indices[j] == largest_indexB)
296 if (!found)
continue;
299 if (dot > maximum_face_dotB)
301 maximum_face_dotB = dot;
302 largest_face_indexB = i;
306 HullFace * reference_face = &fA[largest_face_indexA];
307 vec3 * reference_points = vA;
308 HullFace * incident_face = &fB[largest_face_indexB];
309 int reference_idx = largest_face_indexA;
310 int incident_idx = largest_face_indexB;
311 vec3 * incident_points = vB;
312 mat4 * reference_mat = &modelA;
313 mat4 * incident_mat = &modelB;
314 bool flipped =
false;
319 vec3 * tempP = reference_points;
320 mat4 * tempMat = reference_mat;
321 reference_face = incident_face;
322 reference_points = incident_points;
323 reference_mat = incident_mat;
324 incident_face =
temp;
325 incident_points = tempP;
326 incident_mat = tempMat;
327 incident_idx = largest_face_indexA;
328 reference_idx = largest_face_indexB;
351 const int MAX_CLIP_PT = 64;
353 for (
int i = 0; i < incident_face->
count; i++)
360 int incident_count = incident_face->
count;
368 for (
int i = 0; i < reference_face->
count; i++)
381 if (incident_count >= MAX_CLIP_PT)
383 printf(
"INCIDENT CLIP OOB\n");
388 const int MAX_CLIP_AND_CONTACT = 68;
389 float depths[MAX_CLIP_PT];
391 vec3 temp_arr[MAX_CLIP_AND_CONTACT];
392 size_t clip_contact_cnt = 0;
396 m4_inverse((
float *)&inverse_a, (
float*)&modelA);
400 m4_inverse((
float *)&inverse_b, (
float*)&modelB);
403 for (
int i = 0; i < incident_count; i++)
405 if (i >= incident_count)
break;
407 float depth =
vec3_dot(
vec3_sub(ping[i].p, reference_origin), reference_normal);
410 for (
int j = i; j < incident_count-1; j++)
421 clip_contact[clip_contact_cnt].
b =
mat4_mul_point(inverse_b, ping[i].p);
425 clip_contact[clip_contact_cnt].
edge_a = ping[i].
edge0;
426 clip_contact[clip_contact_cnt].
edge_b = ping[i].
edge1;
428 clip_contact[clip_contact_cnt].
normal = p->normal;
429 clip_contact[clip_contact_cnt].
d = -depth;
430 clip_contact[clip_contact_cnt].
pcA = p->pcA;
431 clip_contact[clip_contact_cnt].
pcB = p->pcB;
432 clip_contact[clip_contact_cnt].
mnA = p->mnA;
433 clip_contact[clip_contact_cnt].
mnB = p->mnB;
437 clip_contact[clip_contact_cnt].
tangent = (
vec3){0,0,0};
444 clip_contact[clip_contact_cnt].
a =
mat4_mul_point(inverse_a, ping[i].p);
446 clip_contact[clip_contact_cnt].
normal = p->normal;
449 clip_contact[clip_contact_cnt].
edge_a = ping[i].
edge0;
450 clip_contact[clip_contact_cnt].
edge_b = ping[i].
edge1;
451 clip_contact[clip_contact_cnt].
d = -depth;
452 clip_contact[clip_contact_cnt].
pcA = p->pcA;
453 clip_contact[clip_contact_cnt].
pcB = p->pcB;
454 clip_contact[clip_contact_cnt].
mnA = p->mnA;
455 clip_contact[clip_contact_cnt].
mnB = p->mnB;
459 clip_contact[clip_contact_cnt].
tangent = (
vec3){0,0,0};
466 for (
int i = 0; i < clip_contact_cnt; i++)
476 bool not_found =
false;
478 for (
int i = 0; i < manifold->
count; i++)
482 for (
int j = 0; j < clip_contact_cnt; j++)
511 size_t deepest_index = 0;
512 if (clip_contact_cnt >= 1)
514 float deepest = -INFINITY;
515 for (
int i = 0; i < clip_contact_cnt; i++)
517 if (clip_contact[i].d > deepest)
520 deepest = clip_contact[i].
d;
525 manifold->
contacts[0] = clip_contact[deepest_index];
527 size_t furthest_index_pt = 0;
528 if (clip_contact_cnt >= 2)
530 float furthest = -INFINITY;
532 for (
int i = 0; i < clip_contact_cnt; i++)
534 if (deepest_index == i)
continue;
539 furthest_index_pt = i;
543 manifold->
contacts[1] = clip_contact[furthest_index_pt];
545 size_t furthest_index_seg = 0;
546 if (clip_contact_cnt >= 3)
549 float furthest = -INFINITY;
551 for (
int i = 0; i < clip_contact_cnt; i++)
553 if (deepest_index == i || furthest_index_pt == i)
continue;
559 furthest_index_seg = i;
563 manifold->
contacts[2] = clip_contact[furthest_index_seg];
565 size_t furthest_index_tri = 0;
566 if (clip_contact_cnt >= 4)
569 float furthest = -INFINITY;
571 for (
int i = 0; i < clip_contact_cnt; i++)
573 if (deepest_index == i || furthest_index_pt == i || furthest_index_seg == i)
continue;
579 furthest_index_tri = i;
583 manifold->
contacts[3] = clip_contact[furthest_index_tri];
587 manifold->
count =
MIN(clip_contact_cnt, 4);
601 if ((m->
mnA == mn0 && m->
mnB == mn1) || (m->
mnB == mn0 && m->
mnA == mn1))
638static bool PC_process_collision_node(
MeshNode * mn,
PhysicsComponent * pc,
Mesh * m0,
MeshNode * mn0,
BVHNode * node,
CollisionData cd,
mat4 mat,
mat4 mat0,
mat4 mat_inv,
mat4 mat0_inv,
Manifold * manifold)
645 for (
int k = 0; k < node->
count; k++)
671 cd0.
data.hull.pts = vertices;
672 cd0.
data.hull.count = 3;
673 cd0.
data.hull.mfs = &face;
674 cd0.
data.hull.face_count = 1;
676 if (
GJK(cd, cd0, mat, mat0, mat_inv, mat0_inv, &p,
EW[0]))
717static bool PC_traverse_collision_bvh(
MeshNode * mn,
PhysicsComponent * pc,
Mesh * m0,
MeshNode * mn0,
BVHNode * nodes,
CollisionData cd,
mat4 mat,
mat4 mat0,
mat4 mat_inv,
mat4 mat0_inv,
AABB tr_aabb,
Manifold * manifold)
732 if (node->
left == -1 && node->
right == -1)
734 if (
PC_process_collision_node(mn, pc, m0, mn0, node, cd, mat, mat0, mat_inv, mat0_inv, manifold))
772 if (node->
left == -1 && node->
right == -1)
775 for (
int i = 0; i < node->
count; i++)
780 if ((mn0->
mesh == -1 && mn0->
parent != -1) || mn0->
free)
continue;
806 if (mn0->
mesh == -1)
continue;
818 bool col =
PC_traverse_collision_bvh(mn, pc, m0, mn0, mesh_nodes, cd, mat, mat0, mat_inv, mat0_inv, tr, manifold);
823 if (mn0->
mesh == -1)
continue;
843 if (
GJK(cd, cd0, mat, mat0, mat_inv, mat0_inv, &p,
EW[0]))
885 if (
GJK(cd, cd0, mat, mat0, mat_inv, mat0_inv, &p,
EW[0]))
934 bool col =
PC_traverse_collision_bvh(mn, pc, m0, mn0, mesh_nodes, cd, mat, mat0, mat_inv, mat0_inv, tr, manifold);
955 if (
GJK(cd, cd0, mat, mat0, mat_inv, mat0_inv, &p,
EW[0]))
1109 float IMA = 1.0f / pcA->
mass;
1128 float angularA, angularB;
1139 const float slop = 0.005f;
1140 const float beta = 0.2f;
1142 float bias = fmaxf(p->
d - slop, 0) * beta /
dt;
1144 float K = IMA + angularA;
1145 float j_vel = (-(1 + restitution) * vn) / K;
1146 float j_bias = bias / K;
1160 pcA->
vel.
x += impulse.
x * IMA;
1161 pcA->
vel.
y += impulse.
y * IMA;
1162 pcA->
vel.
z += impulse.
z * IMA;
1180 if (entB->
free)
return;
1188 float IMA = 1.0f / pcA->
mass;
1189 float IMB = 1.0f / pcB->
mass;
1226 float angularA, angularB;
1241 float K = IMA + IMB + angularA + angularB;
1243 const float slop = 0.005f;
1244 const float beta = 0.05f;
1246 float bias = fmaxf(p->
d - slop, 0) * beta /
dt;
1249 float j_bias = bias / K;
1265 pcA->
vel.
x += impulse.
x * IMA;
1266 pcA->
vel.
y += impulse.
y * IMA;
1267 pcA->
vel.
z += impulse.
z * IMA;
1269 pcB->
vel.
x -= impulse.
x * IMB;
1270 pcB->
vel.
y -= impulse.
y * IMB;
1271 pcB->
vel.
z -= impulse.
z * IMB;
1306 float angulartA =
vec3_dot(tangent, ttA);
1312 float angulartB =
vec3_dot(tangent, ttB);
1314 float jt = -
vec3_dot(relative, tangent) / (IMA + IMB + angulartA + angulartB);
1329 pcB->
vel.
x -= FIA.
x * IMB;
1330 pcB->
vel.
y -= FIA.
y * IMB;
1331 pcB->
vel.
z -= FIA.
z * IMB;
1369 if (entA->
free)
return;
1378 float IMA = 1.0f / pcA->
mass;
1408 float angularA, angularB;
1419 const float slop = 0.005f;
1420 const float beta = 0.05f;
1422 float bias = fmaxf(p->
d - slop, 0) * beta /
dt;
1424 float K = IMA + angularA;
1425 float j_vel = (-(1 + restitution) * vn) / K;
1426 float j_bias = bias / K;
1441 pcA->
vel.
x += impulse.
x * IMA;
1442 pcA->
vel.
y += impulse.
y * IMA;
1443 pcA->
vel.
z += impulse.
z * IMA;
1475 float angulartA =
vec3_dot(tangent, ttA);
1477 float jt = -
vec3_dot(relative, tangent) / (IMA + angulartA);
1488 float jtA =
clamp(jt, -max_frictionA, max_frictionA);
1492 pcA->
vel.
x += FIA.
x * IMA;
1493 pcA->
vel.
y += FIA.
y * IMA;
1494 pcA->
vel.
z += FIA.
z * IMA;
1528 if (entA->
free)
return;
1537 if (entB->
free)
return;
1545 float IMA = 1.0f / pcA->
mass;
1546 float IMB = 1.0f / pcB->
mass;
1589 float angularA, angularB;
1604 float K = IMA + IMB + angularA + angularB;
1606 const float slop = 0.005f;
1607 const float beta = 0.05f;
1609 float bias = fmaxf(p->
d - slop, 0) * beta /
dt;
1612 float j_bias = bias / K;
1627 pcA->
vel.
x += impulse.
x * IMA;
1628 pcA->
vel.
y += impulse.
y * IMA;
1629 pcA->
vel.
z += impulse.
z * IMA;
1631 pcB->
vel.
x -= impulse.
x * IMB;
1632 pcB->
vel.
y -= impulse.
y * IMB;
1633 pcB->
vel.
z -= impulse.
z * IMB;
1668 float angulartA =
vec3_dot(tangent, ttA);
1674 float angulartB =
vec3_dot(tangent, ttB);
1676 float jt = -
vec3_dot(relative, tangent) / (IMA + IMB + angulartA + angulartB);
1690 pcA->
vel.
x += FIA.
x * IMA;
1691 pcA->
vel.
y += FIA.
y * IMA;
1692 pcA->
vel.
z += FIA.
z * IMA;
1694 pcB->
vel.
x -= FIA.
x * IMB;
1695 pcB->
vel.
y -= FIA.
y * IMB;
1696 pcB->
vel.
z -= FIA.
z * IMB;
1743 if (ent->
free)
continue;
1758 for (
int j = 0; j < 24; j++)
1802 if (ent->
free)
continue;
1828 for (
int k = 0; k < m->
count; k++)
1852 for (
int j = 0; j < 4; j++)
1859 if(m->
count == 0)
continue;
1861 for (
int k = 0; k < m->
count; k++)
1863 int idx = (seed + k) % m->
count;
1870 if (p->
d < 0.0)
continue;
1964 if (ent->
free)
continue;
1976 int light_count = 0;
1979 Light * l = &lights[j];
1987 lights_in_range[light_count++] = j;
1991 float lowest_dist = INFINITY;
1993 for (
int j = 0; j < light_count; j++)
1995 Light * l = &lights[lights_in_range[j]];
1997 if (dist < lowest_dist)
1999 closest = lights_in_range[j];
2038 for (
int k = 0; k < m->
count; k++)
2053 if (fabsf(p->
normal.
z) < 0.9f)
2062 if (separation > 0.01f || td > 0.01f)
2064 for (
int j = k; j < m->
count-1; j++)
2090 const float rest_eps = 0.1f;
2091 const float rest_ceil = 0.2f;
2093 if (vel_len < rest_ceil && angular_len < rest_ceil)
2104 const int REST_MARGIN = 50;
2125 float mass = pc->
mass;
2127 iia.
a0 = 12.0f / (mass * (h2 + d2));
2131 iia.
b1 = 12.0f / (mass * (w2 + d2));
2135 iia.
c2 = 12.0f / (mass * (w2 + h2));
2166 float mass = 200.0f;
2173 pc->
cd.
type = collision_type;
2174 switch(collision_type)
2189 pc->
cd.
data.capsule.radius = 0.2;
GJK and EPA collision resolution.
vec3 rot(vec3 M[3], vec3 a)
Refer to Ken Perlin's 2 joint IK implmentation.
Camera cam
This is currently the player cam.
bool test_sphere_aabb(vec3 light_pos, float light_radius, vec4 min, vec4 max)
AABBBounds transform_aabb_by_model_matrix(MeshNode mn, mat4 mat)
Engine specific types and defines.
Vector mesh_nodes
MeshNodes.
SceneData scene_data
SceneData that is more-so scene specific.
int mesh_node
The top-most MeshNode that belongs to this Entity.
#define MAX_LIGHTS
Maximum amount of Lights to be pushed per frame (used for SSBO sizing).
Globals GLOBALS
Engine Globals.
bool free
If the Entity is empty.
#define ACCEL_BETA
Friction / air accel decay constant.
Camera * cam
Player Camera.
vec4 cam_pos
The position of the Camera (padded).
Entity structure that holds components and references to the data it owns.
The data for the current scene.
MeshNode * get_root_node(MeshNode *mns, MeshNode *mn)
mat4 compose_trs_from_mesh_node(MeshNode *mn)
Vector hull_faces
HullFaces that are generated after incremental_hull() that combine contiguous triangles into singular...
CollisionData cd
Tagged union for collision options.
vec3 old_vel
Last step's velocity.
Vector vertices
Points that initially copy the Mesh vertices but then are deduplicated and modified in incremental_hu...
mat3 inverse_world
PhysicsComponent.inverse_inertia transformed by rotation into world space for the current step.
int rest_counter
The counter that decreases until at rest.
int count
The amount of valid contacts.
bool processed
Tracks if a Manifold has been processed this frame yet.
bool player_pc
If this is the Player PhysicsComponent.
mat3 inverse_inertia
IIA (currently just a calculated box).
bool free
Tracks if a Manifold can be replaced.
vec3 accel
Acceleration from this step + acceleration from last step * ACCEL_BETA.
vec3 tangent
The tangent used for frictional impulse resolution.
float mass
Mass of the component.
PhysicsType physics_type
Impulse resolution options.
vec3 a
The bottom of the capsule (based on AABB).
AABB aabb
Bounding box of the PC, determined based on Mesh or MeshNode.
vec3 angular_velocity
Rotational velocity.
float deepest
Current deepest contact for a search.
union CollisionData::@341211070342303276310035141141142214214320110321 data
CollisionPoints contacts[4]
The collision contacts.
bool at_rest
If this component is at rest it does not update.
float mu
The friction constant for the component.
float radius
The radius of the capsule.
Entity * ent
Which Entity this component belongs to.
vec3 old_angular
Last step's angular velocity.
vec3 b
The top of the capsule (based on AABB).
vec3 a
Furthest point of A into B.
vec3 center_of_mass
COM based on the AABB.
vec3 normal
The collision normal from B into A.
vec3 b
Furthest point of B into A.
float restitution
The restitution (bounce).
bool PC_traverse_collision_bvh(MeshNode *mn, PhysicsComponent *pc, Mesh *m0, MeshNode *mn0, BVHNode *nodes, CollisionData cd, mat4 mat, mat4 mat0, mat4 mat_inv, mat4 mat0_inv, AABB tr_aabb, Manifold *manifold)
Traverses the BVH for a static MeshNode with a PhysicsComponent to detect collisions.
void PC_find_collision(MeshNode *mn, PhysicsComponent *pc)
Searches for collisions from a PhysicsComponent and determines how based on if its corresponding Mesh...
void search_collisions_from_pc(MeshNode *mn, PhysicsComponent *pc)
Searches for collisions from a PhysicsComponent that has no corresponding Mesh.
void PC_resolve_impulse_static(PhysicsComponent *pcA, CollisionPoints *p)
Solves an impulse for a PhysicsComponent against a static Mesh.
void update_physics_components()
The main PhysicsComponent loop that determines velocity, solves collisions, then integrates position.
void player_resolve_impulse_static(PhysicsComponent *pcA, CollisionPoints *p)
Solves an impulse for a Player PhysicsComponent against a static Mesh.
void PC_apply_velocity(PhysicsComponent *pc, float dt)
Applies gravity to a PhysicsComponent.
Manifold * create_new_manifold(PhysicsComponent *a, int mn0, PhysicsComponent *b, int mn1)
Finds a free Manifold and initializes it between two MeshNodes.
void PC_traverse_scene_bvh(MeshNode *mn, PhysicsComponent *pc, CollisionData cd, SceneData *sd, mat4 mat, mat4 mat_inv, AABB aabb)
Traverses the scene BVH to detect collisions from a PhysicsComponent.
Manifold * find_manifold_for_pair(int mn0, int mn1)
Finds a current Manifold if there is one from MANIFOLDS for a given pair of MeshNodes.
bool GJK(CollisionData a_cd, CollisionData b_cd, mat4 a_mat, mat4 b_mat, mat4 a_inv, mat4 b_inv, CollisionPoints *collision_points, EPAWorkspace *EW)
GJK polytope construction based on A and B (which can be any CollisionType), calls EPA internally.
void init_PC(int mesh_node, PhysicsComponent *pc, AABB ai_aabb, CollisionType collision_type, PhysicsType physics_type)
Initializes a PhysicsComponent.
void clip_manifold(Manifold *manifold, CollisionPoints *p, CollisionData a_cd, mat4 modelA, CollisionData b_cd, mat4 modelB)
Clips a manifold based on two different sets of points and faces with separate transforms.
int generate_capsule_hull_manifold(CapsuleData *cap, mat4 cap_transform, vec3 hull_normal, float hull_plane_dist, Manifold *manifold, PhysicsComponent *pcA, PhysicsComponent *pcB)
Generates a manifold between a capsule and a hull plane.
CollisionType
Defines collision types with different behaviors and mesh setup and validation.
mat3 calc_inverse_inertia(PhysicsComponent *pc)
Calculates the mat3 IIA for a PhysicsComponent, using AABB bounds and mass.
void PC_resolve_impulse(PhysicsComponent *pcA, PhysicsComponent *pcB, CollisionPoints *p)
Solves an impulse for a PhysicsComponent against another.
bool PC_process_collision_node(MeshNode *mn, PhysicsComponent *pc, Mesh *m0, MeshNode *mn0, BVHNode *node, CollisionData cd, mat4 mat, mat4 mat0, mat4 mat_inv, mat4 mat0_inv, Manifold *manifold)
Processes a collision against one BVHNode inside of a COL_TRIANGLE static MeshNode.
void search_collisions_from_hull(MeshNode *mn, PhysicsComponent *pc)
Searches for collisions from a PhysicsComponent that has a corresponding Mesh.
PhysicsType
Defines physics types with different behaviors in impulse resolution.
void player_resolve_impulse(PhysicsComponent *pcA, PhysicsComponent *pcB, CollisionPoints *p)
Solves an impulse for a Player PhysicsComponent against another PhysicsComponent.
@ COL_CAPSULE
A capsule is constructed via AABB dimensions and is used for collision tests.
@ COL_HULL
Incremental hull generates a ConvexHull which is used for collision tests.
@ COL_TRIANGLE
The triangle BVH is generated for this mesh and triangle tests are performed on it.
@ PHYSICS_FULL
All impulse resolution options applied.
The capsule data for collisions.
The tagged union for collision type, stored in PhysicsComponent.
Points that track collision data such as direction, penetration depth, and more to generate Manifolds...
Convex Hulls that are generated via incremental hull for non-static meshes.
Persistent Manifolds that track collisions and how to resolve them.
Entity Component used for physics resolution.
size_t id
The ID inside of Globals.mesh_nodes.
vec3 pos
Position of light.
LightType light_type
The type of Light.
PhysicsComponent * pc
The physics controller initialized based on data from this MeshNode.
size_t local_id
The ID local to the original file structure.
bool sm_dirty
If a point light needs a new shadowmap.
bool free
If the MeshNode can be replaced.
int mesh
The Mesh it references.
int parent
The parent to this node, a global index into Globals.mesh_nodes.
float radius
The radius of the Light.
AABB aabb
The AABB of the MeshNode and its children.
The CPU side structure for Lights.
MeshNodes that describe the position of Meshes, GLTF nodes for GLTFAnimations, or hold references to ...
Important globals for the entire engine and initialization functions that are mainly called on engine...
#define MAX_PHYSICS_COMPONENTS
#define MAX_MANIFOLDS
The maximum amount of Manifolds in MANIFOLDS.
Vector hulls
The ConvexHulls generated if this Mesh is dynamic.
bool static_mesh
This Mesh is static and must create a BVH or if not it must perform incremental_hull.
size_t * bvh_indices
Indices for the BVH, sorted as the BVH is generated.
AABB aabb
The AABB of the mesh.
Vector tris
The MeshFaces.
Vector vertices
The Points.
A Mesh with geometry data that is either initialized as static or dynamic and split into SubMeshes.
PhysicsComponent PHYSICS_COMPONENTS[MAX_PHYSICS_COMPONENTS]
float dt
The 1.0f/60 simulation timestep.
Manifold MANIFOLDS[MAX_MANIFOLDS]
DebugVertex DEBUG_LINES[DEBUG_LINES_MAX]
Player player
The Player data.
vec3 vec3_cross(vec3 a, vec3 b)
float vec3_dot(vec3 a, vec3 b)
vec3 vec3_normalize(vec3 v)
vec3 vec3_scale(vec3 a, float b)
vec3 vec3_sub(vec3 a, vec3 b)
vec3 vec3_add(vec3 a, vec3 b)
vec4 vec4_normalize(vec4 v)
float clamp(float a, float b, float c)
bool m4_inverse(float out[16], const float m[16])
mat4 mat4_inverse(mat4 in)
float vec3_length(vec3 v)
Mesh functions that modify and initialize Mesh data.
int next
The pointer to the next node (either right child or parent's right child) for recursion-less traversa...
AABB aabb
The bounding box of all of this node's children.
Nodes for the acceleration structures of BVHs.
void render_mesh_aabbs_from_root(MeshNode *mn)
Adds Mesh AABBs for each MeshNode child recursively to DEBUG_LINES.
void aabb_to_vertices(DebugVertex *out, AABB *aabb, vec3 offset)
Transfers an AABB to DebufVertex for a wireframe (GL_LINES).
The main render pass, data GPU uploads, and SSBO management.
bool vec3_equal(vec3 a, vec3 b, float eps)
vec3 closest_point_segment(vec3 p, vec3 a, vec3 b)
bool aabbs_intersect(AABB *a, AABB *b)
int clip_pts_against_plane(ClipVertex *in, int in_count, ClipVertex *out, vec3 plane_point, vec3 plane_normal)
vec3 closest_point_triangle(vec3 p, vec3 a, vec3 b, vec3 c)
vec3 mat3_mul_vec3(mat3 m, vec3 v)
void print_aabb(AABB *aabb)
mat3 quat_to_mat3(const vec4 q)
#define CAST_VEC(vec, type)
vec4 quat_mul(vec4 a, vec4 b)
mat4 compose_trs_from_vectors(vec3 pos, vec4 rot, vec3 scale)
mat3 mat3_mul(mat3 M, mat3 N)
vec3 mat4_mul_direction(const mat4 m, vec3 v)
mat3 mat3_transpose(mat3 in)
vec3 mat4_mul_point(mat4 m, vec3 v)
vec3 vec4_to_vec3(vec4 v)
vec4 quat_from_axis_angle(vec3 axis, float angle)