diff --git a/src/core/render/primitives/mod.rs b/src/core/render/primitives/mod.rs index c7211a6..9061f3c 100644 --- a/src/core/render/primitives/mod.rs +++ b/src/core/render/primitives/mod.rs @@ -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}; diff --git a/src/core/render/primitives/transform.rs b/src/core/render/primitives/transform.rs index 506158c..c5a6fae 100644 --- a/src/core/render/primitives/transform.rs +++ b/src/core/render/primitives/transform.rs @@ -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, - 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) diff --git a/src/core/render/primitives/velocity.rs b/src/core/render/primitives/velocity.rs new file mode 100644 index 0000000..7663f3e --- /dev/null +++ b/src/core/render/primitives/velocity.rs @@ -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 } + } +}