Skip to content
Permalink
Browse files

Check intersection with all relevant nodes to find the closest inters…

…ection
  • Loading branch information
wonder-sk committed Jun 28, 2018
1 parent 255aa9e commit 1002a140151fea511273d8af069af686a2098e7d
Showing with 14 additions and 4 deletions.
  1. +14 −4 src/3d/terrain/qgsterrainentity_p.cpp
@@ -102,21 +102,31 @@ bool QgsTerrainEntity::rayIntersection( const QgsRayCastingUtils::Ray3D &ray, QV
if ( mMap.terrainGenerator()->type() != QgsTerrainGenerator::Dem )
return false; // currently only working with DEM terrain

float minDist = -1;

QList<QgsChunkNode *> lst = activeNodes();
for ( QgsChunkNode *n : lst )
{
if ( n->entity() && QgsRayCastingUtils::rayBoxIntersection( ray, n->bbox() ) )
if ( n->entity() && ( minDist < 0 || n->bbox().distanceFromPoint( ray.origin() ) < minDist ) && QgsRayCastingUtils::rayBoxIntersection( ray, n->bbox() ) )
{
Qt3DRender::QGeometryRenderer *rend = n->entity()->findChild<Qt3DRender::QGeometryRenderer *>();
Qt3DRender::QGeometry *geom = rend->geometry();
DemTerrainTileGeometry *demGeom = static_cast<DemTerrainTileGeometry *>( geom );
Qt3DCore::QTransform *tr = n->entity()->findChild<Qt3DCore::QTransform *>();
if ( demGeom->rayIntersection( ray, tr->matrix(), intersectionPoint ) )
return true;
QVector3D nodeIntPoint;
if ( demGeom->rayIntersection( ray, tr->matrix(), nodeIntPoint ) )
{
float dist = ( ray.origin() - intersectionPoint ).length();
if ( minDist < 0 || dist < minDist )
{
minDist = dist;
intersectionPoint = nodeIntPoint;
}
}
}
}

return false;
return minDist >= 0;
}

void QgsTerrainEntity::onShowBoundingBoxesChanged()

0 comments on commit 1002a14

Please sign in to comment.
You can’t perform that action at this time.