Fixed power delivery from engine, now 0-100 time seems to be in the right ballpark

This commit is contained in:
sergeypdev 2025-04-27 12:40:46 +04:00
parent cbe0dd20e5
commit 5c797145ae
3 changed files with 49 additions and 18 deletions

View File

@ -402,13 +402,13 @@ update_runtime_world :: proc(runtime_world: ^Runtime_World, dt: f32) {
physics.Engine_Config { physics.Engine_Config {
rpm_torque_curve = assets.get_curve_2d(&g_mem.assetman, "assets/ae86_rpm_torque.csv").points, rpm_torque_curve = assets.get_curve_2d(&g_mem.assetman, "assets/ae86_rpm_torque.csv").points,
lowest_rpm = 1000, lowest_rpm = 1000,
inertia = 0.0264, inertia = 0.264,
internal_friction = 0.00, internal_friction = 0.01,
gear_ratios = []f32{3.48, 3.587, 2.022, 1.384, 1, 0.861}, gear_ratios = []f32{3.48, 3.587, 2.022, 1.384, 1, 0.861},
axle = physics.Drive_Axle_Config { axle = physics.Drive_Axle_Config {
wheels = {wheel_rl, wheel_rr}, wheels = {wheel_rl, wheel_rr},
wheel_count = 2, wheel_count = 2,
diff_type = .Fixed, diff_type = .Open,
final_drive_ratio = 4.1, final_drive_ratio = 4.1,
}, },
}, },

View File

@ -177,6 +177,7 @@ Suspension_Constraint :: struct {
} }
Diff_Type :: enum { Diff_Type :: enum {
Open,
Fixed, Fixed,
// TODO: LSD // TODO: LSD
} }

View File

@ -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) gear_ratio := lookup_gear_ratio(gear_ratios, engine.gear)
if engine.gear != 0 { if engine.gear != 0 {
for i in 0 ..< engine.axle.wheel_count { ratio := gear_ratio * engine.axle.final_drive_ratio
drive_wheel := &engine.axle.wheels[i] inv_ratio := f32(1.0 / (ratio))
wheel := get_suspension_constraint(sim_state, drive_wheel.wheel)
ratio := gear_ratio * engine.axle.final_drive_ratio drive_wheel1 := &engine.axle.wheels[0]
inv_ratio := f32(1.0 / (ratio)) wheel1 := get_suspension_constraint(sim_state, drive_wheel1.wheel)
w1 := wheel.inv_inertia drive_wheel2 := &engine.axle.wheels[1]
w2 := f32(1.0 / (engine.inertia * ratio * ratio)) wheel2 := get_suspension_constraint(sim_state, drive_wheel2.wheel)
w := w1 + w2 w1 := f32(1.0 / (engine.inertia * ratio * ratio))
inv_w := f32(1.0 / w) 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 avg_wheel_vel := (wheel1.w + wheel2.w) * 0.5
// drive_wheel.impulse += incremental_impulse
wheel.w += incremental_impulse * w1 * inv_ratio delta_omega := avg_wheel_vel * ratio - (-engine.w)
engine.w += incremental_impulse / (engine.inertia * ratio * ratio)
} 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
} }
} }
} }