working raycasting
parent
2afdfbf3a9
commit
a066d8f6e4
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 3.25)
|
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)
|
set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
|
||||||
|
|
||||||
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})
|
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})
|
||||||
|
|
|
@ -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 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 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
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 0a04408e70f9aa20704b8d7db9ee248dd53d57e8
|
Subproject commit e6b4c4a3302c0dbc5decc506dfc4916634b049f5
|
|
@ -35,33 +35,25 @@ namespace blt::gfx
|
||||||
return calculateRay3D(static_cast<float>(getMouseX()), static_cast<float>(getMouseY()), width, height, view, proj);
|
return calculateRay3D(static_cast<float>(getMouseX()), static_cast<float>(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();
|
auto inv_p = proj.inverse();
|
||||||
blt::mat4x4 inv_v = view.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;
|
mat4x4 scale_mat;
|
||||||
//scale_mat.scale(blt::vec3(scale.x(), scale.y(), 0));
|
scale_mat.scale(scale);
|
||||||
auto inv_s = scale_mat.inverse();
|
auto inv_s = scale_mat.inverse();
|
||||||
|
|
||||||
//auto normalized_coords = detail::getNormalisedDeviceCoordinates(mx, my, width, height);
|
auto normalized_coords = detail::getNormalisedDeviceCoordinates(mx, height - my, width, height);
|
||||||
blt::vec2 normalized_coords(mx * 2.0 / width, my * 2.0 / height);
|
|
||||||
blt::vec4 clip_coords(normalized_coords.x(), normalized_coords.y(), 0.0, 1.0f);
|
blt::vec4 clip_coords(normalized_coords.x(), normalized_coords.y(), 0.0, 1.0f);
|
||||||
auto scaled_coords = inv_s * clip_coords;
|
auto scaled_coords = inv_s * clip_coords;
|
||||||
auto eye_coords = inv_p * scaled_coords;
|
auto eye_coords = inv_p * scaled_coords;
|
||||||
auto world_coords = inv_v * eye_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());
|
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<float>(getMouseX()), static_cast<float>(getMouseY()), width, height, scale, view, proj);
|
return calculateRay2D(static_cast<float>(getMouseX()), static_cast<float>(getMouseY()), width, height, scale, view, proj);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue