notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 32f7d484f81673f049ff056e4b9e818324ca0293
parent 343f2ce410915aa421f2c0793ee5e7710eefb8f9
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 24 Mar 2025 14:16:09 -0700

dave: rotation tweaks

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mcrates/notedeck_dave/src/avatar.rs | 18++++++++++++------
Mcrates/notedeck_dave/src/lib.rs | 2+-
2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/crates/notedeck_dave/src/avatar.rs b/crates/notedeck_dave/src/avatar.rs @@ -5,6 +5,7 @@ use egui::{Rect, Response}; pub struct DaveAvatar { rotation: Quaternion, + rot_dir: egui::Vec2, } // A simple quaternion implementation @@ -357,6 +358,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { Self { rotation: Quaternion::identity(), + rot_dir: egui::Vec2::ZERO, } } } @@ -368,17 +370,21 @@ impl DaveAvatar { // Update rotation based on drag or animation if response.dragged() { // Create rotation quaternions based on drag - let x_rotation = - Quaternion::from_axis_angle([1.0, 0.0, 0.0], response.drag_delta().y * 0.01); - let y_rotation = - Quaternion::from_axis_angle([0.0, 1.0, 0.0], response.drag_delta().x * 0.01); + let dx = response.drag_delta().x; + let dy = response.drag_delta().y; + let x_rotation = Quaternion::from_axis_angle([1.0, 0.0, 0.0], dy * 0.01); + let y_rotation = Quaternion::from_axis_angle([0.0, 1.0, 0.0], dx * 0.01); + + self.rot_dir = egui::Vec2::new(dx, dy); // Apply rotations (order matters) self.rotation = y_rotation.multiply(&x_rotation).multiply(&self.rotation); } else { // Continuous rotation - reduced speed and simplified axis - let continuous_rotation = Quaternion::from_axis_angle([0.0, 1.0, 0.0], 0.005); - self.rotation = continuous_rotation.multiply(&self.rotation); + let x_rotation = Quaternion::from_axis_angle([1.0, 0.0, 0.0], self.rot_dir.y * 0.01); + let y_rotation = Quaternion::from_axis_angle([0.0, 1.0, 0.0], self.rot_dir.x * 0.01); + + self.rotation = y_rotation.multiply(&x_rotation).multiply(&self.rotation); } // Create model matrix from rotation quaternion diff --git a/crates/notedeck_dave/src/lib.rs b/crates/notedeck_dave/src/lib.rs @@ -107,7 +107,7 @@ impl Dave { }); if let Some(avatar) = &mut self.avatar { - let avatar_size = Vec2::splat(400.0); + let avatar_size = Vec2::splat(200.0); let pos = Vec2::splat(100.0).to_pos2(); let pos = Rect::from_min_max(pos, pos + avatar_size); avatar.render(pos, ui);