Skip to content

Implement control torques, thrust-pitch coupling, and ground handling (#14 #15)#19

Open
mido3ds wants to merge 2 commits into
masterfrom
feat/control-torques-ground-handling
Open

Implement control torques, thrust-pitch coupling, and ground handling (#14 #15)#19
mido3ds wants to merge 2 commits into
masterfrom
feat/control-torques-ground-handling

Conversation

@mido3ds

@mido3ds mido3ds commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Two features in one PR (they share overlapping file changes):

#14 — Control Torques and Thrust-Pitch Coupling

  • Replaced direct delta-angle rotation with full torque-based physics
  • Control surface deflections produce torques: torque = deflection * EFFICIENCY * rho * v^2
  • Angular acceleration from inertia tensor: ang_accel = I^-1 * torque
  • Angular velocity integrated per-frame with damping
  • Quaternion updated from body-frame angular velocity
  • Thrust-pitch coupling: thrust offset from CG (derived from AABB) produces pitching moment via cross(offset, thrust)

#15 — Ground Handling

  • Rolling friction opposes velocity when on ground
  • Brake input bound to Left Shift
  • Weight zeroed on ground (prevents gravity accumulation)
  • Ground clamp runs after translation (unconditional)
  • Engine power formula: zero thrust when speed_percent = 0 (idle power only applies above zero)
  • NaN guard: normalize(0,0,0) protected with length check
  • FP epsilon: aircraft_on_ground uses 0.001m tolerance to prevent gravity impulse from floating-point drift

Files Changed

src/aircraft.cpp | 21 +++++++++++----------
src/aircraft.h   |  2 +-
src/math.h       | 13 ++++++++++---

Test Plan

  1. Build: cmake --build build -j — should compile without errors
  2. Run: ./build/bin/Debug/open-ysf — verify all 8 test suites PASS at startup:
    • test_parser, test_aabbs_intersection, test_polygons_to_triangles, test_line_segments_to_lines
    • test_rotational_physics, test_torque_physics, test_ground_handling, test_aircraft_ground_handling
  3. Startup stability — plane should sit on ground, NOT move, NOT clip through terrain
  4. Taxi — apply throttle (Q), plane should roll forward; rudder (C/Z) should steer (no veering)
  5. Take off — accelerate to rotation speed, elevator (up/down) should raise nose
  6. Fly — aileron (left/right), elevator, rudder should all respond
  7. Land — touch down, brake (Left Shift) should stop the plane

… handling physics (#14 #15)

#14 — Control torques:
- Replace direct delta-angle rotation with torque-based physics
- torque = deflection × EFFICIENCY × ρ × v² in body frame
- angular acceleration = I⁻¹ × torque, integrated to angular velocity
- quaternion updated from body-frame angular velocity
- thrust-pitch coupling via cross(thrust_offset, thrust_vec)
- thrust_offset computed from AABB on aircraft load
- Ang_vel damping via ANGULAR_DAMPING constant

#15 — Ground handling:
- Rolling friction opposes velocity on ground
- Brake input (Left Shift) applies braking force
- Ground clamp replaces old std::min line
- Old thrust-reduction ground block removed
- New constants: BRAKE_FORCE, GROUND_RUDDER_BOOST, GROUND_FRICTION

Tests: test_torque_physics, test_ground_handling, test_aircraft_ground_handling
@mido3ds mido3ds force-pushed the feat/control-torques-ground-handling branch from f2c8995 to d33bbf9 Compare July 2, 2026 11:49
… normalize

Fixes three root causes:

1. Idle thrust at zero throttle (aircraft.cpp:266):
   engine power formula produced idle_power even when speed_percent=0.
   Changed to require speed_percent > 0.

2. FP ground-detection failure (aircraft.h:262):
   on_ground used y >= -1.0f which fails at y=-1.0000001 from
   accumulated std::min FP error. Added 0.001m epsilon.

3. NaN from zero-vector normalize (aircraft.cpp:391):
   With total force=0 (ground, no thrust), normalize(0,0,0) returns NaN.
   Guarded with length checks.

4. Clamp after translation (aircraft.cpp:314->404):
   Moved ground-clamp AFTER translation so plane stays at ground level.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ground handling physics (taxi, takeoff roll, landing) Implement control torques and thrust-pitch coupling

1 participant