Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

animations: Add rotation parameter to Doom Fire #194

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions animations/src/doom_fire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use animation_utils::{
ParameterSchema,
};
use lightfx::{Color, Gradient};
use nalgebra::{Rotation3, Vector3};
use rand::Rng;
use serde::{Deserialize, Serialize};
use serde_json::json;
Expand Down Expand Up @@ -63,20 +64,20 @@ impl DoomFire {

fn tick(&mut self, parameters: &Parameters) {
let mut rng = rand::thread_rng();
for x in 0..self.surface.width {
for y in 1..self.surface.height() {
for y in 1..self.surface.height() {
for x in 0..self.surface.width {
let side_spread = if parameters.side_spread == 0 {
rng.gen_range(0..parameters.side_spread) * parameters.side_spread.signum()
} else {
0
};
let curr = self.surface.get(x, y).cloned().unwrap_or(0.0);
let curr = self.surface.get(x, y).copied().unwrap_or(0.0);
if let Some(p) = self.surface.get_mut(
(x as isize - side_spread as isize + 1).rem_euclid(self.surface.width as isize)
as usize,
y - 1,
) {
*p = (curr - rng.gen_range(0.0..1.0) * (1.0 - parameters.upward_spread) / 64.0)
*p = (curr - rng.gen_range(0.0..1.0) * (1.0 - parameters.upward_spread) / 36.0)
.clamp(0.0, 1.0);
}
}
Expand All @@ -101,20 +102,24 @@ pub struct Parameters {

#[schema_field(name = "Side spread", number(min = "-5.0", max = 5.0, step = 1.0))]
side_spread: i32,

#[schema_field(name = "Angle", number(min = 0.0, max = 360.0, step = 5.0))]
angle: f64,
}

impl Default for Parameters {
fn default() -> Self {
Parameters {
upward_spread: 0.33,
side_spread: 3,
angle: 0.0,
}
}
}

#[animation_utils::plugin]
pub struct DoomFireAnimation {
points: Vec<(f64, f64, f64)>,
points: Vec<Vector3<f64>>,
parameters: Parameters,
time: f64,
fire: DoomFire,
Expand All @@ -123,7 +128,10 @@ pub struct DoomFireAnimation {
impl DoomFireAnimation {
pub fn create(points: Vec<(f64, f64, f64)>) -> impl Animation {
SpeedControlled::new(BrightnessControlled::new(Self {
points,
points: points
.into_iter()
.map(|(x, y, z)| Vector3::new(x, y, z))
.collect(),
parameters: Default::default(),
time: 0.0,
fire: DoomFire::new(200, 200),
Expand All @@ -145,9 +153,12 @@ impl Animation for DoomFireAnimation {
}

fn render(&self) -> lightfx::Frame {
let rotation =
Rotation3::from_axis_angle(&Vector3::y_axis(), self.parameters.angle.to_radians());
self.points
.iter()
.map(|(x, y, _z)| self.fire.sample(*x, *y))
.map(|v| rotation * v)
.map(|v| self.fire.sample(v.x, v.y))
.into()
}

Expand Down
3 changes: 3 additions & 0 deletions plugins/doom-fire/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"display_name": "Doom Fire"
}
1 change: 1 addition & 0 deletions plugins/doom-fire/plugin
Loading