diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-12 03:01:23 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-12 03:01:23 +0100 |
commit | c626006c767f21d1ba0d452b64e244c7d69fa09b (patch) | |
tree | 92ec926e01918b2ebb4e7c9e535bb3b71fc5c01b /client/src/ui.rs | |
parent | 8782d510ed5d2c3314dc589210505786833decf5 (diff) | |
download | weareserver-c626006c767f21d1ba0d452b64e244c7d69fa09b.tar weareserver-c626006c767f21d1ba0d452b64e244c7d69fa09b.tar.bz2 weareserver-c626006c767f21d1ba0d452b64e244c7d69fa09b.tar.zst |
ui projection almost works. but scaling is wrong
Diffstat (limited to 'client/src/ui.rs')
-rw-r--r-- | client/src/ui.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/client/src/ui.rs b/client/src/ui.rs index be206b5..a5ff775 100644 --- a/client/src/ui.rs +++ b/client/src/ui.rs @@ -20,7 +20,7 @@ use egui::{ epaint::{ImageDelta, Primitive, Vertex}, }; use glam::{Affine3A, Mat2, Mat3, Mat4, Vec2, Vec3Swizzles, Vec4Swizzles, vec2, vec4}; -use log::info; +use log::{info, warn}; use rand::random; use std::{ collections::HashMap, @@ -338,20 +338,27 @@ impl UiRenderer { let mouse_xy_clip = (input_state.cursor_pos / screen_size) * 2. - 1.; - let iproject = projection.inverse(); + if projection.determinant() < 0e-4 { + warn!("bad UI projection") + } - let mut mouse_world_1 = iproject * vec4(mouse_xy_clip.x, mouse_xy_clip.y, 0.0, 1.0); - let mut mouse_world_2 = iproject * vec4(mouse_xy_clip.x, mouse_xy_clip.y, 1.0, 1.0); + let unproject = projection.inverse(); + let mut mouse_world_1 = unproject * vec4(mouse_xy_clip.x, -mouse_xy_clip.y, 0.0, 1.0); + let mut mouse_world_2 = unproject * vec4(mouse_xy_clip.x, -mouse_xy_clip.y, 1.0, 1.0); mouse_world_1 /= mouse_world_1.w; mouse_world_2 /= mouse_world_2.w; - let mouse_world_1 = mouse_world_1.xyz(); let mouse_world_2 = mouse_world_2.xyz(); let ray_norm = (mouse_world_2 - mouse_world_1).normalize(); let ray_t = mouse_world_1.z / ray_norm.z; - let ray_hit = mouse_world_1 + ray_norm * ray_t; + let ray_hit = mouse_world_1 - ray_norm * ray_t; + + debug_assert!(ray_hit.z.abs() < 0.1, "mouse was not projected properly"); + + eprintln!("z={} t={ray_t}", mouse_world_1.z); + eprintln!("hit={ray_hit}"); let cursor_pos = ray_hit.xy(); |