Add exponential fog controllable with keyboard and MARSH parameter

This commit is contained in:
Marek S. Łukasiewicz 2026-01-15 16:39:54 +01:00
parent aaef0b0475
commit c1c3be7e85
8 changed files with 78 additions and 7 deletions

View file

@ -1,15 +1,18 @@
extends Node3D
signal use_fallback(active: bool)
signal fog_density_changed(new_density: float)
## Rotation of cyclic stick model for full control deflection, in degrees
@export var range_cyclic: float = 30
## Main rotor speed, in revolutions per minute
@export var rotor_rpm: float = 500
@export var track_platform: bool = false
@export var fog_values: Array[float] = [0.0, -1.0, -2.0, -3.0, -4.0]
## Current angle of rotor rotation
var _rotor_azimuth: float = 0
var fog_index: int = 0
@onready var connector: MarshConnector = $MarshConnector
@onready var skeleton: Skeleton3D = $"Mi-2/Armature/Skeleton3D"
@ -65,6 +68,14 @@ func _process(delta: float) -> void:
xr_origin.transform = tracker_mount.transform * tracker.transform.affine_inverse()
recent_tracking.start()
func _input(event):
if event.is_action_pressed("fog_cycle"):
var step = 1
if event is InputEventWithModifiers and event.shift_pressed:
step = -1
# The index is updated in the signal callback to handle parameter changes
connector.fog_density = fog_values[(fog_index + step) % len(fog_values)]
# Only reset the position when tracking is lost for some time
func _on_recent_tracking_timeout() -> void:
xr_origin.transform = Transform3D.IDENTITY
@ -72,3 +83,14 @@ func _on_recent_tracking_timeout() -> void:
func _on_vr_setup_failed() -> void:
xr_camera.current = false
use_fallback.emit(true)
func _on_marsh_connector_fog_density_changed(new_density: float) -> void:
# Forward to parent
fog_density_changed.emit(new_density)
# Round down to nearest defined value or assign the last one (so it will disable on next cycle)
# Example: -1.5 should select -2 and on next cycle it will be -3
var new_index = fog_values.find_custom(func (d): return d <= new_density)
if new_index == -1:
new_index = len(fog_values) - 1
fog_index = new_index