Skip to content

Physics & FPS#102

Merged
CubeBerry merged 4 commits into
mainfrom
Physics&FPS
Apr 15, 2026
Merged

Physics & FPS#102
CubeBerry merged 4 commits into
mainfrom
Physics&FPS

Conversation

@doyoung413

@doyoung413 doyoung413 commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Physics Core & Collisions

  • Implemented Continuous Collision Detection (CCD) to prevent 3D tunneling and added AABB-based Broad-phase filtering.
  • Upgraded SAT collision resolution to calculate exact contact points and apply angular impulses using Lever Arm (rA, rB) calculations.
  • Introduced collisionMaskMap and isGhostCollision to explicitly filter interactions and optimize out IGNORED pairs early.

Rigid Body & Rotational Dynamics

  • Introduced Moment of Inertia, Torque, and Angular Velocity with automatic inertia calculation and rotational damping.
  • Implemented Quaternion integration in Physics3D to accurately track rotation and prevent gimbal lock.

Architecture & Optimization

  • Delegated core movement and collision logic from Physics2D/Physics3D to the PhysicsManager.
  • Implemented a sleep state algorithm for stationary 3D objects to significantly improve CPU performance.
  • Stabilized FPS calculation using a fixed 1.0s interval and first-frame synchronization.

Demo & UI Updates

  • Added randomized 3D object spawning to the physics demo.
  • Replaced the Backspace key shortcut with a dedicated ImGui button for better UI usability.

Note: Additional optimization for the physics pipeline is currently in progress.

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.
@doyoung413 doyoung413 self-assigned this Apr 15, 2026
@CubeBerry
CubeBerry self-requested a review April 15, 2026 07:18
@CubeBerry CubeBerry added the enhancement New feature or request label Apr 15, 2026
@CubeBerry
CubeBerry merged commit aa45f2a into main Apr 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants