35#include <QDomDocument>
38#include <QStringLiteral>
40#include <Qt3DRender/QCamera>
42#include "moc_qgscameracontroller.cpp"
44using namespace Qt::StringLiterals;
49 , mCamera( scene->engine()->
camera() )
51 , mMouseHandler( new
Qt3DInput::QMouseHandler )
52 , mKeyboardHandler( new
Qt3DInput::QKeyboardHandler )
53 , mOrigin( scene->mapSettings()->
origin() )
60 connect( mPointerLocker, &QgsPointerLocker::pointerMoved,
this, [
this](
double dx,
double dy ) {
61 if ( !mCaptureFpsMouseMovements || !mInputHandlersEnabled )
63 applyRelativePointerRotation( dx, dy );
68 mMouseHandler->setSourceDevice(
new Qt3DInput::QMouseDevice() );
69 connect( mMouseHandler, &Qt3DInput::QMouseHandler::positionChanged,
this, &QgsCameraController::onPositionChanged );
70 connect( mMouseHandler, &Qt3DInput::QMouseHandler::wheel,
this, &QgsCameraController::onWheel );
71 connect( mMouseHandler, &Qt3DInput::QMouseHandler::pressed,
this, &QgsCameraController::onMousePressed );
72 connect( mMouseHandler, &Qt3DInput::QMouseHandler::released,
this, &QgsCameraController::onMouseReleased );
73 addComponent( mMouseHandler );
76 connect(
this, &Qt3DCore::QEntity::enabledChanged, mMouseHandler, &Qt3DInput::QMouseHandler::setEnabled );
77 connect(
this, &Qt3DCore::QEntity::enabledChanged, mKeyboardHandler, &Qt3DInput::QKeyboardHandler::setEnabled );
79 mFpsNavTimer =
new QTimer(
this );
80 mFpsNavTimer->setInterval( 10 );
81 connect( mFpsNavTimer, &QTimer::timeout,
this, &QgsCameraController::applyFlyModeKeyMovements );
82 mFpsNavTimer->start();
87 mGlobeCrsToLatLon =
QgsCoordinateTransform( mScene->mapSettings()->crs(), mScene->mapSettings()->crs().toGeographicCrs(), mScene->mapSettings()->transformContext() );
93QWindow *QgsCameraController::window()
const
96 return windowEngine ? windowEngine->
window() :
nullptr;
101 if ( navigationMode == mCameraNavigationMode )
104 mCameraNavigationMode = navigationMode;
105 mIgnoreNextMouseMove =
true;
111 if ( movementSpeed == mCameraMovementSpeed )
116 mCameraMovementSpeed = std::clamp( movementSpeed, 0.05, 150.0 );
122 mVerticalAxisInversion = inversion;
127 float newPitch = mCameraPose.pitchAngle() + diffPitch;
128 float newHeading = mCameraPose.headingAngle() + diffHeading;
130 newPitch = std::clamp( newPitch, 0.f, 180.f );
132 switch ( mScene->mapSettings()->sceneMode() )
143 viewCenterLatLon = mGlobeCrsToLatLon.transform( mCameraPose.centerPoint() + mOrigin );
147 QgsDebugError( u
"rotateCamera: ECEF -> lat,lon transform failed!"_s );
150 QQuaternion qLatLon = QQuaternion::fromAxisAndAngle( QVector3D( 0, 0, 1 ),
static_cast<float>( viewCenterLatLon.
x() ) )
151 * QQuaternion::fromAxisAndAngle( QVector3D( 0, -1, 0 ),
static_cast<float>( viewCenterLatLon.
y() ) );
152 QQuaternion qPitchHeading = QQuaternion::fromAxisAndAngle( QVector3D( 1, 0, 0 ), newHeading ) * QQuaternion::fromAxisAndAngle( QVector3D( 0, 1, 0 ), newPitch );
153 QVector3D newCameraToCenter = ( qLatLon * qPitchHeading * QVector3D( -1, 0, 0 ) ) * mCameraPose.distanceFromCenterPoint();
155 mCameraPose.setCenterPoint( mCamera->position() + newCameraToCenter );
156 mCameraPose.setPitchAngle( newPitch );
157 mCameraPose.setHeadingAngle( newHeading );
158 updateCameraFromPose();
165 QVector3D newCameraToCenter = q * QVector3D( 0, 0, -mCameraPose.distanceFromCenterPoint() );
166 mCameraPose.setCenterPoint( mCamera->position() + newCameraToCenter );
167 mCameraPose.setPitchAngle( newPitch );
168 mCameraPose.setHeadingAngle( newHeading );
169 updateCameraFromPose();
177 const float oldPitch = mCameraPose.pitchAngle();
178 const float oldHeading = mCameraPose.headingAngle();
180 newPitch = std::clamp( newPitch, 0.f, 180.f );
186 const QQuaternion q = qNew * qOld.conjugated();
188 const QVector3D newViewCenter = q * ( mCamera->viewCenter() - pivotPoint ) + pivotPoint;
190 mCameraPose.setCenterPoint( newViewCenter );
191 mCameraPose.setPitchAngle( newPitch );
192 mCameraPose.setHeadingAngle( newHeading );
193 updateCameraFromPose();
199 QVector3D newCamPosition = pivotPoint + ( oldCameraPosition - pivotPoint ) * zoomFactor;
200 double newDistance = mCameraPose.distanceFromCenterPoint() * zoomFactor;
204 QVector3D cameraToCenter = q * QVector3D( 0, 0, -newDistance );
205 QVector3D newViewCenter = newCamPosition + cameraToCenter;
207 mCameraPose.setDistanceFromCenterPoint( newDistance );
208 mCameraPose.setCenterPoint( newViewCenter );
209 updateCameraFromPose();
215 QVector3D newCamPosition = pivotPoint + ( oldCameraPosition - pivotPoint ) * zoomFactor;
216 const double newDistance = oldDistanceFromCenterPoint * zoomFactor;
220 QVector3D cameraToCenter = q * QVector3D( 0, 0, -newDistance );
221 QVector3D newViewCenter = newCamPosition + cameraToCenter;
223 mCameraPose.setDistanceFromCenterPoint( newDistance );
224 mCameraPose.setCenterPoint( newViewCenter );
225 updateCameraFromPose();
233 updateOrthographicProjectionPlane();
235 if ( mCameraChanged )
238 mCameraChanged =
false;
244 QgsPointXY extentCenter = mScene->mapSettings()->extent().center();
253 QgsDebugError( u
"setViewFromTop() should not be used with globe!"_s );
258 QgsTerrainEntity *terrain = mScene->terrainEntity();
259 const float terrainElevationOffset = terrain ? terrain->terrainElevationOffset() : 0.0f;
265 mCamera->setNearPlane(
distance / 2 );
266 mCamera->setFarPlane(
distance * 2 );
273 return mCameraPose.centerPoint();
298 if ( camPose == mCameraPose && !force )
301 mCameraPose = camPose;
302 updateCameraFromPose();
307 QDomElement elemCamera = doc.createElement( u
"camera"_s );
310 QgsVector3D centerPoint = mCameraPose.centerPoint() + mOrigin;
311 elemCamera.setAttribute( u
"xMap"_s, centerPoint.
x() );
312 elemCamera.setAttribute( u
"yMap"_s, centerPoint.
y() );
313 elemCamera.setAttribute( u
"zMap"_s, centerPoint.
z() );
314 elemCamera.setAttribute( u
"dist"_s, mCameraPose.distanceFromCenterPoint() );
315 elemCamera.setAttribute( u
"pitch"_s, mCameraPose.pitchAngle() );
316 elemCamera.setAttribute( u
"yaw"_s, mCameraPose.headingAngle() );
322 const float dist = elem.attribute( u
"dist"_s ).toFloat();
323 const float pitch = elem.attribute( u
"pitch"_s ).toFloat();
324 const float yaw = elem.attribute( u
"yaw"_s ).toFloat();
327 if ( elem.hasAttribute(
"xMap" ) )
330 const double x = elem.attribute( u
"xMap"_s ).toDouble();
331 const double y = elem.attribute( u
"yMap"_s ).toDouble();
332 const double z = elem.attribute( u
"zMap"_s ).toDouble();
338 const double x = elem.attribute( u
"x"_s ).toDouble();
339 const double y = elem.attribute( u
"y"_s ).toDouble();
340 const double elev = elem.attribute( u
"elev"_s ).toDouble();
341 centerPoint =
QgsVector3D( x, elev, y ) - savedOrigin + mOrigin;
348 if ( !mDepthBufferIsReady )
350 QgsDebugError( u
"Asked to sample depth buffer, but depth buffer not ready!"_s );
355 if ( QWindow *win = window() )
359 px =
static_cast<int>( px * win->devicePixelRatio() );
360 py =
static_cast<int>( py * win->devicePixelRatio() );
364 for (
int x = px - 3; x <= px + 3; ++x )
366 for (
int y = py - 3; y <= py + 3; ++y )
368 if ( mDepthBufferImage.valid( x, y ) )
377double QgsCameraController::depthBufferNonVoidAverage()
380 if ( mDepthBufferNonVoidAverage != -1 )
381 return mDepthBufferNonVoidAverage;
385 int samplesCount = 0;
387 Q_ASSERT( mDepthBufferImage.format() == QImage::Format_RGB32 );
388 for (
int y = 0; y < mDepthBufferImage.height(); ++y )
390 const QRgb *line =
reinterpret_cast<const QRgb *
>( mDepthBufferImage.constScanLine( y ) );
391 for (
int x = 0; x < mDepthBufferImage.width(); ++x )
403 if ( samplesCount == 0 )
406 depth /= samplesCount;
408 mDepthBufferNonVoidAverage = depth;
413QgsVector3D QgsCameraController::moveGeocentricPoint(
const QgsVector3D &point,
double latDiff,
double lonDiff )
417 QgsVector3D pointLatLon = mGlobeCrsToLatLon.transform( point );
418 pointLatLon.
setX( pointLatLon.
x() + lonDiff );
419 pointLatLon.
setY( std::clamp( pointLatLon.
y() + latDiff, -90., 90. ) );
423 catch (
const QgsCsException & )
425 QgsDebugError( u
"moveGeocentricPoint: transform failed!"_s );
430void QgsCameraController::applyRelativePointerRotation(
double dx,
double dy )
432 float diffPitch = -0.2f *
static_cast<float>( dy );
436 const float diffYaw = -0.2f *
static_cast<float>( dx );
442 const QgsVector3D viewCenter = mCameraPose.centerPoint() + mOrigin;
443 const QgsVector3D newViewCenter = moveGeocentricPoint( viewCenter, latDiff, lonDiff );
444 mCameraPose.setCenterPoint( newViewCenter - mOrigin );
445 updateCameraFromPose();
450 mCameraPose.setDistanceFromCenterPoint( mCameraPose.distanceFromCenterPoint() * factor );
451 updateCameraFromPose();
456 mCameraPose.setPitchAngle( std::clamp( mCameraPose.pitchAngle() + angleDiff, 0.f, 90.f ) );
457 updateCameraFromPose();
462 mCameraPose.setHeadingAngle( mCameraPose.headingAngle() + angleDiff );
463 updateCameraFromPose();
485void QgsCameraController::updateOrthographicProjectionPlane()
491 const QSize viewportRect = mScene->
engine()->
size();
492 const float viewWidthFromCenter =
distance();
493 const float viewHeightFromCenter =
distance() *
static_cast<float>( viewportRect.height() ) /
static_cast<float>( viewportRect.width() );
494 mCamera->lens()->setOrthographicProjection( -viewWidthFromCenter, viewWidthFromCenter, -viewHeightFromCenter, viewHeightFromCenter, mCamera->nearPlane(), mCamera->farPlane() );
498void QgsCameraController::updateCameraFromPose()
504 const QgsVector3D viewCenter = mCameraPose.centerPoint() + mOrigin;
506 QgsVector3D viewCenterLatLon;
509 viewCenterLatLon = mGlobeCrsToLatLon.transform( viewCenter );
511 catch (
const QgsCsException & )
513 QgsDebugError( u
"updateCameraFromPose: transform failed!"_s );
517 mCameraPose.updateCameraGlobe( mCamera, viewCenterLatLon.
y(), viewCenterLatLon.
x() );
521 mCameraPose.updateCamera( mCamera );
524 updateOrthographicProjectionPlane();
526 mCameraChanged =
true;
532 mCameraPose.setCenterPoint( mCameraPose.centerPoint() + posDiff );
533 updateCameraFromPose();
536void QgsCameraController::onPositionChanged( Qt3DInput::QMouseEvent *mouse )
538 if ( !mInputHandlersEnabled )
541 QgsScopedEvent traceEvent( u
"3D"_s, u
"QgsCameraController::onPositionChanged"_s );
543 switch ( mCameraNavigationMode )
546 onPositionChangedTerrainNavigation( mouse );
550 onPositionChangedFlyNavigation( mouse );
554 onPositionChangedGlobeTerrainNavigation( mouse );
559bool QgsCameraController::screenPointToWorldPos( QPoint position,
double &depth, QVector3D &worldPosition )
567 depth = depthBufferNonVoidAverage();
571 if ( !std::isfinite( worldPosition.x() ) || !std::isfinite( worldPosition.y() ) || !std::isfinite( worldPosition.z() ) )
573 QgsDebugMsgLevel( u
"screenPointToWorldPos: position is NaN or Inf. This should not happen."_s, 2 );
580void QgsCameraController::onPositionChangedTerrainNavigation( Qt3DInput::QMouseEvent *mouse )
582 if ( mIgnoreNextMouseMove )
584 mIgnoreNextMouseMove =
false;
585 mMousePos = QPoint( mouse->x(), mouse->y() );
589 const int dx = mouse->x() - mMousePos.x();
590 const int dy = mouse->y() - mMousePos.y();
592 const bool hasShift = ( mouse->modifiers() & Qt3DInput::QMouseEvent::Modifiers::ShiftModifier );
593 const bool hasCtrl = ( mouse->modifiers() & Qt3DInput::QMouseEvent::Modifiers::ControlModifier );
594 const bool hasLeftButton = ( mouse->buttons() & Qt::LeftButton );
595 const bool hasMiddleButton = ( mouse->buttons() & Qt::MiddleButton );
596 const bool hasRightButton = ( mouse->buttons() & Qt::RightButton );
598 if ( ( hasLeftButton && hasShift && !hasCtrl ) || ( hasMiddleButton && !hasShift && !hasCtrl ) )
601 setMouseParameters( MouseOperation::RotationCenter, mMousePos );
603 float scale =
static_cast<float>( std::max( mScene->engine()->size().width(), mScene->engine()->size().height() ) );
604 float pitchDiff = -180.0f *
static_cast<float>( mouse->y() - mClickPoint.y() ) / scale;
605 float yawDiff = -180.0f *
static_cast<float>( mouse->x() - mClickPoint.x() ) / scale;
610 if ( !mDepthBufferIsReady )
613 if ( !mRotationCenterCalculated )
616 QVector3D worldPosition;
617 if ( screenPointToWorldPos( mClickPoint, depth, worldPosition ) )
619 mRotationCenter = worldPosition;
620 mRotationDistanceFromCenter = ( mRotationCenter - mCameraBefore->position() ).length();
622 mRotationCenterCalculated =
true;
628 else if ( hasLeftButton && hasCtrl && !hasShift )
630 setMouseParameters( MouseOperation::RotationCamera );
632 applyRelativePointerRotation( dx, dy );
634 else if ( hasLeftButton && !hasShift && !hasCtrl )
637 setMouseParameters( MouseOperation::Translation, mMousePos );
639 if ( !mDepthBufferIsReady )
642 if ( !mDragPointCalculated )
645 QVector3D worldPosition;
646 if ( screenPointToWorldPos( mClickPoint, depth, worldPosition ) )
649 mDragPoint = worldPosition;
650 mDragPointCalculated =
true;
654 QVector3D cameraBeforeDragPos = mCameraBefore->position();
657 QVector3D shiftVector;
660 float angle = std::fabs( std::acos( QVector3D::dotProduct( QVector3D( 0, 0, 1 ), mCameraBefore->viewVector().normalized() ) ) - M_PI / 2 );
661 bool changeAltitude =
false;
663 switch ( mScene->mapSettings()->projectionType() )
666 changeAltitude =
angle < M_PI / 30;
669 changeAltitude =
angle < M_PI / 3;
675 if ( changeAltitude )
676 shiftVector = mDragPoint - moveToPosition;
678 switch ( mScene->mapSettings()->projectionType() )
685 shiftVector = { mDragPoint.x() - moveToPosition.x(), mDragPoint.y() - moveToPosition.y(), 0 };
690 QVector3D cameraBeforeToMoveToPos = ( moveToPosition - mCameraBefore->position() ).normalized();
691 QVector3D cameraBeforeToDragPointPos = ( mDragPoint - mCameraBefore->position() ).normalized();
694 if ( cameraBeforeToMoveToPos.z() == 0 )
696 cameraBeforeToMoveToPos.setZ( 0.01 );
697 cameraBeforeToMoveToPos = cameraBeforeToMoveToPos.normalized();
700 if ( cameraBeforeToDragPointPos.z() == 0 )
702 cameraBeforeToDragPointPos.setZ( 0.01 );
703 cameraBeforeToDragPointPos = cameraBeforeToDragPointPos.normalized();
706 float d1 = ( mDragPoint.z() - cameraBeforeDragPos.z() ) / cameraBeforeToMoveToPos.z();
707 float d2 = ( mDragPoint.z() - cameraBeforeDragPos.z() ) / cameraBeforeToDragPointPos.z();
709 QVector3D from = cameraBeforeDragPos + d1 * cameraBeforeToMoveToPos;
710 QVector3D to = cameraBeforeDragPos + d2 * cameraBeforeToDragPointPos;
712 shiftVector = to - from;
719 mCameraPose.setCenterPoint( mCameraBefore->viewCenter() + shiftVector );
720 updateCameraFromPose();
722 else if ( hasLeftButton && hasShift && hasCtrl )
725 QgsVector3D center = mCameraPose.centerPoint();
726 double tElev = mMousePos.y() - mouse->y();
727 center.
set( center.
x(), center.
y(), center.
z() + tElev * 0.5 );
728 mCameraPose.setCenterPoint( center );
729 updateCameraFromPose();
731 else if ( hasRightButton && !hasShift && !hasCtrl )
733 setMouseParameters( MouseOperation::Zoom, mMousePos );
734 if ( !mDepthBufferIsReady )
737 if ( !mDragPointCalculated )
740 QVector3D worldPosition;
741 if ( screenPointToWorldPos( mClickPoint, depth, worldPosition ) )
743 mDragPoint = worldPosition;
744 mDragPointCalculated =
true;
748 const double oldDist = ( QgsVector3D( mCameraBefore->position() ) - QgsVector3D( mDragPoint ) ).length();
749 double newDist = oldDist;
752 int screenHeight = mScene->engine()->size().height();
753 QWindow *win = window();
756 yOffset = win->mapToGlobal( QPoint( 0, 0 ) ).y();
757 screenHeight = win->screen()->virtualSize().height();
761 if ( mMousePos.y() > mClickPoint.y() )
763 double f = ( double ) ( mMousePos.y() - mClickPoint.y() ) / ( double ) ( screenHeight - mClickPoint.y() - yOffset );
764 f = std::max( 0.0, std::min( 1.0, f ) );
765 f = 1 - ( std::expm1( -2 * f ) ) / ( std::expm1( -2 ) );
766 newDist = newDist * f;
770 double f = 1 - ( double ) ( mMousePos.y() + yOffset ) / ( double ) ( mClickPoint.y() + yOffset );
771 f = std::max( 0.0, std::min( 1.0, f ) );
772 f = ( std::expm1( 2 * f ) ) / ( std::expm1( 2 ) );
773 newDist = newDist + 2 * newDist * f;
776 const double zoomFactor = newDist / oldDist;
777 zoomCameraAroundPivot( mCameraBefore->position(), mCameraBefore->viewCenter().distanceToPoint( mCameraBefore->position() ), zoomFactor, mDragPoint );
780 mMousePos = QPoint( mouse->x(), mouse->y() );
783void QgsCameraController::onPositionChangedGlobeTerrainNavigation( Qt3DInput::QMouseEvent *mouse )
785 const bool hasShift = ( mouse->modifiers() & Qt3DInput::QMouseEvent::Modifiers::ShiftModifier );
786 const bool hasCtrl = ( mouse->modifiers() & Qt3DInput::QMouseEvent::Modifiers::ControlModifier );
787 const bool hasLeftButton = ( mouse->buttons() & Qt::LeftButton );
788 const bool hasMiddleButton = ( mouse->buttons() & Qt::MiddleButton );
790 if ( ( hasLeftButton && hasShift && !hasCtrl ) || ( hasMiddleButton && !hasShift && !hasCtrl ) )
792 setMouseParameters( MouseOperation::RotationCenter, mMousePos );
794 const float scale =
static_cast<float>( std::max( mScene->engine()->size().width(), mScene->engine()->size().height() ) );
795 float pitchDiff = -180.0f *
static_cast<float>( mouse->y() - mClickPoint.y() ) / scale;
796 const float yawDiff = -180.0f *
static_cast<float>( mouse->x() - mClickPoint.x() ) / scale;
801 mCameraPose.setPitchAngle( mRotationPitch + pitchDiff );
802 mCameraPose.setHeadingAngle( mRotationYaw + yawDiff );
803 updateCameraFromPose();
807 if ( !( mouse->buttons() & Qt::LeftButton ) )
811 setMouseParameters( MouseOperation::Translation, mMousePos );
813 if ( !mDepthBufferIsReady )
816 if ( !mDragPointCalculated )
819 QVector3D worldPosition;
820 if ( !screenPointToWorldPos( mClickPoint, depth, worldPosition ) )
824 mDragPoint = worldPosition;
825 mDragPointCalculated =
true;
830 const QgsVector3D startPosMap = QgsVector3D( mDragPoint ) + mOrigin;
831 const double sphereRadiusMap = startPosMap.
length();
834 const QgsVector3D rayOriginMap = QgsVector3D( ray.
origin() ) + mOrigin;
838 const double quadC =
QgsVector3D::dotProduct( rayOriginMap, rayOriginMap ) - sphereRadiusMap * sphereRadiusMap;
839 const double disc = quadB * quadB - 4 * quadA * quadC;
844 const double rayDistMap = ( -quadB - sqrt( disc ) ) / ( 2 * quadA );
845 if ( rayDistMap < 0 )
847 QgsDebugError( u
"Sphere intersection result negative, canceling move"_s );
850 const QgsVector3D newPosMap = rayOriginMap + QgsVector3D( ray.
direction() ) * rayDistMap;
855 QgsVector3D oldLatLon, newLatLon;
858 oldLatLon = mGlobeCrsToLatLon.transform( startPosMap );
859 newLatLon = mGlobeCrsToLatLon.transform( newPosMap );
861 catch (
const QgsCsException & )
863 QgsDebugError( u
"onPositionChangedGlobeTerrainNavigation: transform failed!"_s );
867 const double latDiff = oldLatLon.
y() - newLatLon.
y();
868 const double lonDiff = oldLatLon.
x() - newLatLon.
x();
870 const QgsVector3D newVC = moveGeocentricPoint( mMousePressViewCenter, latDiff, lonDiff );
871 const QgsVector3D newVCWorld = newVC - mOrigin;
873 mCameraPose.setCenterPoint( newVCWorld );
874 updateCameraFromPose();
881 float dist = mCameraPose.distanceFromCenterPoint();
882 dist -= dist * factor * 0.01f;
883 mCameraPose.setDistanceFromCenterPoint( dist );
884 updateCameraFromPose();
887void QgsCameraController::handleTerrainNavigationWheelZoom()
889 if ( !mDepthBufferIsReady )
892 if ( !mZoomPointCalculated )
895 QVector3D worldPosition;
896 if ( screenPointToWorldPos( mMousePos, depth, worldPosition ) )
898 mZoomPoint = worldPosition;
899 mZoomPointCalculated =
true;
903 double oldDist = ( mZoomPoint - mCameraBefore->position() ).length();
905 double newDist = std::pow( 0.8, mCumulatedWheelY ) * oldDist;
907 newDist = std::max( newDist, 2.0 );
908 double zoomFactor = newDist / oldDist;
910 zoomFactor = std::clamp( zoomFactor, 0.01, 100.0 );
912 zoomCameraAroundPivot( mCameraBefore->position(), mCameraBefore->viewCenter().distanceToPoint( mCameraBefore->position() ), zoomFactor, mZoomPoint );
914 mCumulatedWheelY = 0;
915 setMouseParameters( MouseOperation::None );
918void QgsCameraController::onWheel( Qt3DInput::QWheelEvent *wheel )
920 if ( !mInputHandlersEnabled )
923 switch ( mCameraNavigationMode )
927 const float scaling = ( ( wheel->modifiers() & Qt3DInput::QWheelEvent::Modifiers::ControlModifier ) != 0 ? 0.1f : 1.0f ) / 1000.f;
928 setCameraMovementSpeed( mCameraMovementSpeed + mCameraMovementSpeed * scaling * wheel->angleDelta().y() );
936 const double scaling = ( 1.0 / 120.0 ) * ( ( wheel->modifiers() & Qt3DInput::QWheelEvent::Modifiers::ControlModifier ) != 0 ? 0.1 : 1.0 );
940 mCumulatedWheelY += scaling * wheel->angleDelta().y();
942 if ( mCurrentOperation != MouseOperation::ZoomWheel )
944 setMouseParameters( MouseOperation::ZoomWheel );
949 handleTerrainNavigationWheelZoom();
956 float wheelAmount =
static_cast<float>( wheel->angleDelta().y() );
957 float factor = abs( wheelAmount ) / 1000.f;
958 float mulFactor = wheelAmount > 0 ? ( 1 - factor ) : ( 1 + factor );
959 mCameraPose.setDistanceFromCenterPoint( mCameraPose.distanceFromCenterPoint() * mulFactor );
960 updateCameraFromPose();
966void QgsCameraController::onMousePressed( Qt3DInput::QMouseEvent *mouse )
968 if ( !mInputHandlersEnabled )
971 mKeyboardHandler->setFocus(
true );
973 if ( mouse->button() == Qt3DInput::QMouseEvent::MiddleButton
974 || ( ( mouse->modifiers() & Qt3DInput::QMouseEvent::Modifiers::ShiftModifier ) != 0 && mouse->button() == Qt3DInput::QMouseEvent::LeftButton )
975 || ( ( mouse->modifiers() & Qt3DInput::QMouseEvent::Modifiers::ControlModifier ) != 0 && mouse->button() == Qt3DInput::QMouseEvent::LeftButton ) )
977 mMousePos = QPoint( mouse->x(), mouse->y() );
979 if ( mCaptureFpsMouseMovements )
980 mIgnoreNextMouseMove =
true;
982 const MouseOperation operation {
983 ( mouse->modifiers() & Qt3DInput::QMouseEvent::Modifiers::ControlModifier ) != 0 && mouse->button() == Qt3DInput::QMouseEvent::LeftButton ? MouseOperation::RotationCamera
984 : MouseOperation::RotationCenter
986 setMouseParameters( operation, mMousePos );
989 else if ( mouse->button() == Qt3DInput::QMouseEvent::LeftButton || mouse->button() == Qt3DInput::QMouseEvent::RightButton )
991 mMousePos = QPoint( mouse->x(), mouse->y() );
993 if ( mCaptureFpsMouseMovements )
994 mIgnoreNextMouseMove =
true;
996 const MouseOperation operation = ( mouse->button() == Qt3DInput::QMouseEvent::LeftButton ) ? MouseOperation::Translation : MouseOperation::Zoom;
997 setMouseParameters( operation, mMousePos );
1001void QgsCameraController::onMouseReleased( Qt3DInput::QMouseEvent *mouse )
1004 if ( !mInputHandlersEnabled )
1008 setMouseParameters( MouseOperation::None );
1011bool QgsCameraController::onKeyPressedTerrainNavigation( QKeyEvent *event )
1013 const bool hasShift = (
event->modifiers() & Qt::ShiftModifier );
1014 const bool hasCtrl = (
event->modifiers() & Qt::ControlModifier );
1016 int tx = 0, ty = 0, tElev = 0;
1017 switch ( event->key() )
1033 case Qt::Key_PageDown:
1036 case Qt::Key_PageUp:
1045 if ( !hasShift && !hasCtrl )
1049 else if ( hasShift && !hasCtrl )
1055 else if ( hasCtrl && !hasShift )
1058 const float diffPitch = ty;
1059 const float diffYaw = -tx;
1067 QgsVector3D center = mCameraPose.centerPoint();
1068 center.
set( center.
x(), center.
y(), center.
z() + tElev * 10 );
1069 mCameraPose.setCenterPoint( center );
1076bool QgsCameraController::onKeyPressedGlobeTerrainNavigation( QKeyEvent *event )
1080 constexpr float MOVE_FACTOR = 0.000001f;
1081 constexpr float ZOOM_FACTOR = 0.9f;
1083 const bool hasShift = (
event->modifiers() & Qt::ShiftModifier );
1085 switch ( event->key() )
1111 case Qt::Key_PageDown:
1114 case Qt::Key_PageUp:
1123static const QSet<int> walkNavigationSavedKeys = {
1138bool QgsCameraController::onKeyPressedFlyNavigation( QKeyEvent *event )
1140 switch ( event->key() )
1142 case Qt::Key_QuoteLeft:
1145 mCaptureFpsMouseMovements = !mCaptureFpsMouseMovements;
1146 mIgnoreNextMouseMove =
true;
1148 if ( mCaptureFpsMouseMovements )
1150 if ( mPointerLocker )
1152 mPointerLocker->lock();
1154 qApp->setOverrideCursor( QCursor( Qt::BlankCursor ) );
1158 if ( mPointerLocker )
1160 mPointerLocker->unlock();
1162 qApp->restoreOverrideCursor();
1168 case Qt::Key_Escape:
1171 if ( mCaptureFpsMouseMovements )
1173 mCaptureFpsMouseMovements =
false;
1174 mIgnoreNextMouseMove =
true;
1175 if ( mPointerLocker )
1177 mPointerLocker->unlock();
1180 qApp->restoreOverrideCursor();
1190 if ( walkNavigationSavedKeys.contains( event->key() ) )
1192 if ( !event->isAutoRepeat() )
1194 mDepressedKeys.insert( event->key() );
1204 const QVector3D cameraUp = mCamera->upVector().normalized();
1205 const QVector3D cameraFront = ( QVector3D( mCameraPose.centerPoint().x(), mCameraPose.centerPoint().y(), mCameraPose.centerPoint().z() ) - mCamera->position() ).normalized();
1206 const QVector3D cameraLeft = QVector3D::crossProduct( cameraUp, cameraFront );
1208 QVector3D cameraPosDiff( 0.0f, 0.0f, 0.0f );
1212 cameraPosDiff +=
static_cast<float>( tx ) * cameraFront;
1216 cameraPosDiff +=
static_cast<float>( ty ) * cameraLeft;
1220 cameraPosDiff +=
static_cast<float>( tz ) * QVector3D( 0.0f, 0.0f, 1.0f );
1226void QgsCameraController::applyFlyModeKeyMovements()
1232 const bool shiftPressed = mDepressedKeys.contains( Qt::Key_Shift );
1233 const bool ctrlPressed = mDepressedKeys.contains( Qt::Key_Control );
1235 const double movementSpeed = mCameraMovementSpeed * ( shiftPressed ? 2 : 1 ) * ( ctrlPressed ? 0.1 : 1 );
1237 bool changed =
false;
1241 if ( mDepressedKeys.contains( Qt::Key_Left ) || mDepressedKeys.contains( Qt::Key_A ) )
1247 if ( mDepressedKeys.contains( Qt::Key_Right ) || mDepressedKeys.contains( Qt::Key_D ) )
1253 if ( mDepressedKeys.contains( Qt::Key_Up ) || mDepressedKeys.contains( Qt::Key_W ) )
1259 if ( mDepressedKeys.contains( Qt::Key_Down ) || mDepressedKeys.contains( Qt::Key_S ) )
1267 static constexpr double ELEVATION_MOVEMENT_SCALE = 0.5;
1268 if ( mDepressedKeys.contains( Qt::Key_PageUp ) || mDepressedKeys.contains( Qt::Key_E ) )
1271 z += ELEVATION_MOVEMENT_SCALE * movementSpeed;
1274 if ( mDepressedKeys.contains( Qt::Key_PageDown ) || mDepressedKeys.contains( Qt::Key_Q ) )
1277 z -= ELEVATION_MOVEMENT_SCALE * movementSpeed;
1284void QgsCameraController::onPositionChangedFlyNavigation( Qt3DInput::QMouseEvent *mouse )
1286 const bool hasMiddleButton = ( mouse->buttons() & Qt::MiddleButton );
1287 const bool hasRightButton = ( mouse->buttons() & Qt::RightButton );
1289 const double dx = mCaptureFpsMouseMovements ? QCursor::pos().x() - mMousePos.x() : mouse->x() - mMousePos.x();
1290 const double dy = mCaptureFpsMouseMovements ? QCursor::pos().y() - mMousePos.y() : mouse->y() - mMousePos.y();
1291 mMousePos = mCaptureFpsMouseMovements ? QCursor::pos() : QPoint( mouse->x(), mouse->y() );
1293 if ( mIgnoreNextMouseMove )
1295 mIgnoreNextMouseMove =
false;
1299 if ( hasMiddleButton )
1302 const QVector3D cameraUp = mCamera->upVector().normalized();
1303 const QVector3D cameraFront = ( QVector3D( mCameraPose.centerPoint().x(), mCameraPose.centerPoint().y(), mCameraPose.centerPoint().z() ) - mCamera->position() ).normalized();
1304 const QVector3D cameraLeft = QVector3D::crossProduct( cameraUp, cameraFront );
1305 const QVector3D cameraPosDiff = -dx * cameraLeft - dy * cameraUp;
1306 moveCenterPoint(
static_cast<float>( mCameraMovementSpeed ) * cameraPosDiff / 10.0 );
1308 else if ( hasRightButton )
1311 const QVector3D cameraFront = ( QVector3D( mCameraPose.centerPoint().x(), mCameraPose.centerPoint().y(), mCameraPose.centerPoint().z() ) - mCamera->position() ).normalized();
1312 const QVector3D cameraPosDiff = dy * cameraFront;
1313 moveCenterPoint(
static_cast<float>( mCameraMovementSpeed ) * cameraPosDiff / 5.0 );
1317 if ( mCaptureFpsMouseMovements )
1320 if ( !mPointerLocker )
1322 applyRelativePointerRotation( dx, dy );
1325 else if ( mouse->buttons() & Qt::LeftButton )
1327 applyRelativePointerRotation( dx, dy );
1331 if ( mCaptureFpsMouseMovements )
1333 if ( !mPointerLocker )
1336 mIgnoreNextMouseMove =
true;
1337 emit
setCursorPosition( QPoint( mScene->engine()->size().width() / 2, mScene->engine()->size().height() / 2 ) );
1345 float pitch = mCameraPose.pitchAngle();
1346 pitch -= deltaPitch;
1347 mCameraPose.setPitchAngle(
pitch );
1348 updateCameraFromPose();
1354 float yaw = mCameraPose.headingAngle();
1356 mCameraPose.setHeadingAngle(
yaw );
1357 updateCameraFromPose();
1362 mCameraPose.setHeadingAngle( angle );
1363 updateCameraFromPose();
1368 const float yaw = mCameraPose.headingAngle();
1369 const float dist = mCameraPose.distanceFromCenterPoint();
1370 const float x = tx * dist * 0.02f;
1371 const float y = -ty * dist * 0.02f;
1374 const float t = sqrt( x * x + y * y );
1375 const float a = atan2( y, x ) -
yaw * M_PI / 180;
1376 const float dx = cos( a ) * t;
1377 const float dy = sin( a ) * t;
1380 center.
set( center.
x() + dx, center.
y() - dy, center.
z() );
1381 mCameraPose.setCenterPoint( center );
1382 updateCameraFromPose();
1387 if ( !mInputHandlersEnabled )
1390 if ( event->type() == QKeyEvent::Type::KeyRelease )
1392 if ( !event->isAutoRepeat() && mDepressedKeys.contains( event->key() ) )
1394 mDepressedKeys.remove( event->key() );
1398 else if ( event->type() == QEvent::ShortcutOverride )
1400 if ( event->modifiers() & Qt::ControlModifier )
1402 switch ( event->key() )
1404 case Qt::Key_QuoteLeft:
1407 switch ( mCameraNavigationMode )
1455 switch ( mCameraNavigationMode )
1458 return onKeyPressedFlyNavigation( event );
1461 return onKeyPressedTerrainNavigation( event );
1464 return onKeyPressedGlobeTerrainNavigation( event );
1472 mDepthBufferImage = depthImage;
1473 mDepthBufferIsReady =
true;
1474 mDepthBufferNonVoidAverage = -1;
1484 if ( mCurrentOperation == MouseOperation::ZoomWheel )
1486 handleTerrainNavigationWheelZoom();
1490bool QgsCameraController::isATranslationRotationSequence( MouseOperation newOperation )
const
1492 return std::find( mTranslateOrRotate.begin(), mTranslateOrRotate.end(), newOperation ) != std::end( mTranslateOrRotate )
1493 && std::find( mTranslateOrRotate.begin(), mTranslateOrRotate.end(), mCurrentOperation ) != std::end( mTranslateOrRotate );
1496void QgsCameraController::setMouseParameters(
const MouseOperation &newOperation,
const QPoint &clickPoint )
1498 if ( newOperation == mCurrentOperation )
1503 if ( newOperation == MouseOperation::None )
1505 mClickPoint = QPoint();
1513 else if ( mClickPoint.isNull() || isATranslationRotationSequence( newOperation ) )
1515 mClickPoint = clickPoint;
1516 mRotationPitch = mCameraPose.pitchAngle();
1517 mRotationYaw = mCameraPose.headingAngle();
1519 mCurrentOperation = newOperation;
1520 mDepthBufferIsReady =
false;
1521 mRotationCenterCalculated =
false;
1522 mDragPointCalculated =
false;
1523 mZoomPointCalculated =
false;
1525 if ( mCurrentOperation != MouseOperation::None && mCurrentOperation != MouseOperation::RotationCamera )
1527 mMousePressViewCenter = mCameraPose.centerPoint() + mOrigin;
1537 mCameraPose.setCenterPoint( mCameraPose.centerPoint() - diff );
1540 mCameraBefore->setPosition( (
QgsVector3D( mCameraBefore->position() ) - diff ).toVector3D() );
1541 mCameraBefore->setViewCenter( (
QgsVector3D( mCameraBefore->viewCenter() ) - diff ).toVector3D() );
1542 mDragPoint = (
QgsVector3D( mDragPoint ) - diff ).toVector3D();
1543 mRotationCenter = (
QgsVector3D( mRotationCenter ) - diff ).toVector3D();
1547 updateCameraFromPose();
1550void QgsCameraController::rotateToRespectingTerrain(
float pitch,
float yaw )
1553 double elevation = 0.0;
1557 QVector3D camPos = mCamera->position();
1562 const QList<QgsRayCastHit> results = mScene->
terrainEntity()->rayIntersection( ray, context );
1564 if ( !results.isEmpty() )
1566 elevation = results.constFirst().mapCoordinates().z() - mOrigin.z();
1567 QgsDebugMsgLevel( QString(
"Computed elevation from terrain: %1" ).arg( elevation ), 2 );
1574 pos.
set( pos.
x(), pos.
y(), elevation + mScene->terrainEntity()->terrainElevationOffset() );
1581 if ( !crossSection.
isValid() )
1586 const double width = crossSection.
halfWidth();
1588 const QgsVector3D startVec { startPoint.
x(), startPoint.
y(), 0 };
1591 QgsVector linePerpVec( ( endPoint - startPoint ).x(), ( endPoint - startPoint ).y() );
1594 const QgsVector3D linePerpVec3D( linePerpVec.
x(), linePerpVec.
y(), 0 );
1595 const QgsVector3D frontStartPoint( startVec + linePerpVec3D * width );
1596 const QgsVector3D frontEndPoint( endVec + linePerpVec3D * width );
@ WhenPivoting
When pivoting camera around point in terrain.
@ WhenRotatingCaptured
When rotating camera around self with mouse button pressed.
NavigationMode
The navigation mode used by 3D cameras.
@ TerrainBased
The default navigation based on the terrain.
@ Walk
Uses WASD keys or arrows to navigate in walking (first person) manner.
@ GlobeTerrainBased
Navigation similar to TerrainBased, but for use with globe.
QFlags< VerticalAxisInversion > VerticalAxisInversionFlags
@ Orthographic
Orthogonal projection.
@ Perspective
Perspective projection.
@ Globe
Scene is represented as a globe using a geocentric CRS.
@ Local
Local scene based on a projected CRS.
@ Reverse
Reverse/inverse transform (from destination to source).
Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
QgsTerrainEntity * terrainEntity() SIP_SKIP
Returns terrain entity (may be nullptr if using globe scene, terrain rendering is disabled or when te...
Qgs3DMapSettings * mapSettings() const
Returns the 3D map settings.
QgsAbstract3DEngine * engine() const SIP_SKIP
Returns the abstract 3D engine.
Qgis::Map3DProjectionType projectionType() const
Returns the camera lens' projection type.
bool terrainRenderingEnabled() const
Returns whether the 2D terrain surface will be rendered.
static QQuaternion rotationFromPitchHeadingAngles(float pitchAngle, float headingAngle)
Returns rotation quaternion that performs rotation around X axis by pitchAngle, followed by rotation ...
static std::unique_ptr< Qt3DRender::QCamera > copyCamera(Qt3DRender::QCamera *cam)
Returns new camera object with copied properties.
static double decodeDepth(const QRgb &pixel)
Decodes the depth value from the pixel's color value The depth value is encoded from OpenGL side (the...
static QVector3D screenPointToWorldPos(const QPoint &screenPoint, double depth, const QSize &screenSize, Qt3DRender::QCamera *camera)
Converts the clicked mouse position to the corresponding 3D world coordinates.
static QgsRay3D rayFromScreenPoint(const QPoint &point, const QSize &windowSize, Qt3DRender::QCamera *camera)
Convert from clicked point on the screen to a ray in world coordinates.
static QgsCameraPose lineSegmentToCameraPose(const QgsVector3D &startPoint, const QgsVector3D &endPoint, const QgsDoubleRange &elevationRange, float fieldOfView, const QgsVector3D &worldOrigin)
Returns the camera pose for a camera looking at mid-point between startPoint and endPoint.
virtual QSize size() const =0
Returns size of the engine's rendering area in pixels.
void navigationModeChanged(Qgis::NavigationMode mode)
Emitted when the navigation mode is changed using the hotkey ctrl + ~.
void rotateCameraToBottom()
Rotate to bottom-up view.
void setLookingAtMapPoint(const QgsVector3D &point, float distance, float pitch, float yaw)
Sets camera configuration like setLookingAtPoint(), but the point is given in map coordinates.
float pitch() const
Returns pitch angle in degrees (0 = looking from the top, 90 = looking from the side).
Qt3DRender::QCamera * camera() const
Returns camera that is being controlled.
~QgsCameraController() override
float yaw() const
Returns yaw angle in degrees.
void requestDepthBufferCapture()
Emitted to ask for the depth buffer image.
void rotateCameraToTop()
Rotate to top-down view.
void tiltUpAroundViewCenter(float deltaPitch)
Tilt up the view by deltaPitch around the view center (camera moves).
void globeMoveCenterPoint(double latDiff, double lonDiff)
Orbits camera around the globe by the specified amount given as the difference in latitude/longitude ...
void rotateCameraToEast()
Rotate to view from the east.
const QgsVector3D origin() const
Returns the origin of the scene in map coordinates.
void rotateCameraToHome()
Rotate to diagonal view.
void rotateCameraToNorth()
Rotate to view from the north.
float distance() const
Returns distance of the camera from the point it is looking at.
void globeUpdatePitchAngle(float angleDiff)
Updates pitch angle by the specified amount given as the angular difference in degrees.
Q_DECL_DEPRECATED void zoomCameraAroundPivot(const QVector3D &oldCameraPosition, double zoomFactor, const QVector3D &pivotPoint)
Zooms camera by given zoom factor (>1 one means zoom in) while keeping the pivot point (given in worl...
void globeZoom(float factor)
Moves camera closer or further away from the globe.
void rotateCamera(float diffPitch, float diffYaw)
Rotates the camera on itself.
void rotateCameraToWest()
Rotate to view from the west.
void setCameraNavigationMode(Qgis::NavigationMode navigationMode)
Sets the navigation mode used by the camera controller.
void setVerticalAxisInversion(Qgis::VerticalAxisInversionFlags inversion)
Sets the vertical axis inversion behavior.
void cameraChanged()
Emitted when camera has been updated.
void moveCenterPoint(const QVector3D &posDiff)
Moves camera position by the given difference vector in world coordinates.
void cameraMovementSpeedChanged(double speed)
Emitted whenever the camera movement speed is changed by the controller.
void setCrossSectionSideView(const QgsCrossSection &crossSection)
Sets the cross section side view definition for the 3D map canvas.
QgsCameraController(Qgs3DMapScene *scene)
Constructs the camera controller with optional parent node that will take ownership.
void frameTriggered(float dt)
Called internally from 3D scene when a new frame is generated. Updates camera according to keyboard/m...
void resetView(float distance)
Move camera back to the initial position (looking down towards origin of world's coordinates).
void setLookingAtPoint(const QgsVector3D &point, float distance, float pitch, float yaw)
Sets the complete camera configuration: the point towards it is looking (in 3D world coordinates),...
QgsVector3D lookingAtPoint() const
Returns the point in the world coordinates towards which the camera is looking.
QgsVector3D lookingAtMapPoint() const
Returns the point in the map coordinates towards which the camera is looking.
void depthBufferReady()
Emitted after the depth buffer has been captured and is ready to sample.
void rotateCameraToSouth()
Rotate to view from the south.
QDomElement writeXml(QDomDocument &doc) const
Writes camera configuration to the given DOM element.
void setViewFromTop(float worldX, float worldY, float distance, float yaw=0)
Sets camera to look down towards given point in world coordinate, in given distance from plane with z...
bool keyboardEventFilter(QKeyEvent *event)
If the event is relevant, handles the event and returns true, otherwise false.
void resetGlobe(float distance, double lat=0, double lon=0)
Resets view of the globe to look at a particular location given as latitude and longitude (in degrees...
void readXml(const QDomElement &elem, QgsVector3D savedOrigin)
Reads camera configuration from the given DOM element.
void zoom(float factor)
Zoom the map by factor.
void globeUpdateHeadingAngle(float angleDiff)
Updates heading angle by the specified amount given as the angular difference in degrees.
void rotateAroundViewCenter(float deltaYaw)
Rotate clockwise the view by deltaYaw around the view center (camera moves).
void walkView(double tx, double ty, double tz)
Walks into the map by tx, ty, and tz.
void setCameraPose(const QgsCameraPose &camPose, bool force=false)
Sets camera pose.
void setOrigin(const QgsVector3D &origin)
Reacts to the shift of origin of the scene, updating camera pose and any other member variables so th...
double sampleDepthBuffer(int px, int py)
Returns the minimum depth value in the square [px - 3, px + 3] * [py - 3, py + 3] Returned depth is i...
void setCameraHeadingAngle(float angle)
Set camera heading to angle (used for rotating the view).
void setCameraMovementSpeed(double movementSpeed)
Sets the camera movement speed.
void rotateCameraAroundPivot(float newPitch, float newHeading, const QVector3D &pivotPoint)
Rotates the camera around the pivot point (in world coordinates) to the given new pitch and heading a...
void depthBufferCaptured(const QImage &depthImage)
Sets the depth buffer image used by the camera controller to calculate world position from a pixel's ...
void cameraRotationCenterChanged(QVector3D position)
Emitted when the camera rotation center changes.
void setCursorPosition(QPoint point)
Emitted when the mouse cursor position should be moved to the specified point on the map viewport.
void moveView(float tx, float ty)
Move the map by tx and ty.
Encapsulates camera pose in a 3D scene.
void setPitchAngle(float pitch)
Sets pitch angle in degrees.
void setCenterPoint(const QgsVector3D &point)
Sets center point (towards which point the camera is looking).
void setHeadingAngle(float heading)
Sets heading (yaw) angle in degrees.
void setDistanceFromCenterPoint(float distance)
Sets distance of the camera from the center point.
Encapsulates the definition of a cross section in 3D map coordinates.
double halfWidth() const
Returns the half-width of the cross section.
QgsPoint endPoint() const
Returns the end point of the cross section.
bool isValid() const
Returns cross section validity.
QgsPoint startPoint() const
Returns the start point of the cross section.
Custom exception class for Coordinate Reference System related exceptions.
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
Point geometry type, with support for z-dimension and m-values.
A representation of a ray in 3D.
QVector3D origin() const
Returns the origin of the ray.
QVector3D direction() const
Returns the direction of the ray see setDirection().
Responsible for defining parameters of the ray casting operations in 3D map canvases.
void setSingleResult(bool enable)
Sets whether to fetch only the closest hit for each layer or entity type.
void setMaximumDistance(float distance)
Sets the maximum distance from ray origin to look for hits when casting a ray.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
double y() const
Returns Y coordinate.
double z() const
Returns Z coordinate.
QVector3D toVector3D() const
Converts the current object to QVector3D.
static double dotProduct(const QgsVector3D &v1, const QgsVector3D &v2)
Returns the dot product of two vectors.
double x() const
Returns X coordinate.
void setX(double x)
Sets X coordinate.
void set(double x, double y, double z)
Sets vector coordinates.
void setY(double y)
Sets Y coordinate.
double length() const
Returns the length of the vector.
Represent a 2-dimensional vector.
double y() const
Returns the vector's y-component.
QgsVector normalized() const
Returns the vector's normalized (or "unit") vector (ie same angle but length of 1....
QgsVector perpVector() const
Returns the perpendicular vector to this vector (rotated 90 degrees counter-clockwise).
double x() const
Returns the vector's x-component.
On-screen 3D engine: it creates an OpenGL window (QWindow) and displays rendered 3D scenes there.
QWindow * window()
Returns the internal 3D window where all the rendered output is displayed.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored).
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)