mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
26 lines
1006 B
GDScript
26 lines
1006 B
GDScript
class_name HudInstrument
|
|
extends Control
|
|
|
|
# Shared base for the HUD's procedural instruments (heading tape, attitude
|
|
# indicator, gauges): the exponential-smoothing weight calc and the
|
|
# angle-aware lerp helper they all use. Each instrument still owns its own
|
|
# _process (smoothing 1-2 distinct fields) and _draw (entirely bespoke).
|
|
|
|
const SMOOTHING := 12.0
|
|
|
|
|
|
static func lerp_angle_deg(from: float, to: float, weight: float) -> float:
|
|
return rad_to_deg(lerp_angle(deg_to_rad(from), deg_to_rad(to), weight))
|
|
|
|
|
|
# Shortest signed distance from `from` to `to` in degrees, wrapped to
|
|
# [-180, 180]. Use this (never a plain subtraction) to decide whether an
|
|
# angle that wraps around (heading, roll) has moved enough to redraw —
|
|
# a naive delta gives a false-large jump at the 0/360 boundary.
|
|
static func angle_delta_deg(from: float, to: float) -> float:
|
|
return wrapf(to - from, -180.0, 180.0)
|
|
|
|
|
|
func _smoothing_weight(delta: float) -> float:
|
|
return 1.0 - exp(-SMOOTHING * delta) # frame-rate independent
|