Physics & FPS#102
Merged
Merged
Conversation
Physics - Implemented Continuous Collision Detection (CCD) using Time-of-Impact (TOI) to prevent tunneling in 3D. - Added AABB-based Broad-phase filtering to optimize collision detection performance. - Refactored Physics2D and Physics3D components to delegate movement and collision logic to the manager. - Standardized physics integration (Gravity, Force, Friction) across the engine. FPS - Switched FPS calculation from frame-count based to fixed-time interval (1.0s) for enhanced stability. -Implemented first-frame synchronization to eliminate initial startup and loading spikes. -Added FPS clamping logic to maintain statistical consistency within user-defined limits.
Rigid Body Dynamics & Rotational Physics
- Introduced Moment of Inertia, Torque, and Angular Velocity to simulate realistic rotational movements for both 2D and 3D objects.
- Implemented Quaternion integration in 3D (Physics3D) to prevent gimbal lock and ensure accurate 3D rotation tracking.
Advanced Collision Response (Angular Impulse)
- Upgraded the collision resolution logic to calculate exact contact points (e.g., finding the deepest penetrating vertices and centroids via SAT).
- Added Lever Arm (rA, rB) calculations to apply angular impulses. Objects now spin realistically when hit off-center, conserving angular momentum.
Physics Optimization (Sleep System)
- Implemented a Sleep State algorithm for 3D physics. Objects with negligible linear and angular velocities are put to sleep, preventing unnecessary frame-by-frame calculations and significantly improving performance.
Code Standardization & Documentation
- Variable Naming: Standardized all local variables to lowerCamelCase (e.g., skin_width -> skinWidth, objA -> objectA).
- Formatting: Enforced explicit curly braces {} and line breaks for all if statements to prevent future scope bugs.
- Comments: Added comprehensive, step-by-step English comments explaining the complex math behind the Separating Axis Theorem (SAT), collision detection, and impulse calculations.
3D Physics Demo Updates
- Added a dynamic object spawning feature to the physics demo. Pressing the BACKSPACE key now randomly instantiates physics objects (either cubes or spheres) in mid-air. These spawned objects are generated with randomized properties, including initial position, rotation, scale, and color, along with an accurately scaled mass and restitution for realistic physical interactions.
Collision Filtering & Masking Architecture - Implemented a dynamic collisionMaskMap within PhysicsManager to explicitly define interaction rules between different ObjectType pairs (e.g., COLLIDE vs IGNORED). - Introduced the isGhostCollision property to physics bodies. This allows specific objects to be evaluated during the broad/narrow phases for overlap detection (triggers/boundaries) without applying physical positional corrections or impulses. - Optimized the Narrow Phase pipeline to immediately discard and erase object pairs marked as IGNORED, bypassing expensive SAT (Separating Axis Theorem) and distance checks entirely. 2D Rotational Physics Dynamics - Introduced MomentOfInertia, InverseInertia, Torque, and AngularVelocity to the Physics2D component to simulate realistic rigid-body rotational movements. - Automated the calculation of Moment of Inertia upon collider creation, applying the correct physics formulas based on the shape and mass. -nIntegrated rotational damping (friction) into the angular velocity calculations to gradually stabilize spinning objects over time. Refactored the Physics Demo UI - Replaced the Backspace key shortcut for spawning objects with a dedicated button in the ImGui window for better usability.
CubeBerry
approved these changes
Apr 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Physics Core & Collisions
Rigid Body & Rotational Dynamics
Physics3Dto accurately track rotation and prevent gimbal lock.Architecture & Optimization
Demo & UI Updates
Note: Additional optimization for the physics pipeline is currently in progress.