From 5c797145ae45a4313851c2afc3dba516ab30087a Mon Sep 17 00:00:00 2001 From: sergeypdev Date: Sun, 27 Apr 2025 12:40:46 +0400 Subject: [PATCH] Fixed power delivery from engine, now 0-100 time seems to be in the right ballpark --- game/game.odin | 6 ++-- game/physics/scene.odin | 1 + game/physics/simulation.odin | 60 +++++++++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/game/game.odin b/game/game.odin index 916e5a0..2680aae 100644 --- a/game/game.odin +++ b/game/game.odin @@ -402,13 +402,13 @@ update_runtime_world :: proc(runtime_world: ^Runtime_World, dt: f32) { physics.Engine_Config { rpm_torque_curve = assets.get_curve_2d(&g_mem.assetman, "assets/ae86_rpm_torque.csv").points, lowest_rpm = 1000, - inertia = 0.0264, - internal_friction = 0.00, + inertia = 0.264, + internal_friction = 0.01, gear_ratios = []f32{3.48, 3.587, 2.022, 1.384, 1, 0.861}, axle = physics.Drive_Axle_Config { wheels = {wheel_rl, wheel_rr}, wheel_count = 2, - diff_type = .Fixed, + diff_type = .Open, final_drive_ratio = 4.1, }, }, diff --git a/game/physics/scene.odin b/game/physics/scene.odin index 9ebce02..a94a4ee 100644 --- a/game/physics/scene.odin +++ b/game/physics/scene.odin @@ -177,6 +177,7 @@ Suspension_Constraint :: struct { } Diff_Type :: enum { + Open, Fixed, // TODO: LSD } diff --git a/game/physics/simulation.odin b/game/physics/simulation.odin index 6f07feb..64ef176 100644 --- a/game/physics/simulation.odin +++ b/game/physics/simulation.odin @@ -587,27 +587,57 @@ pgs_solve_engines :: proc(sim_state: ^Sim_State, config: Solver_Config, dt: f32, gear_ratio := lookup_gear_ratio(gear_ratios, engine.gear) if engine.gear != 0 { - for i in 0 ..< engine.axle.wheel_count { - drive_wheel := &engine.axle.wheels[i] - wheel := get_suspension_constraint(sim_state, drive_wheel.wheel) + ratio := gear_ratio * engine.axle.final_drive_ratio + inv_ratio := f32(1.0 / (ratio)) - ratio := gear_ratio * engine.axle.final_drive_ratio - inv_ratio := f32(1.0 / (ratio)) + drive_wheel1 := &engine.axle.wheels[0] + wheel1 := get_suspension_constraint(sim_state, drive_wheel1.wheel) - w1 := wheel.inv_inertia - w2 := f32(1.0 / (engine.inertia * ratio * ratio)) + drive_wheel2 := &engine.axle.wheels[1] + wheel2 := get_suspension_constraint(sim_state, drive_wheel2.wheel) - w := w1 + w2 - inv_w := f32(1.0 / w) + w1 := f32(1.0 / (engine.inertia * ratio * ratio)) + w2 := wheel1.inv_inertia + w3 := wheel2.inv_inertia - delta_omega := wheel.w * ratio - (-engine.w) + w := w1 + w2 + w3 + inv_w := f32(1.0 / w) - incremental_impulse := -inv_w * delta_omega - // drive_wheel.impulse += incremental_impulse + avg_wheel_vel := (wheel1.w + wheel2.w) * 0.5 - wheel.w += incremental_impulse * w1 * inv_ratio - engine.w += incremental_impulse / (engine.inertia * ratio * ratio) - } + delta_omega := avg_wheel_vel * ratio - (-engine.w) + + incremental_impulse := -inv_w * delta_omega + + engine.w += incremental_impulse * w1 + wheel1.w += incremental_impulse * w2 * inv_ratio + wheel2.w += incremental_impulse * w3 * inv_ratio + } + } + + // Diff + { + switch engine.axle.diff_type { + case .Open: + case .Fixed: + drive_wheel1 := &engine.axle.wheels[0] + wheel1 := get_suspension_constraint(sim_state, drive_wheel1.wheel) + + drive_wheel2 := &engine.axle.wheels[1] + wheel2 := get_suspension_constraint(sim_state, drive_wheel2.wheel) + + w1 := wheel1.inv_inertia + w2 := wheel2.inv_inertia + + w := w1 + w2 + inv_w := f32(1.0 / w) + + delta_omega := wheel2.w - wheel1.w + + incremental_impulse := -inv_w * delta_omega + + wheel1.w += -incremental_impulse * wheel1.inv_inertia + wheel2.w += incremental_impulse * wheel2.inv_inertia } } }