use bevy_ecs::bundle::Bundle; use bevy_ecs::component::Component; use bevy_ecs::system::Resource; use nalgebra::Matrix3; #[derive(Component, Debug, Clone, Copy)] pub struct Translation { pub x: f32, pub y: f32, } impl Translation { pub fn as_matrix(&self) -> Matrix3 { Matrix3::from_iterator([ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, self.x, self.y, 1.0, ]) } } #[derive(Component, Debug, Clone, Copy)] pub struct Scale { pub width: f32, pub height: f32, } impl Scale { pub fn as_matrix(&self) -> Matrix3 { Matrix3::from_iterator([ self.width, 0.0, 0.0, 0.0, self.height, 0.0, 0.0, 0.0, 1.0 ]) } } #[derive(Component, Debug, Clone, Copy)] pub struct Rotation { pub radians: f32 } impl Rotation { pub fn as_matrix(&self) -> Matrix3 { let x = self.radians.cos(); let y = self.radians.sin(); Matrix3::from_iterator([ x, y, 0.0, -y, x, 0.0, 0.0, 0.0, 1.0 ]) } } #[derive(Component, Debug, Clone)] pub struct SpriteTexture { pub texture: String, } #[derive(Bundle)] pub struct SpriteBundle { pub position: Translation, pub scale: Scale, pub texture: SpriteTexture, pub rotation: Rotation } #[derive(Resource, Debug)] pub struct Camera { pub x: f32, pub y: f32, pub zoom: f32, }