From a066d8f6e47d63c14387ab002d30c6a87ffb1c15 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 1 May 2024 12:46:26 -0400 Subject: [PATCH] working raycasting --- CMakeLists.txt | 2 +- include/blt/gfx/raycast.h | 4 ++-- libraries/BLT | 2 +- src/blt/gfx/raycast.cpp | 16 ++++------------ 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c58f2c..0bb1e51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -set(BLT_GRAPHICS_VERSION 0.12.2) +set(BLT_GRAPHICS_VERSION 0.12.3) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/raycast.h b/include/blt/gfx/raycast.h index bcf093d..b7f1762 100644 --- a/include/blt/gfx/raycast.h +++ b/include/blt/gfx/raycast.h @@ -26,9 +26,9 @@ namespace blt::gfx { blt::vec3 calculateRay3D(float mx, float my, float width, float height, const blt::mat4x4& view, const blt::mat4x4& proj); - blt::vec3 calculateRay2D(float mx, float my, float width, float height, const blt::vec2 scale, const blt::mat4x4& view, const blt::mat4x4& proj); blt::vec3 calculateRay3D(float width, float height, const blt::mat4x4& view, const blt::mat4x4& proj); - blt::vec3 calculateRay2D(float width, float height, const blt::vec2 scale, const blt::mat4x4& view, const blt::mat4x4& proj); + blt::vec3 calculateRay2D(float mx, float my, float width, float height, const blt::vec3 scale, const blt::mat4x4& view, const blt::mat4x4& proj); + blt::vec3 calculateRay2D(float width, float height, const blt::vec3 scale, const blt::mat4x4& view, const blt::mat4x4& proj); namespace detail { diff --git a/libraries/BLT b/libraries/BLT index 0a04408..e6b4c4a 160000 --- a/libraries/BLT +++ b/libraries/BLT @@ -1 +1 @@ -Subproject commit 0a04408e70f9aa20704b8d7db9ee248dd53d57e8 +Subproject commit e6b4c4a3302c0dbc5decc506dfc4916634b049f5 diff --git a/src/blt/gfx/raycast.cpp b/src/blt/gfx/raycast.cpp index ab93c51..6ee0e31 100644 --- a/src/blt/gfx/raycast.cpp +++ b/src/blt/gfx/raycast.cpp @@ -35,33 +35,25 @@ namespace blt::gfx return calculateRay3D(static_cast(getMouseX()), static_cast(getMouseY()), width, height, view, proj); } - blt::vec3 calculateRay2D(float mx, float my, float width, float height, const blt::vec2 scale, const mat4x4& view, const mat4x4& proj) + blt::vec3 calculateRay2D(float mx, float my, float width, float height, const blt::vec3 scale, const mat4x4& view, const mat4x4& proj) { auto inv_p = proj.inverse(); blt::mat4x4 inv_v = view.inverse(); - BLT_DEBUG_STREAM << inv_v << '\n'; - BLT_TRACE_STREAM << view << '\n'; - BLT_INFO_STREAM << (inv_v * view) << '\n'; - BLT_INFO_STREAM << (view * inv_v) << '\n'; - mat4x4 scale_mat; - //scale_mat.scale(blt::vec3(scale.x(), scale.y(), 0)); + scale_mat.scale(scale); auto inv_s = scale_mat.inverse(); - //auto normalized_coords = detail::getNormalisedDeviceCoordinates(mx, my, width, height); - blt::vec2 normalized_coords(mx * 2.0 / width, my * 2.0 / height); + auto normalized_coords = detail::getNormalisedDeviceCoordinates(mx, height - my, width, height); blt::vec4 clip_coords(normalized_coords.x(), normalized_coords.y(), 0.0, 1.0f); auto scaled_coords = inv_s * clip_coords; auto eye_coords = inv_p * scaled_coords; auto world_coords = inv_v * eye_coords; - //auto world_coords = view * blt::vec4(-mx, my, 0, 1.0); - return blt::vec3(world_coords.x(), world_coords.y(), world_coords.z()); } - blt::vec3 calculateRay2D(float width, float height, const blt::vec2 scale, const blt::mat4x4& view, const blt::mat4x4& proj) + blt::vec3 calculateRay2D(float width, float height, const blt::vec3 scale, const blt::mat4x4& view, const blt::mat4x4& proj) { return calculateRay2D(static_cast(getMouseX()), static_cast(getMouseY()), width, height, scale, view, proj); }