mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Check intersection with all relevant nodes to find the closest intersection
This commit is contained in:
parent
255aa9e00b
commit
1002a14015
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user