From 2539dead1e4abc75e58a8bf8c0ea180f8f73a380 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 1 May 2025 20:21:30 -0700 Subject: [PATCH] dave: nudge avatar when you click Signed-off-by: William Casarin --- crates/notedeck_dave/src/avatar.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/notedeck_dave/src/avatar.rs b/crates/notedeck_dave/src/avatar.rs index 5050f54..79a50ec 100644 --- a/crates/notedeck_dave/src/avatar.rs +++ b/crates/notedeck_dave/src/avatar.rs @@ -301,12 +301,16 @@ fn apply_friction(val: f32, friction: f32, clamp: f32) -> f32 { impl DaveAvatar { pub fn random_nudge(&mut self) { + self.random_nudge_with(1.0); + } + + pub fn random_nudge_with(&mut self, force: f32) { let mut rng = rand::rng(); let nudge = Vec3::new( - rng.random::(), - rng.random::(), - rng.random::(), + rng.random::() * force, + rng.random::() * force, + rng.random::() * force, ) .normalize(); @@ -331,7 +335,7 @@ impl DaveAvatar { // Apply rotations (order matters) self.rotation = y_rotation.multiply(&x_rotation).multiply(&self.rotation); } else if response.clicked() { - self.random_nudge(); + self.random_nudge_with(1.0); } else { // Continuous rotation - reduced speed and simplified axis let friction = 0.95; @@ -343,11 +347,11 @@ impl DaveAvatar { // we only need to render if we're still spinning if self.rot_dir.x > clamp || self.rot_dir.y > clamp || self.rot_dir.z > clamp { let x_rotation = - Quaternion::from_axis_angle(&Vec3::new(1.0, 0.0, 0.0), self.rot_dir.y * 0.01); + Quaternion::from_axis_angle(&Vec3::new(1.0, 0.0, 0.0), self.rot_dir.y * 0.03); let y_rotation = - Quaternion::from_axis_angle(&Vec3::new(0.0, 1.0, 0.0), self.rot_dir.x * 0.01); + Quaternion::from_axis_angle(&Vec3::new(0.0, 1.0, 0.0), self.rot_dir.x * 0.03); let z_rotation = - Quaternion::from_axis_angle(&Vec3::new(0.0, 0.0, 1.0), self.rot_dir.z * 0.01); + Quaternion::from_axis_angle(&Vec3::new(0.0, 0.0, 1.0), self.rot_dir.z * 0.03); self.rotation = y_rotation .multiply(&x_rotation)