I MADE A GRID USING WGSL
This commit is contained in:
parent
5adc76505d
commit
f43cf6728b
8 changed files with 264 additions and 163 deletions
|
@ -1,5 +1,3 @@
|
|||
#![feature(let_chains)]
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::egui;
|
||||
|
||||
|
@ -7,6 +5,7 @@ pub mod create;
|
|||
pub mod helpers;
|
||||
pub mod modify;
|
||||
pub mod ui;
|
||||
pub mod infinite_grid;
|
||||
pub use modify::modify_sys;
|
||||
pub use create::create_sys;
|
||||
pub use helpers::*;
|
||||
|
@ -17,11 +16,12 @@ pub struct SnapGrid {
|
|||
pub height: f32,
|
||||
pub snap: bool,
|
||||
pub offset: Vec2,
|
||||
pub visible: bool,
|
||||
}
|
||||
impl SnapGrid {
|
||||
pub fn snap_to_grid(&self, v: Vec2) -> Vec2 {
|
||||
if self.snap {
|
||||
let w = v - self.offset;
|
||||
let w = v - self.offset + 0.5 * Vec2::new(self.width.copysign(v.x), self.height.copysign(v.y));
|
||||
let snapped = Vec2::new(w.x - w.x % self.width, w.y - w.y % self.height);
|
||||
|
||||
snapped + self.offset
|
||||
|
@ -33,7 +33,7 @@ impl SnapGrid {
|
|||
}
|
||||
impl Default for SnapGrid {
|
||||
fn default() -> Self {
|
||||
Self { width: 15.0, height: 15.0, snap: false, offset: Vec2::ZERO }
|
||||
Self { width: 15.0, height: 15.0, snap: false, offset: Vec2::ZERO, visible: true }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue