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 camera;
|
||||||
pub mod mvp;
|
pub mod mvp;
|
||||||
pub mod transform;
|
pub mod transform;
|
||||||
|
pub mod velocity;
|
||||||
pub mod vertex;
|
pub mod vertex;
|
||||||
pub use buffer::{AsBindableBuffer, AsIndexBuffer, AsUniformBuffer, AsVertexBuffer};
|
pub use buffer::{AsBindableBuffer, AsIndexBuffer, AsUniformBuffer, AsVertexBuffer};
|
||||||
pub use command::{AsRecordable, AsRenderableMesh, AsRenderableMeshInstance};
|
pub use command::{AsRecordable, AsRenderableMesh, AsRenderableMeshInstance};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use bevy_ecs::resource::Resource;
|
||||||
use glam::{Mat4, Quat, Vec3};
|
use glam::{Mat4, Quat, Vec3};
|
||||||
use vulkano::{
|
use vulkano::{
|
||||||
Validated,
|
Validated,
|
||||||
|
@ -12,14 +13,11 @@ use crate::core::render::primitives::{AsBindableBuffer, AsVertexBuffer};
|
||||||
|
|
||||||
use super::command::AsRenderableMeshInstance;
|
use super::command::AsRenderableMeshInstance;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Resource, Debug, Clone)]
|
||||||
pub struct Transform {
|
pub struct Transform {
|
||||||
pub position: Vec3,
|
pub position: Vec3,
|
||||||
pub rotation: Quat,
|
pub rotation: Quat,
|
||||||
pub scale: Vec3,
|
pub scale: Vec3,
|
||||||
// Cache to avoid unnecessary recalculations
|
|
||||||
cached_matrix: Option<Mat4>,
|
|
||||||
dirty: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(BufferContents, Vertex, Clone, Copy, Debug)]
|
#[derive(BufferContents, Vertex, Clone, Copy, Debug)]
|
||||||
|
@ -35,8 +33,6 @@ impl Default for Transform {
|
||||||
position: Vec3::ZERO,
|
position: Vec3::ZERO,
|
||||||
rotation: Quat::IDENTITY,
|
rotation: Quat::IDENTITY,
|
||||||
scale: Vec3::ONE,
|
scale: Vec3::ONE,
|
||||||
cached_matrix: None,
|
|
||||||
dirty: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,44 +43,31 @@ impl Transform {
|
||||||
position,
|
position,
|
||||||
rotation,
|
rotation,
|
||||||
scale,
|
scale,
|
||||||
cached_matrix: None,
|
|
||||||
dirty: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rotate(&mut self, rotation: Quat) {
|
pub fn rotate(&mut self, rotation: Quat) {
|
||||||
self.rotation *= rotation;
|
self.rotation *= rotation;
|
||||||
self.mark_dirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn translate(&mut self, translation: Vec3) {
|
pub fn translate(&mut self, translation: Vec3) {
|
||||||
self.position += translation;
|
self.position += translation;
|
||||||
self.mark_dirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scale(&mut self, scale: Vec3) {
|
pub fn scale(&mut self, scale: Vec3) {
|
||||||
self.scale *= scale;
|
self.scale *= scale;
|
||||||
self.mark_dirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_position(&mut self, position: Vec3) {
|
pub fn set_position(&mut self, position: Vec3) {
|
||||||
self.position = position;
|
self.position = position;
|
||||||
self.mark_dirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_rotation(&mut self, rotation: Quat) {
|
pub fn set_rotation(&mut self, rotation: Quat) {
|
||||||
self.rotation = rotation;
|
self.rotation = rotation;
|
||||||
self.mark_dirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_scale(&mut self, scale: Vec3) {
|
pub fn set_scale(&mut self, scale: Vec3) {
|
||||||
self.scale = scale;
|
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)
|
/// 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