Skip to content

Commit 2d176f2

Browse files
committed
Fix drag functionality: visual effects now follow dragged voices
- Update render function to accept voice positions and pulse energy - Replace hardcoded voice positions with dynamic positions from engine - Wave displacement effects now properly follow dragged voices - Maintains all existing audio spatialization functionality - All tests pass, build succeeds, CI runs successfully
1 parent 7db15fb commit 2d176f2

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/frame.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,17 @@ impl<'a> FrameContext<'a> {
171171
let w = self.canvas.width();
172172
let h = self.canvas.height();
173173
g.resize_if_needed(w, h);
174-
if let Err(e) = g.render(dt_sec) {
174+
// Get current voice positions and pulse energy for rendering
175+
let voice_positions: Vec<Vec3> = {
176+
let engine_ref = self.engine.borrow();
177+
engine_ref.voices.iter().map(|v| v.position).collect()
178+
};
179+
let pulse_energy_snapshot: Vec<f32> = {
180+
let pulses_ref = self.pulses.borrow();
181+
pulses_ref.clone()
182+
};
183+
184+
if let Err(e) = g.render(dt_sec, &voice_positions, &pulse_energy_snapshot) {
175185
log::error!("render error: {:?}", e);
176186
}
177187
}

src/render.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,12 @@ impl<'a> GpuState<'a> {
343343
}
344344
}
345345

346-
pub fn render(&mut self, dt_sec: f32) -> Result<(), wgpu::SurfaceError> {
346+
pub fn render(
347+
&mut self,
348+
dt_sec: f32,
349+
voice_positions: &[Vec3],
350+
pulse_energy: &[f32],
351+
) -> Result<(), wgpu::SurfaceError> {
347352
self.resize_if_needed(self.width, self.height);
348353
self.time_accum += dt_sec.max(0.0);
349354
let frame = self.surface.get_current_texture()?;
@@ -376,14 +381,29 @@ impl<'a> GpuState<'a> {
376381
ambient: self.ambient_energy,
377382
voices: [
378383
VoicePacked {
379-
pos_pulse: [0.0, 0.0, -4.0, 0.0],
380-
}, // Voice 1 at center
384+
pos_pulse: [
385+
voice_positions[0].x,
386+
voice_positions[0].y,
387+
voice_positions[0].z,
388+
pulse_energy[0],
389+
],
390+
},
381391
VoicePacked {
382-
pos_pulse: [-1.8, 0.0, -4.0, 0.0],
383-
}, // Voice 2 left
392+
pos_pulse: [
393+
voice_positions[1].x,
394+
voice_positions[1].y,
395+
voice_positions[1].z,
396+
pulse_energy[1],
397+
],
398+
},
384399
VoicePacked {
385-
pos_pulse: [1.8, 0.0, -4.0, 0.0],
386-
}, // Voice 3 right
400+
pos_pulse: [
401+
voice_positions[2].x,
402+
voice_positions[2].y,
403+
voice_positions[2].z,
404+
pulse_energy[2],
405+
],
406+
},
387407
],
388408
swirl_uv: [
389409
self.swirl_uv[0].clamp(0.0, 1.0),

0 commit comments

Comments
 (0)