Searchlights with real spot lights and volumetric beams (#60); replay director: several angles per event, slow-motion kills, /airdef replay film and export to MP4 (#58) (fork patch 32)
build / mod (push) Successful in 3m32s
build / mod (push) Successful in 3m32s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,13 @@ const FLARE_LIGHT: f64 = 90.0;
|
||||
const FLARE_CLIMB: u32 = 28;
|
||||
/// How far a searchlight's beam reaches.
|
||||
pub const BEAM: f64 = 450.0;
|
||||
/// A searchlight's cone: full strength inside the inner half angle, none past the outer (radians).
|
||||
pub const BEAM_INNER: f64 = 0.03;
|
||||
pub const BEAM_OUTER: f64 = 0.075;
|
||||
/// A target is lit once the axis is this close to it (inside the cone's soft edge).
|
||||
const LIT_ANGLE: f64 = 0.05;
|
||||
/// Ticks between casts of the beam's axis against the land.
|
||||
const CAST_EVERY: u64 = 4;
|
||||
/// Guns' hits at night on an unlit target.
|
||||
pub const DARK_HITS: f64 = 0.4;
|
||||
/// Ticks between a gun's own flares.
|
||||
@@ -35,7 +42,7 @@ impl Sim {
|
||||
}
|
||||
|
||||
/// The flares and the searchlights, and what they light; the guns' own flares.
|
||||
pub(super) fn step_lights(&mut self, out: &mut Out) {
|
||||
pub(super) fn step_lights(&mut self, ground: &mut Ground, out: &mut Out) {
|
||||
self.lit.clear();
|
||||
let now = self.tick;
|
||||
// Flares: up, a burst, then down slowly, swaying, lighting all round.
|
||||
@@ -71,12 +78,14 @@ impl Sim {
|
||||
let gun_targets: Vec<u32> = self.sams.iter().filter_map(|s| s.gun_target).collect();
|
||||
for i in 0..self.sams.len() {
|
||||
if self.sams[i].kind != SamKind::Light || !self.sams[i].alive() || self.sams[i].moving() {
|
||||
self.sams[i].beam_on = false;
|
||||
continue;
|
||||
}
|
||||
let (pos, id) = (self.sams[i].pos, self.sams[i].id);
|
||||
if !self.night {
|
||||
let sam = &mut self.sams[i];
|
||||
sam.target = None;
|
||||
sam.beam_on = false;
|
||||
sam.pitch += (0.0 - sam.pitch) * 0.05;
|
||||
continue;
|
||||
}
|
||||
@@ -103,15 +112,34 @@ impl Sim {
|
||||
sam.yaw = slew(sam.yaw, want_yaw, 0.12);
|
||||
sam.pitch = slew(sam.pitch, want_pitch.clamp(0.05, 1.5), 0.08);
|
||||
sam.target = target.map(|t| t.0);
|
||||
// The beam: segments widening with distance, out to the target.
|
||||
// The beam: a spot light from the head (see `Sam::beam`); the axis is cast against the land
|
||||
// now and then, and the light and the lit mark stop where the land does.
|
||||
let (head, rot) = self.sams[i].mount();
|
||||
let dir = rot * DVec3::NEG_Z;
|
||||
// The target is lit once the beam is on it, not while it still swings round.
|
||||
let sam = &mut self.sams[i];
|
||||
sam.beam_on = true;
|
||||
if now.saturating_sub(sam.beam_cast) >= CAST_EVERY || sam.beam_free <= 0.0 {
|
||||
sam.beam_cast = now;
|
||||
sam.beam_free = match ground.world.probe(head + dir, head + dir * BEAM, now) {
|
||||
world::Sweep::Hit { point, .. } => point.distance(head).max(1.0),
|
||||
_ => BEAM,
|
||||
};
|
||||
}
|
||||
let free = sam.beam_free;
|
||||
// The target is lit once the beam is on it and nothing of the land is between, not while
|
||||
// it still swings round.
|
||||
if let Some((t, at)) = target
|
||||
&& dir.angle_between(at - head) < 0.08
|
||||
&& dir.angle_between(at - head) < LIT_ANGLE
|
||||
&& (at - head).length() <= free + 2.0
|
||||
{
|
||||
self.lit.push(t);
|
||||
}
|
||||
// Without the renderer's spot light: segments widening with distance, thin; none with
|
||||
// the effects off.
|
||||
if self.spot_hd || !self.shader {
|
||||
continue;
|
||||
}
|
||||
let reach = reach.min(free);
|
||||
let mut along = 1.0;
|
||||
// Up to 14 segments (the unit's part ids 2..15), each longer than the last: one
|
||||
// reaches about 550 blocks, past the beam's reach, about 9 blocks wide out there.
|
||||
@@ -119,7 +147,7 @@ impl Sim {
|
||||
if along >= reach {
|
||||
break;
|
||||
}
|
||||
let size = 0.8 + along * 0.12;
|
||||
let size = 0.5 + along * 0.1;
|
||||
let len = 3.0 * size;
|
||||
out.model(id + 2 + k, "airdef:beam", head + dir * (along + len / 2.0), rot, size, true);
|
||||
along += len;
|
||||
@@ -147,3 +175,23 @@ impl Sim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A searchlight's beam for the renderer: where it starts, which way it points and how far it runs free.
|
||||
pub struct Beam {
|
||||
pub id: u32,
|
||||
pub origin: DVec3,
|
||||
pub dir: DVec3,
|
||||
pub free: f64,
|
||||
}
|
||||
|
||||
impl Sam {
|
||||
/// The beam of a lit searchlight, from the lens of its head.
|
||||
pub fn spot_beam(&self) -> Option<Beam> {
|
||||
if self.kind != SamKind::Light || !self.alive() || !self.beam_on {
|
||||
return None;
|
||||
}
|
||||
let (head, rot) = self.mount();
|
||||
let dir = rot * DVec3::NEG_Z;
|
||||
Some(Beam { id: self.id, origin: head + dir * 1.0, dir, free: self.beam_free })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user