mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
mouse picking improvements: filter out backfacing; include near plane in ray origin computation
This commit is contained in:
@@ -386,12 +386,21 @@ bool NvRenderer::Render() {
|
||||
(static_cast<glm::dvec2>(Global.cursor_pos) /
|
||||
static_cast<glm::dvec2>(Global.window_size) -
|
||||
.5);
|
||||
m_mouse_ro = pass.m_origin;
|
||||
glm::dvec4 mouse_rd_norm =
|
||||
inverse(projection) * glm::dvec4(mousepos, 1., 1.);
|
||||
mouse_rd_norm /= mouse_rd_norm.w;
|
||||
m_mouse_rd =
|
||||
normalize(inverse(transform) * glm::dvec4(mouse_rd_norm.xyz, 0.));
|
||||
{
|
||||
glm::dvec4 mouse_ro_norm =
|
||||
inverse(projection) * glm::dvec4(mousepos, 1., 1.);
|
||||
mouse_ro_norm /= mouse_ro_norm.w;
|
||||
m_mouse_ro = pass.m_origin + static_cast<glm::dvec3>(
|
||||
inverse(transform) *
|
||||
glm::dvec4(mouse_ro_norm.xyz, 1.));
|
||||
}
|
||||
{
|
||||
glm::dvec4 mouse_rd_norm =
|
||||
inverse(projection) * glm::dvec4(mousepos, 0., 1.);
|
||||
mouse_rd_norm /= mouse_rd_norm.w;
|
||||
m_mouse_rd =
|
||||
normalize(inverse(transform) * glm::dvec4(mouse_rd_norm.xyz, 0.));
|
||||
}
|
||||
}
|
||||
|
||||
m_picked_submodel = nullptr;
|
||||
|
||||
@@ -137,7 +137,9 @@ const TSubModel* Rt::RtModel::Intersect(
|
||||
[&](size_t const begin, size_t const end) {
|
||||
for (size_t i = begin; i < end; ++i) {
|
||||
size_t const j = submodel.bvh.prim_ids[i];
|
||||
if (auto hit = submodel.tris[j].intersect(ray)) {
|
||||
if (auto hit = submodel.tris[j].intersect(ray);
|
||||
!!hit && dot(rd_local, glm::make_vec3(
|
||||
submodel.tris[j].n.values)) > 0.) {
|
||||
prim_id = i;
|
||||
std::tie(ray.tmax, u, v) = *hit;
|
||||
result = submodel.submodel;
|
||||
|
||||
Reference in New Issue
Block a user