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 | |
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')
-rw-r--r-- | client/src/scene_prepare.rs | 6 | ||||
-rw-r--r-- | client/src/ui.rs | 19 |
2 files changed, 16 insertions, 9 deletions
diff --git a/client/src/scene_prepare.rs b/client/src/scene_prepare.rs index 36761a0..57d44b0 100644 --- a/client/src/scene_prepare.rs +++ b/client/src/scene_prepare.rs @@ -17,7 +17,7 @@ use crate::download::Downloader; use anyhow::Result; use image::ImageReader; -use log::{debug, info}; +use log::debug; use std::{ collections::{HashMap, HashSet}, hash::Hash, @@ -193,7 +193,7 @@ impl ScenePreparer { image.height(), ); self.textures.insert(pres.clone(), tex_bg); - info!( + debug!( "texture created (res={}x{}, took {:?})", dims.0, dims.1, @@ -202,7 +202,7 @@ impl ScenePreparer { } } for variant in self.placeholder_textures.needed() { - let v = if variant { 1 } else { 0 }; + let v = if variant { 255 } else { 0 }; let tex_bg = create_texture( &self.device, &self.queue, 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(); |