Skip to content
Permalink
Browse files

some fixes

  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 13, 2021
1 parent 36e3229 commit f24dc8c8e54b1fd6f6b72cffb828e613887a7700
Showing with 31 additions and 13 deletions.
  1. +29 −13 src/3d/qgscameracontroller.cpp
  2. +2 −0 src/3d/qgscameracontroller.h
@@ -375,18 +375,7 @@ void QgsCameraController::onPositionChanged( Qt3DInput::QMouseEvent *mouse )
mMousePos = QPoint( mouse->x(), mouse->y() );
}

void QgsCameraController::onPositionChangedFlyNavigation( Qt3DInput::QMouseEvent *mouse )
{
if ( !mMousePressed )
return;
int dx = mouse->x() - mMousePos.x();
int dy = mouse->y() - mMousePos.y();
float diffPitch = 0.2f * dy;
float diffYaw = - 0.2f * dx;
rotateCamera( diffPitch, diffYaw );
updateCameraFromPose( false );
mMousePos = QPoint( mouse->x(), mouse->y() );
}


void QgsCameraController::zoom( float factor )
{
@@ -410,16 +399,18 @@ void QgsCameraController::onMousePressed( Qt3DInput::QMouseEvent *mouse )
{
Q_UNUSED( mouse )
mKeyboardHandler->setFocus( true );
if ( mouse->button() == Qt3DInput::QMouseEvent::Buttons::LeftButton )
if ( mouse->button() == Qt3DInput::QMouseEvent::LeftButton || mouse->button() == Qt3DInput::QMouseEvent::RightButton || mouse->button() == Qt3DInput::QMouseEvent::MiddleButton )
{
mMousePos = QPoint( mouse->x(), mouse->y() );
mPressedButton = mouse->button();
mMousePressed = true;
}
}

void QgsCameraController::onMouseReleased( Qt3DInput::QMouseEvent *mouse )
{
Q_UNUSED( mouse )
mPressedButton = Qt3DInput::QMouseEvent::NoButton;
mMousePressed = false;
}

@@ -531,6 +522,31 @@ void QgsCameraController::onKeyPressedFlyNavigation( Qt3DInput::QKeyEvent *event
moveCameraPositionBy( cameraPosDiff );
}

void QgsCameraController::onPositionChangedFlyNavigation( Qt3DInput::QMouseEvent *mouse )
{
if ( !mMousePressed )
return;
double dx = mouse->x() - mMousePos.x();
double dy = mouse->y() - mMousePos.y();
if ( mPressedButton == Qt3DInput::QMouseEvent::LeftButton || mPressedButton == Qt3DInput::QMouseEvent::MiddleButton )
{
float diffPitch = 0.2f * dy;
float diffYaw = - 0.2f * dx;
rotateCamera( diffPitch, diffYaw );
updateCameraFromPose( false );
}
else if ( mPressedButton == Qt3DInput::QMouseEvent::RightButton )
{
QVector3D cameraUp = mCamera->upVector().normalized();
QVector3D cameraFront = ( QVector3D( mCameraPose.centerPoint().x(), mCameraPose.centerPoint().y(), mCameraPose.centerPoint().z() ) - mCamera->position() ).normalized();
QVector3D cameraLeft = QVector3D::crossProduct( cameraUp, cameraFront );
QVector3D cameraPosDiff = dx / mViewport.width() * cameraLeft + dy / mViewport.height() * cameraUp;
moveCameraPositionBy( 5.0 * mCameraMovementSpeed * cameraPosDiff );
}

mMousePos = QPoint( mouse->x(), mouse->y() );
}

void QgsCameraController::onKeyReleased( Qt3DInput::QKeyEvent *event )
{
Q_UNUSED( event )
@@ -21,6 +21,7 @@
#include <QPointer>
#include <QRect>
#include <Qt3DCore/QEntity>
#include <Qt3DInput/QMouseEvent>

namespace Qt3DInput
{
@@ -221,6 +222,7 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
//! Last mouse position recorded
QPoint mMousePos;
bool mMousePressed = false;
Qt3DInput::QMouseEvent::Buttons mPressedButton = Qt3DInput::QMouseEvent::Buttons::NoButton;

//! Delegates mouse events to the attached MouseHandler objects
Qt3DInput::QMouseDevice *mMouseDevice = nullptr;

0 comments on commit f24dc8c

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