|
Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
|
Mathematical and geometric utility functions. More...
Data Structures | |
| struct | HitResult |
| Represents the result of a ray-object intersection test. More... | |
| struct | Ray |
| Represents a ray in 3D space. More... | |
Functions | |
| std::optional< float > | intersectTriangle (const Ray &ray, const glm::vec3 &v0, const glm::vec3 &v1, const glm::vec3 &v2) |
| Tests ray-triangle intersection using Möller-Trumbore algorithm. | |
| glm::vec3 | screenToWorldRayDirection (double mouseX, double mouseY, int fbWidth, int fbHeight, const glm::mat4 &view, const glm::mat4 &projection) |
| Converts screen coordinates to a world-space ray direction. | |
| std::optional< HitResult > | findFirstHit (const std::vector< IPickable * > &objects, const Ray &ray, IPickable *priority=nullptr) |
| Finds the first object intersected by a ray. | |
Mathematical and geometric utility functions.
Provides ray intersection tests, coordinate transformations, and interpolation utilities used throughout the rendering and physics systems.
| struct Math::HitResult |
Represents the result of a ray-object intersection test.
Contains information about which object was hit by a ray and the distance from the ray origin to the intersection point.
Definition at line 146 of file MathUtils.h.
| Data Fields | ||
|---|---|---|
| float | distance | Distance from the ray origin to the intersection point. Infinity if no hit. |
| IPickable * | object | Pointer to the hit object, or nullptr if no intersection. |
| struct Math::Ray |
Represents a ray in 3D space.
Used for mouse picking, collision detection, and line-of-sight tests. The ray is defined parametrically as: \(P(t) = \texttt{origin} + t \cdot \texttt{dir}\)
| Data Fields | ||
|---|---|---|
| vec3 | dir | Direction vector (should be normalized) |
| vec3 | origin | Starting point of the ray in world space. |
|
inline |
Finds the first object intersected by a ray.
Performs ray intersection tests against all objects in the provided vector and returns the closest hit as a HitResult, which contains both the object and the distance to the intersection. An optional priority object can be provided; if it is intersected by the ray, it will be returned immediately without testing the remaining objects.
| objects | List of pickable objects to test against. |
| ray | Ray to test (origin and direction). |
| priority | Optional object to prioritize; if hit, it takes precedence. |
std::optional<HitResult>, or std::nullopt if no object is hit.:objects list is modified concurrently.Definition at line 173 of file MathUtils.h.
|
inline |
Tests ray-triangle intersection using Möller-Trumbore algorithm.
This is a fast, stable algorithm that computes barycentric coordinates and checks if the intersection point lies within the triangle.
| ray | Ray to test (origin + direction) |
| v0 | First triangle vertex |
| v1 | Second triangle vertex |
| v2 | Third triangle vertex |
std::nullopt if no intersectionExample:
Definition at line 54 of file MathUtils.h.
|
inline |
Converts screen coordinates to a world-space ray direction.
Transforms 2D mouse/screen coordinates into a 3D ray emanating from the camera position. This is essential for mouse picking and interaction.
| mouseX | Screen X coordinate in pixels (0 = left edge) |
| mouseY | Screen Y coordinate in pixels (0 = top edge) |
| fbWidth | Framebuffer width in pixels |
| fbHeight | Framebuffer height in pixels |
| view | Camera view matrix (world-to-camera transform) |
| projection | Camera projection matrix (camera-to-clip transform) |
Ray::dir Example usage:
Definition at line 117 of file MathUtils.h.