M starkingdoms-client/src/ecs.rs => starkingdoms-client/src/ecs.rs +18 -0
@@ 19,6 19,21 @@ impl Translation {
}
#[derive(Component, Debug, Clone, Copy)]
+pub struct Shear {
+ pub x: f32,
+ pub y: f32,
+}
+impl Shear {
+ pub fn as_matrix(&self) -> Matrix3<f32> {
+ Matrix3::from_iterator([
+ 1.0, self.x, 0.0,
+ self.y, 1.0, 0.0,
+ 0.0, 0.0, 1.0,
+ ])
+ }
+}
+
+#[derive(Component, Debug, Clone, Copy)]
pub struct Scale {
pub width: f32,
pub height: f32,
@@ 56,6 71,7 @@ pub struct SpriteTexture {
#[derive(Bundle)]
pub struct SpriteBundle {
pub position: Translation,
+ pub shear: Shear,
pub scale: Scale,
pub texture: SpriteTexture,
pub rotation: Rotation
@@ 65,5 81,7 @@ pub struct SpriteBundle {
pub struct Camera {
pub x: f32,
pub y: f32,
+ pub shear_x: f32,
+ pub shear_y: f32,
pub zoom: f32,
}
M starkingdoms-client/src/lib.rs => starkingdoms-client/src/lib.rs +24 -2
@@ 6,6 6,7 @@ use bevy_ecs::event::{EventReader, Events};
use bevy_ecs::schedule::Schedule;
use bevy_ecs::system::ResMut;
use bevy_ecs::world::World;
+use ecs::Shear;
use egui::{Context, DragValue};
use tracing::info;
use winit::event_loop::{ControlFlow, EventLoop};
@@ 40,6 41,8 @@ pub fn start() {
world.insert_resource(Camera {
x: 0.0,
y: 0.0,
+ shear_x: 0.0,
+ shear_y: 0.0,
zoom: 1.0,
});
@@ 58,6 61,10 @@ pub fn start() {
x: 100.0,
y: 100.0
},
+ shear: Shear {
+ x: 0.0,
+ y: 0.0,
+ },
scale: Scale {
width: 100.0,
height: 100.0,
@@ 108,8 115,8 @@ impl UiRenderable for Gui {
ui.label("A game about floating through space");
ui.separator();
- let mut sprites = world.query::<(&mut Translation, &mut Scale, &SpriteTexture, &mut Rotation)>();
- for (mut pos, mut scale, tex, mut rot) in sprites.iter_mut(world) {
+ let mut sprites = world.query::<(&mut Translation, &mut Shear, &mut Scale, &SpriteTexture, &mut Rotation)>();
+ for (mut pos, mut shear, mut scale, tex, mut rot) in sprites.iter_mut(world) {
ui.heading(&tex.texture);
egui::Grid::new("sprite_grid")
@@ 125,6 132,14 @@ impl UiRenderable for Gui {
ui.add(DragValue::new(&mut pos.y).speed(0.1));
ui.end_row();
+ ui.label("Shear X");
+ ui.add(DragValue::new(&mut shear.x).speed(0.1));
+ ui.end_row();
+
+ ui.label("Shear Y");
+ ui.add(DragValue::new(&mut shear.y).speed(0.1));
+ ui.end_row();
+
ui.label("Width");
ui.add(DragValue::new(&mut scale.width).speed(0.1));
ui.end_row();
@@ 151,6 166,13 @@ impl UiRenderable for Gui {
ui.add(DragValue::new(&mut camera.y).speed(0.1));
ui.end_row();
+ ui.label("Shear X");
+ ui.add(DragValue::new(&mut camera.shear_x).speed(0.1));
+ ui.end_row();
+ ui.label("Shear Y");
+ ui.add(DragValue::new(&mut camera.shear_y).speed(0.1));
+ ui.end_row();
+
ui.label("Camera Zoom");
ui.add(DragValue::new(&mut camera.zoom).speed(0.1));
ui.end_row();
M starkingdoms-client/src/rendering/renderer.rs => starkingdoms-client/src/rendering/renderer.rs +9 -8
@@ 1,4 1,4 @@
-use crate::ecs::{Camera, Translation, Rotation, Scale, SpriteTexture};
+use crate::ecs::{Camera, Rotation, Scale, Shear, SpriteTexture, Translation};
use crate::rendering::mipmap::MipGenerator;
use crate::rendering::renderer::RenderInitRes::{Initialized, NotReadyYet};
use crate::rendering::texture;
@@ 243,19 243,19 @@ impl<T: UiRenderable> Renderer<T> {
label: Some("command encoder"),
});
- let mut sprites_to_render: Vec<(Translation, Scale, SpriteTexture, Rotation)> = vec![];
+ let mut sprites_to_render: Vec<(Translation, Shear, Scale, SpriteTexture, Rotation)> = vec![];
- let mut things_to_render = self.world.query::<(&Translation, &Scale, &SpriteTexture, &Rotation)>();
+ let mut things_to_render = self.world.query::<(&Translation, &Shear, &Scale, &SpriteTexture, &Rotation)>();
for thing in things_to_render.iter_mut(&mut self.world) {
- sprites_to_render.push((*thing.0, *thing.1, thing.2.clone(), *thing.3));
+ sprites_to_render.push((*thing.0, *thing.1, *thing.2, thing.3.clone(), *thing.4));
}
let cam = self.world.resource::<Camera>();
let mut frame_uniform = vec![];
let frame_uniform_values = [
- cam.zoom, 0.0, 0.0, 0.0,
- 0.0, cam.zoom, 0.0, 0.0,
+ cam.zoom, cam.shear_y,0.0, 0.0,
+ cam.shear_x,cam.zoom, 0.0, 0.0,
cam.x, cam.y, 1.0, 0.0,
self.logical_size.width as f32, self.logical_size.height as f32, 0.0, 0.0];
for i in frame_uniform_values {
@@ 265,7 265,7 @@ impl<T: UiRenderable> Renderer<T> {
self.queue.write_buffer(&self.frame_uniform, 0, &frame_uniform);
- for (pos, scale, tex, rot) in sprites_to_render {
+ for (pos, shear, scale, tex, rot) in sprites_to_render {
let tex = self.textures.entry(tex.texture.clone()).or_insert_with(|| {
info!("loading texture {}", &tex.texture);
let b: &[u8] = match tex.texture.as_str() {
@@ 284,10 284,11 @@ impl<T: UiRenderable> Renderer<T> {
});
let xy_matrix = pos.as_matrix();
+ let shear_matrix = shear.as_matrix();
let rot_matrix = rot.as_matrix();
let scale_matrix = scale.as_matrix();
- let transform_matrix = scale_matrix * rot_matrix * xy_matrix;
+ let transform_matrix = scale_matrix * shear_matrix * rot_matrix * xy_matrix;
let mut local_buffer = vec![];