Cleanup + Add velocity

This commit is contained in:
Florian RICHER 2025-06-11 22:34:54 +02:00
parent c494574389
commit 9fabacffc9
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
3 changed files with 17 additions and 19 deletions

View file

@ -6,6 +6,7 @@ pub mod vulkan_resource;
pub mod camera;
pub mod mvp;
pub mod transform;
pub mod velocity;
pub mod vertex;
pub use buffer::{AsBindableBuffer, AsIndexBuffer, AsUniformBuffer, AsVertexBuffer};
pub use command::{AsRecordable, AsRenderableMesh, AsRenderableMeshInstance};

View file

@ -1,5 +1,6 @@
use std::sync::Arc;
use bevy_ecs::resource::Resource;
use glam::{Mat4, Quat, Vec3};
use vulkano::{
Validated,
@ -12,14 +13,11 @@ use crate::core::render::primitives::{AsBindableBuffer, AsVertexBuffer};
use super::command::AsRenderableMeshInstance;
#[derive(Debug, Clone)]
#[derive(Resource, Debug, Clone)]
pub struct Transform {
pub position: Vec3,
pub rotation: Quat,
pub scale: Vec3,
// Cache to avoid unnecessary recalculations
cached_matrix: Option<Mat4>,
dirty: bool,
}
#[derive(BufferContents, Vertex, Clone, Copy, Debug)]
@ -35,8 +33,6 @@ impl Default for Transform {
position: Vec3::ZERO,
rotation: Quat::IDENTITY,
scale: Vec3::ONE,
cached_matrix: None,
dirty: true,
}
}
}
@ -47,44 +43,31 @@ impl Transform {
position,
rotation,
scale,
cached_matrix: None,
dirty: true,
}
}
pub fn rotate(&mut self, rotation: Quat) {
self.rotation *= rotation;
self.mark_dirty();
}
pub fn translate(&mut self, translation: Vec3) {
self.position += translation;
self.mark_dirty();
}
pub fn scale(&mut self, scale: Vec3) {
self.scale *= scale;
self.mark_dirty();
}
pub fn set_position(&mut self, position: Vec3) {
self.position = position;
self.mark_dirty();
}
pub fn set_rotation(&mut self, rotation: Quat) {
self.rotation = rotation;
self.mark_dirty();
}
pub fn set_scale(&mut self, scale: Vec3) {
self.scale = scale;
self.mark_dirty();
}
fn mark_dirty(&mut self) {
self.dirty = true;
self.cached_matrix = None;
}
/// Get the transformation matrix (immutable - recalculates each time)

View file

@ -0,0 +1,14 @@
use bevy_ecs::resource::Resource;
use glam::Vec3;
#[derive(Resource, Debug, Clone)]
pub struct Velocity {
pub linear: Vec3,
pub angular: Vec3,
}
impl Velocity {
pub fn new(linear: Vec3, angular: Vec3) -> Self {
Self { linear, angular }
}
}