Skip to content

Commit

Permalink
Apply suggestions per review
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdkon authored and wonder-sk committed Mar 5, 2025
1 parent b9dd315 commit a3a4957
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/3d/qgs3dmapscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,17 @@ void Qgs3DMapScene::updateScene( bool forceUpdate )
// Make our own projection matrix so that frustum culling done by the
// entities isn't dependent on the current near/far planes, which would then
// require multiple steps to stabilize.
QMatrix4x4 projMatrix;
projMatrix.setToIdentity();
// Just use some high values for the far plane so we don't have to custom-make the matrix.
projMatrix.perspective( camera->fieldOfView(), camera->aspectRatio(), 1, 1'000'000'000'000.0 );
// The matrix is constructed just like in QMatrix4x4::perspective(), but for
// all elements involving the near and far plane, the limit of the expression
// with the far plane going to infinity is taken.
float fovRadians = ( camera->fieldOfView() / 2.0f ) * static_cast<float>( M_PI ) / 180.0f;
float fovCotan = std::cos( fovRadians ) / std::sin( fovRadians );
QMatrix4x4 projMatrix(
fovCotan / camera->fieldOfView(), 0, 0, 0,
0, fovCotan, 0, 0,
0, 0, -1, -2,
0, 0, -1, 0
);
sceneContext.viewProjectionMatrix = projMatrix * camera->viewMatrix();


Expand Down
4 changes: 2 additions & 2 deletions src/3d/qgsvirtualpointcloudentity_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void QgsVirtualPointCloudEntity::handleSceneUpdate( const SceneContext &sceneCon
if ( !needsUpdate && box3D.isEmpty() )
continue;

QgsAABB aabb = QgsAABB::fromBox3D( box3D, mBboxesEntity->vertexDataOrigin() );
QgsAABB aabb = QgsAABB::fromBox3D( box3D, mMapSettings->origin() );
if ( !needsUpdate && Qgs3DUtils::isCullable( aabb, sceneContext.viewProjectionMatrix ) )
continue;

Expand Down Expand Up @@ -190,7 +190,7 @@ QgsRange<float> QgsVirtualPointCloudEntity::getNearFarPlaneRange( const QMatrix4
{
for ( const QgsBox3D &box : mBboxes )
{
QgsAABB aabb = QgsAABB::fromBox3D( box, mBboxesEntity->vertexDataOrigin() );
QgsAABB aabb = QgsAABB::fromBox3D( box, mMapSettings->origin() );
float bboxfnear;
float bboxffar;
Qgs3DUtils::computeBoundingBoxNearFarPlanes( aabb, viewMatrix, bboxfnear, bboxffar );
Expand Down

0 comments on commit a3a4957

Please sign in to comment.