tirbofish/dropbear · commit
d18cb60e38502095cea8a533bca61b0f0add9f26
wip: implementing new classes such as SceneMetadata.kt, ResourceReference.kt and AssetEntry.kt
wip: attempts to do viewport clicking within the editor. would be good for stuff like interactive UI in billboarding (idk if its implemented yet).
fix: changed default ambient strength to 0.1 instead of 1.0 to not make it look like its bad
Signature present but could not be verified.
Unverified
@@ -1,6 +1,7 @@ //! Input management and input state. pub mod gamepad; +pub mod ndc; use crate::scripting::jni::utils::ToJObject; use crate::scripting::native::DropbearNativeError; @@ -0,0 +1,62 @@ +use glam::{Vec3, Mat4, Vec4}; + +/// Helpers for converting from a 2D display to a 3D object, such as billboard ui and some +/// other applications. +// viewport aint even work lmaoooo +pub struct NormalisedDeviceCoordinates; + +impl NormalisedDeviceCoordinates { + pub fn screen_to_ray( + touch_pos: impl Into<[f32; 2]>, + screen_dims: impl Into<[f32; 2]>, + inv_proj: Mat4, + inv_view: Mat4, + ) -> (Vec3, Vec3) { + let [touch_x, touch_y] = touch_pos.into(); + let [screen_width, screen_height] = screen_dims.into(); + + let ndc_x = (touch_x / screen_width) * 2.0 - 1.0; + let ndc_y = -(touch_y / screen_height) * 2.0 + 1.0; // flip Y, screen Y is down + + // unproject to view space + let clip_near = Vec4::new(ndc_x, ndc_y, 0.0, 1.0); // z=0 = near plane + let mut view_near = inv_proj * clip_near; + view_near /= view_near.w; + + // to world space + let world_near = inv_view * view_near; + + // ray origin = camera position, direction = toward unprojected point + let ray_origin = (inv_view * Vec4::new(0.0, 0.0, 0.0, 1.0)).truncate(); + let ray_dir = (world_near.truncate() - ray_origin).normalize(); +
Large diffs are not rendered by default. Showing the first 50 of 5670 lines. Show full diff