shape creation works!
This commit is contained in:
parent
c50609cd64
commit
898cb5e83c
4 changed files with 369 additions and 15 deletions
19
src/helpers.rs
Normal file
19
src/helpers.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use bevy::prelude::*;
|
||||
use crate::*;
|
||||
|
||||
pub fn get_mouse_pos(q_cam: &Query<(&Camera, &GlobalTransform), With<MainCamera>>, wnds: &Windows) -> Option<Vec2> {
|
||||
let (cam, cam_pos) = q_cam.get_single().expect("More than 1 MainCamera...");
|
||||
let wnd = wnds.get_primary().expect("No window available???");
|
||||
if let Some(screen_pos) = wnd.cursor_position() {
|
||||
let w_size = Vec2::new(wnd.width() as f32, wnd.height() as f32);
|
||||
let ndc = (screen_pos / w_size) * 2.0 - Vec2::ONE;
|
||||
let ndc_to_world = cam_pos.compute_matrix() * cam.projection_matrix.inverse();
|
||||
let world_pos = ndc_to_world.project_point3(ndc.extend(-1.0));
|
||||
let world_pos: Vec2 = world_pos.truncate();
|
||||
|
||||
Some(world_pos)
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue