Skip to content

Commit a5b24f9

Browse files
authored
Merge pull request #104 from orange-cpp/copilot/update-docs-new-classes
Add documentation for GJK/EPA collision detection and mesh primitives
2 parents 1553139 + df4947c commit a5b24f9

File tree

12 files changed

+2545
-13
lines changed

12 files changed

+2545
-13
lines changed

docs/3d_primitives/mesh.md

Lines changed: 465 additions & 0 deletions
Large diffs are not rendered by default.

docs/api_overview.md

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ OMath is organized into several logical modules:
1111
### Core Mathematics
1212
- **Linear Algebra** - Vectors, matrices, triangles
1313
- **Trigonometry** - Angles, view angles, trigonometric functions
14-
- **3D Primitives** - Boxes, planes, geometric shapes
14+
- **3D Primitives** - Boxes, planes, meshes, geometric shapes
1515

1616
### Game Development
17-
- **Collision Detection** - Ray tracing, intersection tests
17+
- **Collision Detection** - Ray tracing, GJK/EPA algorithms, mesh collision, intersection tests
1818
- **Projectile Prediction** - Ballistics and aim-assist calculations
1919
- **Projection** - Camera systems and world-to-screen transformations
2020
- **Pathfinding** - A* algorithm, navigation meshes
@@ -131,6 +131,41 @@ omath::opengl_engine::Camera // OpenGL
131131

132132
## Collision Detection
133133

134+
### GJK/EPA Algorithms
135+
136+
Advanced convex shape collision detection using the Gilbert-Johnson-Keerthi and Expanding Polytope algorithms:
137+
138+
```cpp
139+
namespace omath::collision {
140+
template<class ColliderType>
141+
class GjkAlgorithm;
142+
143+
template<class ColliderType>
144+
class Epa;
145+
}
146+
```
147+
148+
**GJK (Gilbert-Johnson-Keerthi):**
149+
* Detects collision between two convex shapes
150+
* Returns a 4-point simplex when collision is detected
151+
* O(k) complexity where k is typically < 20 iterations
152+
* Works with any collider implementing `find_abs_furthest_vertex()`
153+
154+
**EPA (Expanding Polytope Algorithm):**
155+
* Computes penetration depth and separation normal
156+
* Takes GJK's output simplex as input
157+
* Provides contact information for physics simulation
158+
* Configurable iteration limit and convergence tolerance
159+
160+
**Supporting Types:**
161+
162+
| Type | Description | Key Features |
163+
|------|-------------|--------------|
164+
| `Simplex<VectorType>` | 1-4 point geometric simplex | Fixed capacity, GJK iteration support |
165+
| `MeshCollider<MeshType>` | Convex mesh collider | Support function for GJK/EPA |
166+
| `GjkHitInfo<VertexType>` | Collision result | Hit flag and simplex |
167+
| `Epa::Result` | Penetration info | Depth, normal, iteration count |
168+
134169
### LineTracer
135170
136171
Ray-casting and line tracing utilities:
@@ -142,7 +177,7 @@ namespace omath::collision {
142177
```
143178

144179
**Features:**
145-
- Ray-triangle intersection
180+
- Ray-triangle intersection (Möller-Trumbore algorithm)
146181
- Ray-plane intersection
147182
- Ray-box intersection
148183
- Distance calculations
@@ -154,6 +189,14 @@ namespace omath::collision {
154189
|------|-------------|-------------|
155190
| `Plane` | Infinite plane | `intersects_ray()`, `distance_to_point()` |
156191
| `Box` | Axis-aligned bounding box | `contains()`, `intersects()` |
192+
| `Mesh` | Polygonal mesh with transforms | `vertex_to_world_space()`, `make_face_in_world_space()` |
193+
194+
**Mesh Features:**
195+
* Vertex buffer (VBO) and index buffer (VAO/EBO) storage
196+
* Position, rotation, and scale transformations
197+
* Cached transformation matrix
198+
* Engine-specific coordinate system support
199+
* Compatible with `MeshCollider` for collision detection
157200

158201
---
159202

@@ -241,6 +284,13 @@ Implements camera math for an engine:
241284
- `calc_view_matrix()` - Build view matrix from angles and position
242285
- `calc_projection_matrix()` - Build projection matrix from FOV and viewport
243286
287+
### MeshTrait
288+
289+
Provides mesh transformation for an engine:
290+
- `rotation_matrix()` - Build rotation matrix from engine-specific angles
291+
- Handles coordinate system differences (Y-up vs Z-up, left/right-handed)
292+
- Used by `Mesh` class for local-to-world transformations
293+
244294
### PredEngineTrait
245295
246296
Provides physics/ballistics specific to an engine:
@@ -251,18 +301,18 @@ Provides physics/ballistics specific to an engine:
251301
252302
### Available Traits
253303
254-
| Engine | Camera Trait | Pred Engine Trait | Constants | Formulas |
255-
|--------|--------------|-------------------|-----------|----------|
256-
| Source Engine |||||
257-
| Unity Engine |||||
258-
| Unreal Engine |||||
259-
| Frostbite |||||
260-
| IW Engine |||||
261-
| OpenGL |||||
304+
| Engine | Camera Trait | Mesh Trait | Pred Engine Trait | Constants | Formulas |
305+
|--------|--------------|------------|-------------------|-----------|----------|
306+
| Source Engine | ✓ | ✓ | ✓ | ✓ | ✓ |
307+
| Unity Engine | ✓ | ✓ | ✓ | ✓ | ✓ |
308+
| Unreal Engine | ✓ | ✓ | ✓ | ✓ | ✓ |
309+
| Frostbite | ✓ | ✓ | ✓ | ✓ | ✓ |
310+
| IW Engine | ✓ | ✓ | ✓ | ✓ | ✓ |
311+
| OpenGL | ✓ | ✓ | ✓ | ✓ | ✓ |
262312
263313
**Documentation:**
264314
- See `docs/engines/<engine_name>/` for detailed per-engine docs
265-
- Each engine has separate docs for camera_trait, pred_engine_trait, constants, and formulas
315+
- Each engine has separate docs for camera_trait, mesh_trait, pred_engine_trait, constants, and formulas
266316
267317
---
268318
@@ -524,4 +574,4 @@ UnityCamera camera{pos, SourceAngles{}}; // Wrong!
524574

525575
---
526576

527-
*Last updated: 1 Nov 2025*
577+
*Last updated: 13 Nov 2025*

0 commit comments

Comments
 (0)