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