|
Untitled
|
All of the required structures for the Physics system. More...
Data Structures | |
| struct | CollisionPoints |
| Points that track collision data such as direction, penetration depth, and more to generate Manifolds and resolve impulses. More... | |
| struct | Manifold |
| Persistent Manifolds that track collisions and how to resolve them. More... | |
| struct | ConvexHull |
| Convex Hulls that are generated via incremental hull for non-static meshes. More... | |
| struct | TriangleGroup |
| Groups of contiguous triangles with the same plane that are combined via jarvis marching. More... | |
| struct | CapsuleData |
| The capsule data for collisions. More... | |
| struct | HullData |
| Hull data that refers to ConvexHulls of Meshes. More... | |
| struct | CollisionData |
| The tagged union for collision type, stored in PhysicsComponent. More... | |
| union | CollisionData::[union].data |
| struct | PhysicsComponent |
| Entity Component used for physics resolution. More... | |
Macros | |
| #define | MAX_PLAYER_CONTACTS 10 |
| Maximum amount of CollisionPoints to consider per frame. | |
Enumerations | |
| enum | CollisionType { COL_TRIANGLE , COL_HULL , COL_CAPSULE } |
| Defines collision types with different behaviors and mesh setup and validation. More... | |
| enum | PhysicsType { PHYSICS_NONE , PHYSICS_FULL , PHYSICS_NO_ROT , PHYSICS_GRAVITY_ONLY } |
| Defines physics types with different behaviors in impulse resolution. More... | |
Functions | |
| void | EPA_check_face_visibility (vec3 p, EPAWorkspace *EW) |
| Checks what faces are visible from given point (by dotting the normal). | |
| void | EPA_check_horizon_edges (MeshFace *face, EPAWorkspace *EW) |
| Counts edges of each visible face and tests to see if they have matched already within the horizon_edges arraw. | |
| bool | EPA_add_horizon_face_to_hull_faces (size_t p_idx, HorizonEdge e, EPAWorkspace *EW, vec3 center) |
| Adds a horizon face to to the main faces array, while making sure the normal is facing outward. | |
| void | EPA_expand_hull (vec3 p, int index, EPAWorkspace *EW, vec3 centroid) |
| Conducts EPA on a given hull with a support point. | |
| vec3 | support_capsule (CapsuleData *cap, vec3 dir, mat4 inv) |
| The support function for a COL_CAPSULE. | |
| void | support (vec3 *v, size_t *index, vec3 *verts, size_t cnt, mat4 inv, vec3 dir) |
| The support function for a ConvexHull or triangle Mesh. | |
| SupportVertex | support_diff (CollisionData a_cd, CollisionData b_cd, mat4 a_mat, mat4 b_mat, mat4 a_inv, mat4 b_inv, vec3 dir) |
| Finds support points for A and B and then finds the difference. | |
| CollisionPoints | epa (CollisionData a_cd, CollisionData b_cd, mat4 a_mat, mat4 b_mat, mat4 a_inv, mat4 b_inv, Simplex *s, EPAWorkspace *EW) |
| The Expanding Polytope Algorithm - expands a polytope in a loop as it becomes a polyhedron. | |
| void | add_point_to_simplex (Simplex *s, SupportVertex p) |
| Adds a point to the simplex by placing it at the bottom and shifting the other points forward. | |
| void | remove_point_from_simplex (Simplex *s, int i) |
| Adds a point to the simplex by placing it at the bottom and shifting the other points forward. | |
| void | replace_simplex_points (Simplex *s, SupportVertex abcd[4], int count) |
| Replaces Simplex with another array of SupportVertex. | |
| vec3 | find_next_direction (Simplex *sn) |
| Finds next direction in GJK() by pointing away from current points. | |
| 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 | PC_apply_velocity (PhysicsComponent *pc, float dt) |
| Applies gravity to a PhysicsComponent. | |
| 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. | |
| 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. | |
| 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. | |
| Manifold * | create_new_manifold (PhysicsComponent *a, int mn0, PhysicsComponent *b, int mn1) |
| Finds a free Manifold and initializes it between two MeshNodes. | |
| 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. | |
| 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_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. | |
| void | search_collisions_from_pc (MeshNode *mn, PhysicsComponent *pc) |
| Searches for collisions from a PhysicsComponent that has no corresponding Mesh. | |
| void | search_collisions_from_hull (MeshNode *mn, PhysicsComponent *pc) |
| Searches for collisions from a PhysicsComponent that has a corresponding Mesh. | |
| void | PC_find_collision (MeshNode *mn, PhysicsComponent *pc) |
| Searches for collisions from a PhysicsComponent and determines how based on if its corresponding Mesh exists or not. | |
| void | player_resolve_impulse_static (PhysicsComponent *pcA, CollisionPoints *p) |
| Solves an impulse for a Player PhysicsComponent against a static Mesh. | |
| void | player_resolve_impulse (PhysicsComponent *pcA, PhysicsComponent *pcB, CollisionPoints *p) |
| Solves an impulse for a Player PhysicsComponent against another PhysicsComponent. | |
| void | PC_resolve_impulse_static (PhysicsComponent *pcA, CollisionPoints *p) |
| Solves an impulse for a PhysicsComponent against a static Mesh. | |
| void | PC_resolve_impulse (PhysicsComponent *pcA, PhysicsComponent *pcB, CollisionPoints *p) |
| Solves an impulse for a PhysicsComponent against another. | |
| void | update_physics_components () |
| The main PhysicsComponent loop that determines velocity, solves collisions, then integrates position. | |
| mat3 | calc_inverse_inertia (PhysicsComponent *pc) |
| Calculates the mat3 IIA for a PhysicsComponent, using AABB bounds and mass. | |
| void | init_PC (int mesh_node, PhysicsComponent *pc, AABB ai_aabb, CollisionType collision_type, PhysicsType physics_type) |
| Initializes a PhysicsComponent. | |
Variables | |
| float | normal_impulse0 = 0.0f |
| float | normal_impulse1 = 0.0f |
| float | normal_impulse2 = 0.0f |
| float | normal_impulse3 = 0.0f |
| vec3 | torque_sum = (vec3){0,0,0} |
| vec3 | friction_sum = (vec3){0,0,0} |
| vec3 | impulse_sum = (vec3){0,0,0} |
| vec3 | ang_impulse_sum = (vec3){0,0,0} |
All of the required structures for the Physics system.
The structures, functions, constants, and variables within the physics system.
| struct CollisionPoints |
Points that track collision data such as direction, penetration depth, and more to generate Manifolds and resolve impulses.
Definition at line 985 of file engine_types.h.
| Data Fields | ||
|---|---|---|
| vec3 | a | Furthest point of A into B. |
| vec3 | b | Furthest point of B into A. |
| size_t | index_a | |
| size_t | index_b | |
| vec3 | normal | The collision normal from B into A. |
| vec3 | tangent | The tangent used for frictional impulse resolution. |
| float | d | Length of B-A. |
| bool | collision | |
| PhysicsComponent * | pcA | |
| int | mnA | |
| PhysicsComponent * | pcB | |
| int | mnB | |
| int | incident_face | |
| int | reference_face | |
| int | edge_a | |
| int | edge_b | |
| float | normal_impulse | |
| float | bias_impulse | |
| float | tangent_impulse | |
| struct Manifold |
Persistent Manifolds that track collisions and how to resolve them.
Definition at line 1043 of file engine_types.h.
| Data Fields | ||
|---|---|---|
| PhysicsComponent * | a | |
| int | mnA | |
| PhysicsComponent * | b | |
| int | mnB | |
| CollisionPoints | contacts[4] | The collision contacts. |
| int | count | The amount of valid contacts. |
| bool | processed | Tracks if a Manifold has been processed this frame yet. |
| bool | free | Tracks if a Manifold can be replaced. |
| float | deepest | Current deepest contact for a search. |
| struct ConvexHull |
Convex Hulls that are generated via incremental hull for non-static meshes.
Used for collision.
Definition at line 1107 of file engine_types.h.
| Data Fields | ||
|---|---|---|
| Vector | vertices | Points that initially copy the Mesh vertices but then are deduplicated and modified in incremental_hull(). |
| Vector | faces | MeshFaces that initially copy the Mesh faces but then are modified in incremental_hull(). |
| Vector | hull_faces |
HullFaces that are generated after incremental_hull() that combine contiguous triangles into singular faces. Used for manifold clipping. |
| vec3 | centroid | The center of the hull. |
| AABB | aabb | The bounding box of the hull. |
| struct TriangleGroup |
Groups of contiguous triangles with the same plane that are combined via jarvis marching.
Definition at line 1124 of file engine_types.h.
| Data Fields | ||
|---|---|---|
| vec3 | normal | The group's normal. |
| vec3 | ref_point | A point on the plane. |
| Vector | indices | size_t indices of each MeshFace that indexes into ConvexHull.faces. |
| struct CapsuleData |
| struct HullData |
Hull data that refers to ConvexHulls of Meshes.
Populated during traversal and passed into GJK.
Definition at line 2110 of file engine_types.h.
| Data Fields | ||
|---|---|---|
| vec3 * | pts | Points to ConvexHull.vertices. |
| size_t | count | Stored from ConvexHull.vertices.count. |
| HullFace * | mfs | Points to ConvexHull.hull_faces. |
| size_t | face_count | Stored from ConvexHull.hull_faces.count. |
| struct CollisionData |
The tagged union for collision type, stored in PhysicsComponent.
Definition at line 2129 of file engine_types.h.
| Data Fields | ||
|---|---|---|
| CollisionType | type | |
| union | data | |
| union CollisionData::[union].data |
Definition at line 2132 of file engine_types.h.
| Data Fields | ||
|---|---|---|
| HullData | hull | |
| CapsuleData | capsule | |
| struct PhysicsComponent |
Entity Component used for physics resolution.
Definition at line 2150 of file engine_types.h.
| Data Fields | ||
|---|---|---|
| size_t | id | The ID in PHYSICS_COMPONENTS. |
| bool | free | If this is an empty component. |
| bool | player_pc | If this is the Player PhysicsComponent. |
| bool | at_rest | If this component is at rest it does not update. |
| int | rest_counter | The counter that decreases until at rest. |
| float | mass | Mass of the component. |
| float | restitution | The restitution (bounce). |
| float | mu | The friction constant for the component. |
| vec3 | center_of_mass | COM based on the AABB. |
| mat3 | inverse_inertia | IIA (currently just a calculated box). |
| vec3 | vel | Velocity. |
| vec3 | old_vel | Last step's velocity. |
| vec3 | accel | Acceleration from this step + acceleration from last step * ACCEL_BETA. |
| vec3 | angular_velocity | Rotational velocity. |
| vec3 | old_angular | Last step's angular velocity. |
| mat3 | inverse_world | PhysicsComponent.inverse_inertia transformed by rotation into world space for the current step. |
| AABB | aabb | Bounding box of the PC, determined based on Mesh or MeshNode. |
| CollisionData | cd | Tagged union for collision options. |
| PhysicsType | physics_type | Impulse resolution options. |
| Entity * | ent | Which Entity this component belongs to. |
| #define MAX_PLAYER_CONTACTS 10 |
Maximum amount of CollisionPoints to consider per frame.
Definition at line 160 of file engine_types.h.
Referenced by player_find_collision(), and resolve_collisions().
| enum CollisionType |
Defines collision types with different behaviors and mesh setup and validation.
| Enumerator | |
|---|---|
| COL_TRIANGLE | The triangle BVH is generated for this mesh and triangle tests are performed on it. |
| COL_HULL | Incremental hull generates a ConvexHull which is used for collision tests. |
| COL_CAPSULE | A capsule is constructed via AABB dimensions and is used for collision tests. |
Definition at line 2057 of file engine_types.h.
| enum PhysicsType |
Defines physics types with different behaviors in impulse resolution.
Definition at line 2073 of file engine_types.h.
| void EPA_check_face_visibility | ( | vec3 | p, |
| EPAWorkspace * | EW ) |
Checks what faces are visible from given point (by dotting the normal).
\((p - a) \cdot \vec n\)
| p | The point to check. |
| EW | The EPA workspace to store the visible indices into. |
Definition at line 226 of file GJK.c.
References EPA_check_face_visibility(), EW, EPAWorkspace::faces, EPAWorkspace::indices, MeshFace::indices, EPAWorkspace::indices_count, MeshFace::normal, SupportVertex::p, vec3_dot(), vec3_sub(), EPAWorkspace::vertices, EPAWorkspace::visible_faces_count, and EPAWorkspace::visible_faces_indices.
Referenced by EPA_check_face_visibility(), and EPA_expand_hull().
| void EPA_check_horizon_edges | ( | MeshFace * | face, |
| EPAWorkspace * | EW ) |
Counts edges of each visible face and tests to see if they have matched already within the horizon_edges arraw.
| face | The face to add. |
| EW | The EPA workspace to store the visible indices into. |
Definition at line 243 of file GJK.c.
References HorizonEdge::ab, EPA_check_horizon_edges(), EW, EPAWorkspace::horizon_counts, EPAWorkspace::horizon_counts_count, EPAWorkspace::horizon_edges, EPAWorkspace::horizon_edges_count, MeshFace::indices, SupportVertex::p, vec3_equal(), and EPAWorkspace::vertices.
Referenced by EPA_check_horizon_edges(), and EPA_expand_hull().
| bool EPA_add_horizon_face_to_hull_faces | ( | size_t | p_idx, |
| HorizonEdge | e, | ||
| EPAWorkspace * | EW, | ||
| vec3 | center ) |
Adds a horizon face to to the main faces array, while making sure the normal is facing outward.
| p_idx | The original support point index. |
| e | The horizon visible edge to add. |
| EW | The EPA workspace to store the visible indices into. |
| center | The center of the EPA polyhedron. |
Definition at line 283 of file GJK.c.
References A, HorizonEdge::ab, B, C, compute_tri_normal(), EPA_add_horizon_face_to_hull_faces(), EW, EPAWorkspace::faces, EPAWorkspace::faces_count, EPAWorkspace::indices, MeshFace::indices, EPAWorkspace::indices_count, MeshFace::normal, SupportVertex::p, PRINT_VEC3N, vec3_dot(), vec3_length(), vec3_sub(), and EPAWorkspace::vertices.
Referenced by EPA_add_horizon_face_to_hull_faces(), and EPA_expand_hull().
| void EPA_expand_hull | ( | vec3 | p, |
| int | index, | ||
| EPAWorkspace * | EW, | ||
| vec3 | centroid ) |
Conducts EPA on a given hull with a support point.
| p | The support point. |
| index | The index of the support point. |
| EW | The EPA workspace to store the visible indices into. |
| centroid | The center of the polyhedron (hull). |
Definition at line 326 of file GJK.c.
References EPA_add_horizon_face_to_hull_faces(), EPA_check_face_visibility(), EPA_check_horizon_edges(), EPA_expand_hull(), EW, EPAWorkspace::faces, EPAWorkspace::horizon_counts, EPAWorkspace::horizon_counts_count, EPAWorkspace::horizon_edges, EPAWorkspace::horizon_edges_count, EPAWorkspace::indices, EPAWorkspace::indices_count, REMOVE_FROM_ARR, EPAWorkspace::visible_faces_count, and EPAWorkspace::visible_faces_indices.
Referenced by epa(), and EPA_expand_hull().
| vec3 support_capsule | ( | CapsuleData * | cap, |
| vec3 | dir, | ||
| mat4 | inv ) |
The support function for a COL_CAPSULE.
| cap | The CapsuleData inside of CollisionData. |
| dir | The support direction. |
| inv | The inv matrix transform of this collision body. |
Definition at line 376 of file GJK.c.
References CapsuleData::a, CapsuleData::b, mat4_mul_direction(), CapsuleData::radius, support_capsule(), vec3_add(), vec3_dot(), vec3_length(), vec3_normalize(), and vec3_scale().
Referenced by support_capsule(), and support_diff().
The support function for a ConvexHull or triangle Mesh.
\begin{equation*} S_A(v) = \left\lbrace \begin{aligned} \vec d &= \begin{bmatrix}\vec{v_x} \\ \vec{v_y} \\ \vec{v_z} \\ 0\end{bmatrix} \\ \vec d\prime &= Md \\ & \text{arg} \max\limits_{p \in A}(p \cdot d\prime) \end{aligned} \right. \text{Where A is the shape whose points, p, are tested against direction d.} \end{equation*}
| v | The pointer to the resulting support vertex. |
| index | The pointer to the resulting index of the support vertex. |
| verts | The vertices to consider. |
| cnt | The amount of vertices to consider. |
| inv | The inv matrix transform of this collision body. |
| dir | The support direction. |
Definition at line 393 of file GJK.c.
References mat4_mul_direction(), support(), and vec3_dot().
Referenced by epa(), GJK(), support(), and support_diff().
| SupportVertex support_diff | ( | CollisionData | a_cd, |
| CollisionData | b_cd, | ||
| mat4 | a_mat, | ||
| mat4 | b_mat, | ||
| mat4 | a_inv, | ||
| mat4 | b_inv, | ||
| vec3 | dir ) |
Finds support points for A and B and then finds the difference.
\begin{equation*} p = M_a\begin{bmatrix}a_x \\ a_y \\ a_z \\ 1\end{bmatrix} - M_b\begin{bmatrix}b_x \\ b_y \\ b_z \\ 1\end{bmatrix} \end{equation*}
| a_cd | A's CollisionData. |
| b_cd | B's CollisionData. |
| a_mat | A's transform. |
| b_mat | B's transform. |
| a_inv | A's transform. |
| b_inv | B's transform. |
| dir | The support direction. |
Definition at line 418 of file GJK.c.
References SupportVertex::a, SupportVertex::b, COL_CAPSULE, COL_HULL, COL_TRIANGLE, CollisionData::data, SupportVertex::index_a, SupportVertex::index_b, mat4_mul_point(), SupportVertex::p, support(), support_capsule(), support_diff(), CollisionData::type, vec3_scale(), and vec3_sub().
Referenced by epa(), GJK(), and support_diff().
| CollisionPoints epa | ( | CollisionData | a_cd, |
| CollisionData | b_cd, | ||
| mat4 | a_mat, | ||
| mat4 | b_mat, | ||
| mat4 | a_inv, | ||
| mat4 | b_inv, | ||
| Simplex * | s, | ||
| EPAWorkspace * | EW ) |
The Expanding Polytope Algorithm - expands a polytope in a loop as it becomes a polyhedron.
| a_cd | A's CollisionData. |
| b_cd | B's CollisionData. |
| a_mat | A's transform. |
| b_mat | B's transform. |
| a_inv | A's transform. |
| b_inv | B's transform. |
| s | The initial Simplex from GJK(). |
| EW | The EPA workspace to store the visible indices into. |
Definition at line 452 of file GJK.c.
References A, CollisionPoints::a, SupportVertex::a, B, CollisionPoints::b, SupportVertex::b, C, CollisionPoints::collision, compute_3d_barycentric(), compute_tri_normal(), D, CollisionPoints::d, epa(), EPA_expand_hull(), EW, EPAWorkspace::faces, EPAWorkspace::faces_count, EPAWorkspace::horizon_counts_count, EPAWorkspace::horizon_edges_count, EPAWorkspace::indices, MeshFace::indices, EPAWorkspace::indices_count, CollisionPoints::normal, MeshFace::normal, SupportVertex::p, Simplex::points, PRINT_VEC3N, project_point_plane(), support(), support_diff(), vec3_add(), vec3_dot(), vec3_length(), vec3_scale(), vec3_sub(), EPAWorkspace::vertices, EPAWorkspace::vertices_count, EPAWorkspace::visible_faces_count, vec3::x, vec3::y, and vec3::z.
Referenced by add_horizon_face_to_hull_faces(), epa(), and GJK().
| void add_point_to_simplex | ( | Simplex * | s, |
| SupportVertex | p ) |
Adds a point to the simplex by placing it at the bottom and shifting the other points forward.
| s | The current Simplex from GJK(). |
| p | The SupportVertex to add. |
Definition at line 755 of file GJK.c.
References A, add_point_to_simplex(), Simplex::count, and Simplex::points.
Referenced by add_point_to_simplex(), and GJK().
| void remove_point_from_simplex | ( | Simplex * | s, |
| int | i ) |
Adds a point to the simplex by placing it at the bottom and shifting the other points forward.
| s | The current Simplex from GJK(). |
| p | The SupportVertex to add. |
Definition at line 772 of file GJK.c.
References Simplex::count, Simplex::points, and remove_point_from_simplex().
Referenced by find_next_direction(), and remove_point_from_simplex().
| void replace_simplex_points | ( | Simplex * | s, |
| SupportVertex | abcd[4], | ||
| int | count ) |
Replaces Simplex with another array of SupportVertex.
(Used to swap in the final GJK cases.)
| s | The current Simplex from GJK(). |
| abcd | The SupportVertex array that replaces s. |
| count | The amount of abcd points. |
Definition at line 788 of file GJK.c.
References Simplex::count, Simplex::points, and replace_simplex_points().
Referenced by find_next_direction(), and replace_simplex_points().
Finds next direction in GJK() by pointing away from current points.
Case 2: Notate direction vector crossing with safe axis
Remove simplex centroid and d, unneeded
Redundant code here, test and remove
\begin{equation*} \vec v = \begin{cases} -S_a, & \text{if } C = 1\\ \left. \begin{aligned} \mathit{AB} &= S_b - S_a, \\ \mathit{AO} &= -S_a, \\ & \begin{cases} \left. \begin{aligned} & \text{REMOVE}(B) \\ & \mathit{AO} \end{aligned} \right\}, & \text{if } \mathit{AB} \cdot \mathit{AO} \lt 0 \\ \begin{aligned} & (\mathit{AB} \times \mathit{AO}) \times \mathit{AB}, \\ \end{aligned} & \text{otherwise} \\ \end{cases} \end{aligned} \right\}, & \text{if } C = 2 \\ \left. \begin{aligned} \vec{N} &= (S_B - S_a) \times (S_c - S_a) \\ \hat{N} &= \frac{\vec{N}}{||\vec{N}||} \\ \mathit{AB} &= S_b - S_a \\ \mathit{AC} &= S_c - S_a \\ \mathit{AO} &= -S_a \\ \mathit{AB}_p &= \mathit{AB} \times \hat{N} \\ \mathit{AC}_p &= \hat{N} \times \mathit{AC} \\ \mathit{AC}_d &= \mathit{AC}_p \cdot \mathit{AO} \\ & \left. \begin{aligned} & \begin{cases} & \left. \begin{aligned} & \text{REMOVE}(B) \\ & (\mathit{AC} \times \mathit{AO}) \times \mathit{AC} \\ \end{aligned} \right\}, & \text{if } \mathit{AC} \cdot \mathit{AO} \gt 0 \\ & (\mathit{AB} \times \mathit{AO}) \times \mathit{AB}, & \text{otherwise} \\ \end{cases} \\ \end{aligned} \right\}, & \text{if } \mathit{AC}_d \gt 0 \\ \mathit{AB}_d &= \mathit{AB}_p \cdot \mathit{AO} \\ &\left. \begin{aligned} & \text{REMOVE}(S_c) \\ & (\mathit{AB} \times \mathit{AO}) \times \mathit{AB} \\ \end{aligned} \right\}, & \text{if } \mathit{AB}_d \gt 0 \text{ and } \mathit{AB} \cdot \mathit{AO} \gt 0 \\ & \left\lbrace \begin{aligned} & \hat{N}, & \text{if } \hat{N} \cdot \mathit{AO} \gt 0 \\ & \left. \begin{aligned} & (S_c, S_b) \mapsto (S_b, S_c) \\ & -\hat{N} \\ \end{aligned} \right\}, & \text{otherwise} \\ \end{aligned} \right. \\ \end{aligned} \right\}, & \text{if } C = 3 \\ \left. \begin{aligned} \mathit{AO} &= -S_a \\ \mathit{ABC} &= (S_b - S_a) \times (S_c - S_a) \\ &\left. \begin{aligned} & \text{REMOVE}(D) \\ & \mathit{ABC} \end{aligned} \right\}, & \text{if } \mathit{ABC} \cdot \mathit{AO} \gt 0 \\ \mathit{ACD} &= (S_c - S_a) \times (S_d - S_a) \\ &\left. \begin{aligned} & \text{REMOVE}(B) \\ & \mathit{ACD} \end{aligned} \right\}, & \text{if } \mathit{ACD} \cdot \mathit{AO} \gt 0 \\ \mathit{ADB} &= (S_d - S_a) \times (S_b - S_a) \\ &\left. \begin{aligned} & (S_b, S_c) \mapsto (S_d, S_b) \\ & C = C - 1 \\ & \mathit{ADB} \\ \end{aligned} \right\}, & \text{if } \mathit{ADB} \cdot \mathit{AO} \gt 0 \\ \end{aligned} \right\}, & \text{if } C = 4 \\ \end{cases} \\ \begin{aligned} \vec{v} &= \vec v_\perp, & \text{if } \vec{v} \text{ has not been assigned.} \\ & \text{Where } v_\perp \text{ is the sentinel value that signals a complete simplex.} \\ \end{aligned} \end{equation*}
Definition at line 799 of file GJK.c.
References A, B, C, Simplex::centroid, compute_tri_normal(), Simplex::count, D, find_next_direction(), SupportVertex::p, Simplex::points, remove_point_from_simplex(), replace_simplex_points(), vec3_add(), vec3_cross(), vec3_dot(), vec3_length(), vec3_scale(), vec3_sub(), vec3::x, vec3::y, and vec3::z.
Referenced by find_next_direction(), and GJK().
| 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.
\begin{align} v &= \begin{bmatrix} 0 \\ 0\\ 1 \end{bmatrix}\\ c &= 0 \\ & \text{while } c = 0 \text{:} \\
& \quad p = S(A, B) \\ & \quad c = \text{DNE}, & \text{if } p \cdot v \leq 0 \text{ or } p \in s.\\ & \quad s \Vert p \\ & \quad v = D(s, v) \\ & \quad c = 1, & \text{if } v = v_\perp \\ \end{align} \(\text{Where } c \text{ is the collision status and s is the simplex.}\)
| a_cd | CollisionData for A. |
| b_cd | CollisionData for B. |
| a_mat | Transformation for A. |
| b_mat | Transformation for B. |
| a_inv | Inverse transformation for A. |
| b_inv | Inverse transformation for B. |
| collision_points | Pointer to the outgoing collision data. |
| EW | The workspace to conduct EPA in. |
Definition at line 1052 of file GJK.c.
References add_point_to_simplex(), collision(), CollisionPoints::collision, Simplex::count, CollisionPoints::d, epa(), EW, find_next_direction(), GJK(), CollisionPoints::normal_impulse, SupportVertex::p, Simplex::points, support(), support_diff(), CollisionPoints::tangent_impulse, vec3_dot(), vec3_equal(), vec3::x, vec3::y, and vec3::z.
Referenced by GJK(), PC_process_collision_node(), PC_traverse_scene_bvh(), and player_find_collision().
| void PC_apply_velocity | ( | PhysicsComponent * | pc, |
| float | dt ) |
Applies gravity to a PhysicsComponent.
| pc | The PhysicsComponent to modify. |
| dt | The physics timestep. |
Definition at line 148 of file physics.c.
References PhysicsComponent::angular_velocity, dt, PC_apply_velocity(), vec3_scale(), PhysicsComponent::vel, vec3::x, vec3::y, and vec3::z.
Referenced by PC_apply_velocity(), and update_physics_components().
| 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.
Definition at line 172 of file physics.c.
References CapsuleData::a, CollisionPoints::a, CapsuleData::b, CollisionPoints::b, Manifold::contacts, Manifold::count, CollisionPoints::d, generate_capsule_hull_manifold(), mat4_mul_point(), CollisionPoints::normal, CollisionPoints::pcA, CollisionPoints::pcB, CapsuleData::radius, vec3_dot(), vec3_scale(), and vec3_sub().
Referenced by generate_capsule_hull_manifold().
| 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.
| manifold | The pointer to the current or new Manifold. |
| p | The incoming collision data. |
| a_cd | CollisionData for A. |
| modelA | Transformation matrix for A. |
| b_cd | CollisionData for B. |
| modelB | Transformation matrix for B. |
Definition at line 213 of file physics.c.
References A, CollisionPoints::a, B, CollisionPoints::b, CollisionPoints::bias_impulse, clip_manifold(), clip_pts_against_plane(), closest_point_segment(), closest_point_triangle(), DebugVertex::color, Manifold::contacts, HullFace::count, Manifold::count, CollisionPoints::d, CollisionData::data, DEBUG_LINE_COUNT, DEBUG_LINES, ClipVertex::edge0, ClipVertex::edge1, CollisionPoints::edge_a, CollisionPoints::edge_b, CollisionPoints::incident_face, HullFace::indices, m4_inverse(), mat4_inverse(), mat4_mul_direction(), mat4_mul_point(), MIN, CollisionPoints::mnA, CollisionPoints::mnB, n, CollisionPoints::normal, HullFace::normal, CollisionPoints::normal_impulse, ClipVertex::p, CollisionPoints::pcA, CollisionPoints::pcB, DebugVertex::pos, Manifold::processed, CollisionPoints::reference_face, CollisionPoints::tangent, CollisionPoints::tangent_impulse, temp, vec3_cross(), vec3_dot(), vec3_equal(), vec3_scale(), and vec3_sub().
Referenced by clip_manifold(), PC_process_collision_node(), and PC_traverse_scene_bvh().
| 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.
Definition at line 594 of file physics.c.
References find_manifold_for_pair(), MANIFOLDS, MAX_MANIFOLDS, Manifold::mnA, and Manifold::mnB.
Referenced by find_manifold_for_pair(), PC_process_collision_node(), and PC_traverse_scene_bvh().
| Manifold * create_new_manifold | ( | PhysicsComponent * | a, |
| int | mn0, | ||
| PhysicsComponent * | b, | ||
| int | mn1 ) |
Finds a free Manifold and initializes it between two MeshNodes.
| a | The PhysicsComponent for A, if there is one. |
| mn0 | The MeshNode for A, if there is one. |
| b | The PhysicsComponent for B, if there is one. |
| mn1 | The MeshNode for B, if there is one. |
Definition at line 611 of file physics.c.
References Manifold::a, PhysicsComponent::at_rest, Manifold::b, Manifold::count, create_new_manifold(), Manifold::deepest, Manifold::free, MANIFOLDS, MAX_MANIFOLDS, Manifold::mnA, Manifold::mnB, and Manifold::processed.
Referenced by create_new_manifold(), PC_process_collision_node(), and PC_traverse_scene_bvh().
| 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.
| mn | The MeshNode that is colliding against the static MeshNode. |
| pc | The PhysicsComponent that is colliding against the static MeshNode. |
| m0 | The static MeshNodes Mesh. |
| mn0 | The static MeshNode. |
| node | The current BVHNode. |
| cd | The colliding shape's CollisionData. |
| mat | The colliding shape's transformation matrix. |
| mat0 | The static shape's transformation matrix. |
| mat_inv | The colliding shape's inverse transformation matrix. |
| mat0_inv | The static shape's inverse transformation matrix. |
| manifold | The pair's Manifold. |
Definition at line 638 of file physics.c.
References A, B, Mesh::bvh_indices, C, CAST_VEC, clip_manifold(), COL_CAPSULE, COL_TRIANGLE, CollisionPoints::collision, Manifold::contacts, BVHNode::count, HullFace::count, Manifold::count, create_new_manifold(), CollisionPoints::d, CollisionData::data, Manifold::deepest, EW, find_manifold_for_pair(), BVHNode::first_index, GJK(), MeshNode::global_matrix, MeshNode::id, HullFace::indices, MeshFace::indices, CollisionPoints::mnA, CollisionPoints::mnB, CollisionPoints::normal, HullFace::normal, MeshFace::normal, CollisionPoints::normal_impulse, PC_process_collision_node(), CollisionPoints::pcA, CollisionPoints::pcB, Point::pos, Manifold::processed, CollisionPoints::tangent_impulse, Mesh::tris, CollisionData::type, and Mesh::vertices.
Referenced by PC_process_collision_node(), and PC_traverse_collision_bvh().
| 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.
| mn | The MeshNode that is detecting against the static MeshNode. |
| pc | The PhysicsComponent that is detecting against the static MeshNode. |
| m0 | The static MeshNodes Mesh. |
| mn0 | The static MeshNode. |
| nodes | The BVHNodes of the static MeshNode. |
| cd | The detecting shape's CollisionData. |
| mat | The detecting shape's transformation matrix. |
| mat0 | The static shape's transformation matrix. |
| mat_inv | The detecting shape's inverse transformation matrix. |
| mat0_inv | The static shape's inverse transformation matrix. |
| tr_aabb | The world space AABB of the detecting shape to test against BVHNodes. |
| manifold | The pair's Manifold. |
Definition at line 717 of file physics.c.
References BVHNode::aabb, aabbs_intersect(), BVHNode::left, BVHNode::next, PC_process_collision_node(), PC_traverse_collision_bvh(), and BVHNode::right.
Referenced by PC_traverse_collision_bvh(), and PC_traverse_scene_bvh().
| 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.
| mn | The MeshNode that is detecting. |
| pc | The PhysicsComponent that is detecting. |
| cd | The detecting shape's CollisionData. |
| sd | The SceneData that contains the BVH. |
| mat | The detecting shape's transformation matrix. |
| mat_inv | The detecting shape's inverse transformation matrix. |
| aabb | The local space AABB of the detecting shape to test against BVHNodes. |
Definition at line 752 of file physics.c.
References BVHNode::aabb, aabbs_intersect(), CollisionPoints::bias_impulse, Vector::buffer, SceneData::bvh_indices, SceneData::bvh_nodes, CAST_VEC, PhysicsComponent::cd, clip_manifold(), COL_CAPSULE, COL_HULL, COL_TRIANGLE, CollisionPoints::collision, Manifold::contacts, BVHNode::count, Manifold::count, Vector::count, create_new_manifold(), CollisionPoints::d, CollisionData::data, EW, find_manifold_for_pair(), BVHNode::first_index, MeshNode::free, get_root_node(), GJK(), MeshNode::global_matrix, GLOBALS, ConvexHull::hull_faces, Mesh::hulls, MeshNode::id, BVHNode::left, MeshNode::local_id, m4_inverse(), MeshNode::mesh, Globals::mesh_nodes, Globals::meshes, CollisionPoints::mnA, CollisionPoints::mnB, BVHNode::next, Mesh::nodes, CollisionPoints::normal_impulse, MeshNode::parent, MeshNode::pc, PC_traverse_collision_bvh(), PC_traverse_scene_bvh(), CollisionPoints::pcA, CollisionPoints::pcB, Manifold::processed, BVHNode::right, Mesh::static_mesh, CollisionPoints::tangent_impulse, transform_aabb_by_model_matrix(), CollisionData::type, and ConvexHull::vertices.
Referenced by PC_traverse_scene_bvh(), search_collisions_from_hull(), and search_collisions_from_pc().
| void search_collisions_from_pc | ( | MeshNode * | mn, |
| PhysicsComponent * | pc ) |
Searches for collisions from a PhysicsComponent that has no corresponding Mesh.
| mn | The MeshNode that is detecting. |
| pc | The PhysicsComponent that is detecting. |
Definition at line 1005 of file physics.c.
References PhysicsComponent::aabb, CAST_VEC, PhysicsComponent::cd, MeshNode::global_matrix, GLOBALS, m4_inverse(), Globals::mesh_nodes, Globals::meshes, PC_traverse_scene_bvh(), Globals::scene_data, search_collisions_from_pc(), and transform_aabb_by_model_matrix().
Referenced by PC_find_collision(), and search_collisions_from_pc().
| void search_collisions_from_hull | ( | MeshNode * | mn, |
| PhysicsComponent * | pc ) |
Searches for collisions from a PhysicsComponent that has a corresponding Mesh.
| mn | The MeshNode that is detecting. |
| pc | The PhysicsComponent that is detecting. |
Definition at line 1021 of file physics.c.
References Mesh::aabb, Vector::buffer, SceneData::bvh_nodes, CAST_VEC, PhysicsComponent::cd, COL_CAPSULE, COL_HULL, COL_TRIANGLE, Vector::count, CollisionData::data, MeshNode::global_matrix, GLOBALS, ConvexHull::hull_faces, Mesh::hulls, m4_inverse(), MeshNode::mesh, Globals::mesh_nodes, Globals::meshes, PC_traverse_scene_bvh(), Globals::scene_data, search_collisions_from_hull(), Mesh::static_mesh, transform_aabb_by_model_matrix(), CollisionData::type, and ConvexHull::vertices.
Referenced by PC_find_collision(), and search_collisions_from_hull().
| void PC_find_collision | ( | MeshNode * | mn, |
| PhysicsComponent * | pc ) |
Searches for collisions from a PhysicsComponent and determines how based on if its corresponding Mesh exists or not.
| mn | The MeshNode that is detecting. |
| pc | The PhysicsComponent that is detecting. |
Definition at line 1066 of file physics.c.
References CAST_VEC, PhysicsComponent::cd, GLOBALS, MeshNode::mesh, Globals::mesh_nodes, Globals::meshes, PC_find_collision(), search_collisions_from_hull(), and search_collisions_from_pc().
Referenced by PC_find_collision(), and update_physics_components().
| void player_resolve_impulse_static | ( | PhysicsComponent * | pcA, |
| CollisionPoints * | p ) |
Solves an impulse for a Player PhysicsComponent against a static Mesh.
| pcA | The Player PhysicsComponent. |
| p | The input CollisionPoints that describe the collision penetration. |
Definition at line 1097 of file physics.c.
References CollisionPoints::a, cam, Camera::cam_data, CamData::cam_pos, CAST_VEC, PhysicsComponent::center_of_mass, CollisionPoints::d, dt, GLOBALS, PhysicsComponent::inverse_world, PhysicsComponent::mass, mat3_mul_vec3(), Globals::mesh_nodes, CollisionPoints::normal, CollisionPoints::normal_impulse, player_resolve_impulse_static(), PhysicsComponent::restitution, vec3_add(), vec3_cross(), vec3_dot(), vec3_scale(), vec3_sub(), vec4_to_vec3(), PhysicsComponent::vel, vec3::x, vec3::y, and vec3::z.
Referenced by player_resolve_impulse_static(), and resolve_collisions().
| void player_resolve_impulse | ( | PhysicsComponent * | pcA, |
| PhysicsComponent * | pcB, | ||
| CollisionPoints * | p ) |
Solves an impulse for a Player PhysicsComponent against another PhysicsComponent.
| pcA | The Player PhysicsComponent. |
| pcB | The B PhysicsComponent. |
| p | The input CollisionPoints that describe the collision penetration. |
Definition at line 1167 of file physics.c.
References CollisionPoints::a, PhysicsComponent::angular_velocity, CollisionPoints::b, CollisionPoints::bias_impulse, cam, Player::cam, Camera::cam_data, CamData::cam_pos, CAST_VEC, PhysicsComponent::center_of_mass, clamp(), CollisionPoints::d, dt, PhysicsComponent::ent, Entity::free, MeshNode::global_matrix, GLOBALS, PhysicsComponent::inverse_world, PhysicsComponent::mass, mat3_mul_vec3(), mat4_mul_point(), Entity::mesh_node, Globals::mesh_nodes, PhysicsComponent::mu, CollisionPoints::normal, CollisionPoints::normal_impulse, player, PhysicsComponent::player_pc, player_resolve_impulse(), PhysicsComponent::restitution, CollisionPoints::tangent, CollisionPoints::tangent_impulse, vec3_add(), vec3_cross(), vec3_dot(), vec3_length(), vec3_scale(), vec3_sub(), vec4_to_vec3(), PhysicsComponent::vel, vec3::x, vec3::y, and vec3::z.
Referenced by player_resolve_impulse(), and resolve_collisions().
| void PC_resolve_impulse_static | ( | PhysicsComponent * | pcA, |
| CollisionPoints * | p ) |
Solves an impulse for a PhysicsComponent against a static Mesh.
| pcA | The PhysicsComponent. |
| p | The input CollisionPoints that describe the collision penetration. |
| p | The input CollisionPoints that describe the collision . |
Definition at line 1357 of file physics.c.
References CollisionPoints::a, ang_impulse_sum, PhysicsComponent::angular_velocity, CollisionPoints::bias_impulse, cam, Player::cam, Camera::cam_data, CamData::cam_pos, CAST_VEC, PhysicsComponent::center_of_mass, clamp(), CollisionPoints::d, dt, PhysicsComponent::ent, Entity::free, MeshNode::global_matrix, GLOBALS, PhysicsComponent::inverse_world, PhysicsComponent::mass, mat3_mul_vec3(), mat4_mul_point(), Entity::mesh_node, Globals::mesh_nodes, PhysicsComponent::mu, CollisionPoints::normal, CollisionPoints::normal_impulse, PC_resolve_impulse_static(), player, PhysicsComponent::player_pc, PhysicsComponent::restitution, CollisionPoints::tangent, CollisionPoints::tangent_impulse, vec3_add(), vec3_cross(), vec3_dot(), vec3_length(), vec3_scale(), vec3_sub(), vec4_to_vec3(), PhysicsComponent::vel, vec3::x, vec3::y, and vec3::z.
Referenced by PC_resolve_impulse_static(), and update_physics_components().
| void PC_resolve_impulse | ( | PhysicsComponent * | pcA, |
| PhysicsComponent * | pcB, | ||
| CollisionPoints * | p ) |
Solves an impulse for a PhysicsComponent against another.
| pcA | The A PhysicsComponent. |
| pcB | The B PhysicsComponent. |
| p | The input CollisionPoints that describe the collision penetration. |
Definition at line 1516 of file physics.c.
References CollisionPoints::a, PhysicsComponent::angular_velocity, CollisionPoints::b, CollisionPoints::bias_impulse, cam, Player::cam, Camera::cam_data, CamData::cam_pos, CAST_VEC, PhysicsComponent::center_of_mass, clamp(), CollisionPoints::d, dt, PhysicsComponent::ent, Entity::free, MeshNode::global_matrix, GLOBALS, PhysicsComponent::inverse_world, PhysicsComponent::mass, mat3_mul_vec3(), mat4_mul_point(), Entity::mesh_node, Globals::mesh_nodes, PhysicsComponent::mu, CollisionPoints::normal, CollisionPoints::normal_impulse, PC_resolve_impulse(), player, PhysicsComponent::player_pc, PhysicsComponent::restitution, CollisionPoints::tangent, CollisionPoints::tangent_impulse, vec3_add(), vec3_cross(), vec3_dot(), vec3_length(), vec3_scale(), vec3_sub(), vec4_to_vec3(), PhysicsComponent::vel, vec3::x, vec3::y, and vec3::z.
Referenced by PC_resolve_impulse(), and update_physics_components().
| void update_physics_components | ( | ) |
The main PhysicsComponent loop that determines velocity, solves collisions, then integrates position.
\begin{align} & \text{Def:} \\ & \quad v = \text{Velocity} \\ & \quad G = \text{Gravity} \\ & \quad \omega = \text{Angular Velocity} \\ & \quad p = \text{Position} \\ & \quad r = \text{Rotation} \\ & \quad s = \text{Scale} \\ & \quad \mathit{IIA, IIW} = \text{Inverse Inertia} \\ & \quad M = \text{Transformation} \\ & \text{Let } C = \text{ all valid PhysicsComponents and } B = \text{ all valid Manifolds} \\ a(c) &= \begin{cases} v &= (v - G \cdot \Delta t) \cdot \beta \\ \omega &= \omega_{n} \cdot \alpha \end{cases} \\ C\prime &= a(C) = \lbrace a(x) | x \in C\rbrace \\ q(Q) &= \begin{cases} \begin{bmatrix} 1 - 2Q_y^2 - 2Q_z^2 & 2Q_xQ_y - 2Q_wQ_z & 2Q_xQ_z + 2Q_wQ_y \\ 2Q_xQ_y + 2Q_wQ_z & 1 - 2Q_x^2 - 2Q_z^2 & 2Q_yQ_z - 2Q_wQ_x \\ 2Q_xQ_z - 2Q_wQ_y & 2Q_yQ_z + 2Q_wQ_x & 1 - 2Q_x^2 - 2Q_y^2 \end{bmatrix} \end{cases} \\ t(c) &= \begin{cases} p = p + v\Delta t \\ \theta = || \omega || \cdot \Delta t \\ \left. \begin{cases} k = \frac{\omega}{||\omega||}\\ Q = \begin{pmatrix} k_x \cdot \sin \frac{\theta}{2}, k_y \cdot \sin \frac{\theta}{2}, k_z \cdot \sin \frac{\theta}{2}, \cos \frac{\theta}{2} \end{pmatrix}\\ r = \frac{Q r}{||Q r||}\\ \end{cases}\right\rbrace, & \text{if } \theta \gt 0 \\ M = \text{TRS}(p, r, s) \\ R = q(r) \\ \mathit{IIW} = (R \cdot IIA) \cdot R \\
\mathit{AABB}_{tr} = \mathit{AABB} \cdot M \end{cases} \\ t(C\prime) &= \lbrace t(x) | x \in C\prime\rbrace \\ L(c) &= \begin{cases} \text{for } y = 0 \text{ to } C_{\text{max}} - 1: \\ \quad B[c_{i}, t(C\prime)[y]_{i}] = \mathit{AABB}_{tr}(c) \cap \mathit{AABB}_{tr}(t(C\prime)[y]), & \text{if } \mathit{AABB}_{tr}(c) \cap \mathit{AABB}_{tr}(t(C\prime)[y]) \neq \emptyset \\ \end{cases} \\ B &= \lbrace L(x) | x \in t(C\prime)\rbrace \\ f(n, c_a, c_b) &= \begin{cases} R = l \times n \\ I = \mathit{IIW} \cdot R \\ T = I \times l \\ \psi = n \cdot T \\ \frac{1}{m_a} + \frac{1}{m_b} + \psi_a + \psi_b \\ \end{cases} \\ H(b) &= \begin{cases} p_i = a \cap b \\ \text{Where } p_i = \text{ simultaneously the penetration of } b_a \text{ into } b_b \text{ and also } b_b \text{ into } b_a \\ \mathcal P = M \begin{bmatrix} p_{ix} \\ p_{iy} \\ p_{iz} \\ 1\end{bmatrix} \\ \mathcal M = M \begin{bmatrix} c_x \\ c_y \\ c_z \\ 1\end{bmatrix} \\ l = \mathcal P - \mathcal M \\ V = v - \omega \times l \\ \phi = V_a - V_b \\ \mathcal L = \vec \phi \cdot \vec N \\ \text{when } \mathcal L \in (-\infty, 0)\text{:} \\ \quad K = f(\vec N, b_a, b_b) \\ \quad J = \frac{-(1 + \mathcal{R}) \cdot \mathcal L}{K} \\ \quad B_{F}\prime = \max(B_F + J, 0) \\ \quad J_F = B_F\prime - B_F \\ \quad F_\parallel = J_F \vec{N} \\ \quad v = v \pm F_\parallel \frac{1}{m} \\ \quad \omega = \omega + \mathit{IIW} \cdot (l \times \pm F_\parallel) \\ \quad V = V + \omega \times l \\ \quad \phi = V_a - V_b \\ \quad \mathcal L = \vec \phi \cdot \vec N \\ \quad V_t = \phi - \mathcal L \vec N \\ \quad V_l = || V_t || \\ \quad \text{when } V_l \in (0, \infty)\text{:} \\ \qquad \hat t = \frac{V_t}{V_l} \\ \qquad K = f(\hat t, b_a, b_b) \\ \qquad J_t = \frac{-(\phi \cdot \hat t)}{K} \\ \qquad \gamma = \mu_a B_F \\ \qquad B_T\prime = \min(\max(B_T + J_t, -\gamma), \gamma) \\ \qquad J_{tF} = B_T\prime - B_T \\ \qquad F_\perp = J_{tF} \hat t \\ \qquad v = v \pm F_\perp \frac{1}{m} \\ \qquad \omega = \omega + \mathit{IIW} \cdot (l \times \pm F_\perp) \\ \end{cases} \\ & \text {Where } \pm \text{ relates even and opposite forces and where H(b) modifies both respective bodies in } C\prime \\ H(B) &= \lbrace H(x) | x \in B\rbrace \\ C\prime\prime &= t(C\prime) = \lbrace t(x) | x \in C\prime\rbrace \\ S(b) &= \begin{cases} p = M \begin{bmatrix} p_x \\ p_y \\ p_z \\ 1\end{bmatrix} \\ d = p_a - p_b \\ s = d \cdot \vec N \\ u = \begin{cases} \left. \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}\right\rbrace, & \text{if } \vec{N}_z \lt 0.9\\ \left. \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}\right\rbrace, & \text{otherwise} \end{cases} \\ T = \frac{u \times \vec N}{|| u \times \vec N||} \\ D = d \cdot T \\ B \setminus \lbrace b \rbrace, & \text{ if } s \gt 0.01 \text{ or } D \gt 0.01 \end{cases} \\ B\prime &= S(B) = \lbrace S(x) | x \in B\rbrace \\ \end{align}
Definition at line 1724 of file physics.c.
References CollisionPoints::a, Manifold::a, MeshNode::aabb, aabb_to_vertices(), PhysicsComponent::accel, ACCEL_BETA, ang_impulse_sum, PhysicsComponent::angular_velocity, PhysicsComponent::at_rest, CollisionPoints::b, Manifold::b, CAST_VEC, PhysicsComponent::cd, COL_CAPSULE, DebugVertex::color, compose_trs_from_mesh_node(), compose_trs_from_vectors(), Manifold::contacts, Manifold::count, Vector::count, CollisionPoints::d, CollisionData::data, DEBUG_LINE_COUNT, DEBUG_LINES, Manifold::deepest, dt, PhysicsComponent::ent, Entity::free, Manifold::free, friction_sum, MeshNode::global_matrix, GLOBALS, impulse_sum, PhysicsComponent::inverse_inertia, PhysicsComponent::inverse_world, Light::light_type, Globals::lights, MANIFOLDS, mat3_mul(), mat3_transpose(), mat4_mul_point(), MAX_LIGHTS, MAX_MANIFOLDS, MAX_PHYSICS_COMPONENTS, MeshNode::mesh, Entity::mesh_node, Globals::mesh_nodes, Globals::meshes, CollisionPoints::mnA, CollisionPoints::mnB, CollisionPoints::normal, normal_impulse0, normal_impulse1, normal_impulse2, normal_impulse3, PhysicsComponent::old_angular, PhysicsComponent::old_vel, PC_apply_velocity(), PC_find_collision(), PC_resolve_impulse(), PC_resolve_impulse_static(), CollisionPoints::pcA, CollisionPoints::pcB, PHYSICS_COMPONENTS, PHYSICS_FULL, PhysicsComponent::physics_type, POINT_LIGHT, DebugVertex::pos, Light::pos, Manifold::processed, quat_from_axis_angle(), quat_mul(), quat_to_mat3(), Light::radius, rand(), render_mesh_aabbs_from_root(), PhysicsComponent::rest_counter, rot(), MeshNode::rotation, MeshNode::scale, Light::sm_dirty, test_sphere_aabb(), torque_sum, transform_aabb_by_model_matrix(), MeshNode::translation, CollisionData::type, update_physics_components(), vec3_add(), vec3_cross(), vec3_dot(), vec3_length(), vec3_normalize(), vec3_scale(), vec3_sub(), vec4_normalize(), PhysicsComponent::vel, vec3::x, vec3::y, and vec3::z.
Referenced by main(), and update_physics_components().
| mat3 calc_inverse_inertia | ( | PhysicsComponent * | pc | ) |
Calculates the mat3 IIA for a PhysicsComponent, using AABB bounds and mass.
Definition at line 2115 of file physics.c.
References mat3::a0, mat3::a1, mat3::a2, PhysicsComponent::aabb, mat3::b0, mat3::b1, mat3::b2, mat3::c0, mat3::c1, mat3::c2, calc_inverse_inertia(), AABB::extents, PhysicsComponent::mass, vec3::x, vec3::y, and vec3::z.
Referenced by calc_inverse_inertia(), init_PC(), and render_entity_menu().
| void init_PC | ( | int | mesh_node, |
| PhysicsComponent * | pc, | ||
| AABB | ai_aabb, | ||
| CollisionType | collision_type, | ||
| PhysicsType | physics_type ) |
Initializes a PhysicsComponent.
| mesh_node | The top-most MeshNode this corresponds to. |
| pc | Pointer to the PC to initialize. |
| ai_aabb | The AABB over the entire AssetInstance (unused). |
| collision_type | Indicates what to use for collision detection. |
| physics_type | Indicates what to compute during impulse resolution. |
Definition at line 2141 of file physics.c.
References Mesh::aabb, MeshNode::aabb, PhysicsComponent::aabb, PhysicsComponent::angular_velocity, calc_inverse_inertia(), CAST_VEC, PhysicsComponent::cd, AABB::center, PhysicsComponent::center_of_mass, COL_CAPSULE, COL_HULL, COL_TRIANGLE, CollisionData::data, GLOBALS, init_PC(), PhysicsComponent::inverse_inertia, PhysicsComponent::mass, AABB::max_z, MeshNode::mesh, Globals::mesh_nodes, Globals::meshes, AABB::min_z, PhysicsComponent::mu, PhysicsComponent::physics_type, PhysicsComponent::player_pc, print_aabb(), PhysicsComponent::restitution, CollisionData::type, PhysicsComponent::vel, vec3::x, and vec3::y.
Referenced by create_physics_component(), and init_PC().
| float normal_impulse0 = 0.0f |
Definition at line 1088 of file physics.c.
Referenced by update_physics_components().
| float normal_impulse1 = 0.0f |
Definition at line 1089 of file physics.c.
Referenced by update_physics_components().
| float normal_impulse2 = 0.0f |
Definition at line 1090 of file physics.c.
Referenced by update_physics_components().
| float normal_impulse3 = 0.0f |
Definition at line 1091 of file physics.c.
Referenced by update_physics_components().
Definition at line 1092 of file physics.c.
Referenced by update_physics_components().
Definition at line 1093 of file physics.c.
Referenced by update_physics_components().
Definition at line 1094 of file physics.c.
Referenced by update_physics_components().
Definition at line 1095 of file physics.c.
Referenced by PC_resolve_impulse_static(), and update_physics_components().