Cleanup + Add velocity
This commit is contained in:
parent
c494574389
commit
9fabacffc9
3 changed files with 17 additions and 19 deletions
|
@ -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};
|
||||
|
|
|
@ -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)
|
||||
|
|
14
src/core/render/primitives/velocity.rs
Normal file
14
src/core/render/primitives/velocity.rs
Normal 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 }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue