Animated transforms on hover

This commit is contained in:
Aleksander
2025-06-20 13:06:04 +02:00
parent df320a5c7b
commit a2a7c71c22
7 changed files with 125 additions and 66 deletions

View File

@@ -1,3 +1,4 @@
use glam::{Mat4, Vec2, Vec3};
use vulkano::buffer::BufferContents;
// binary compatible mat4 which could be transparently used by vulkano BufferContents
@@ -6,13 +7,20 @@ use vulkano::buffer::BufferContents;
pub struct WMat4(pub [f32; 16]);
impl WMat4 {
pub fn from_glam(mat: &glam::Mat4) -> WMat4 {
pub fn from_glam(mat: &Mat4) -> WMat4 {
WMat4(*mat.as_ref())
}
}
impl Default for WMat4 {
fn default() -> Self {
Self(*glam::Mat4::IDENTITY.as_ref())
Self(*Mat4::IDENTITY.as_ref())
}
}
// works just like CSS transform-origin 50% 50%
pub fn centered_matrix(box_size: Vec2, input: &Mat4) -> Mat4 {
Mat4::from_translation(Vec3::new(box_size.x / 2.0, box_size.y / 2.0, 0.0))
* *input
* Mat4::from_translation(Vec3::new(-box_size.x / 2.0, -box_size.y / 2.0, 0.0))
}