Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix code style.
  • Loading branch information
ismailsunni committed Jun 6, 2019
1 parent c3dc72d commit a89119e
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 214 deletions.
91 changes: 48 additions & 43 deletions src/3d/qgscameracontroller.cpp
Expand Up @@ -327,18 +327,19 @@ void QgsCameraController::onPositionChanged( Qt3DInput::QMouseEvent *mouse )
}
else if ( hasRightButton && !hasShift && !hasCtrl )
{
zoom(dy);
zoom( dy );
}

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

void QgsCameraController::zoom(float factor){
// zoom in/out
float dist = mCameraPose.distanceFromCenterPoint();
dist -= dist * factor * 0.01f;
mCameraPose.setDistanceFromCenterPoint( dist );
updateCameraFromPose();
void QgsCameraController::zoom( float factor )
{
// zoom in/out
float dist = mCameraPose.distanceFromCenterPoint();
dist -= dist * factor * 0.01f;
mCameraPose.setDistanceFromCenterPoint( dist );
updateCameraFromPose();
}

void QgsCameraController::onWheel( Qt3DInput::QWheelEvent *wheel )
Expand Down Expand Up @@ -395,13 +396,13 @@ void QgsCameraController::onKeyPressed( Qt3DInput::QKeyEvent *event )
{
if ( !hasShift && !hasCtrl )
{
moveView(tx, ty);
moveView( tx, ty );
}
else if ( hasShift && !hasCtrl )
{
// rotate/tilt using keyboard (camera moves as it rotates around its view center)
tiltUpAroundViewCenter(ty);
rotateAroundViewCenter(tx);
tiltUpAroundViewCenter( ty );
rotateAroundViewCenter( tx );
}
else if ( hasCtrl && !hasShift )
{
Expand Down Expand Up @@ -432,43 +433,47 @@ void QgsCameraController::onPickerMousePressed( Qt3DRender::QPickEvent *pick )
mLastPressedHeight = pick->worldIntersection().y();
}

void QgsCameraController::tiltUpAroundViewCenter(float deltaPitch){
// Tilt up the view by deltaPitch around the view center (camera moves)
float pitch = mCameraPose.pitchAngle();
pitch -= deltaPitch; // down key = moving camera toward terrain
mCameraPose.setPitchAngle( pitch );
updateCameraFromPose();
void QgsCameraController::tiltUpAroundViewCenter( float deltaPitch )
{
// Tilt up the view by deltaPitch around the view center (camera moves)
float pitch = mCameraPose.pitchAngle();
pitch -= deltaPitch; // down key = moving camera toward terrain
mCameraPose.setPitchAngle( pitch );
updateCameraFromPose();
}

void QgsCameraController::rotateAroundViewCenter(float deltaYaw){
// Rotate clockwise the view by deltaYaw around the view center (camera moves)
float yaw = mCameraPose.headingAngle();
yaw -= deltaYaw; // right key = moving camera clockwise
mCameraPose.setHeadingAngle( yaw );
updateCameraFromPose();
qInfo() << "Delta yaw: " << deltaYaw;
qInfo() << "Yaw: " << yaw;
void QgsCameraController::rotateAroundViewCenter( float deltaYaw )
{
// Rotate clockwise the view by deltaYaw around the view center (camera moves)
float yaw = mCameraPose.headingAngle();
yaw -= deltaYaw; // right key = moving camera clockwise
mCameraPose.setHeadingAngle( yaw );
updateCameraFromPose();
qInfo() << "Delta yaw: " << deltaYaw;
qInfo() << "Yaw: " << yaw;
}

void QgsCameraController::setCameraHeadingAngle(float angle){
mCameraPose.setHeadingAngle( angle );
updateCameraFromPose();
void QgsCameraController::setCameraHeadingAngle( float angle )
{
mCameraPose.setHeadingAngle( angle );
updateCameraFromPose();
}

void QgsCameraController::moveView(float tx, float ty){
float yaw = mCameraPose.headingAngle();
float dist = mCameraPose.distanceFromCenterPoint();
float x = tx * dist * 0.02f;
float y = -ty * dist * 0.02f;

// moving with keyboard - take into account yaw of camera
float t = sqrt( x * x + y * y );
float a = atan2( y, x ) - yaw * M_PI / 180;
float dx = cos( a ) * t;
float dy = sin( a ) * t;

QgsVector3D center = mCameraPose.centerPoint();
center.set( center.x() + dx, center.y(), center.z() + dy );
mCameraPose.setCenterPoint( center );
updateCameraFromPose( true );
void QgsCameraController::moveView( float tx, float ty )
{
float yaw = mCameraPose.headingAngle();
float dist = mCameraPose.distanceFromCenterPoint();
float x = tx * dist * 0.02f;
float y = -ty * dist * 0.02f;

// moving with keyboard - take into account yaw of camera
float t = sqrt( x * x + y * y );
float a = atan2( y, x ) - yaw * M_PI / 180;
float dx = cos( a ) * t;
float dy = sin( a ) * t;

QgsVector3D center = mCameraPose.centerPoint();
center.set( center.x() + dx, center.y(), center.z() + dy );
mCameraPose.setCenterPoint( center );
updateCameraFromPose( true );
}
10 changes: 5 additions & 5 deletions src/3d/qgscameracontroller.h
Expand Up @@ -135,11 +135,11 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
//! Reads camera configuration from the given DOM element
void readXml( const QDomElement &elem );

void zoom(float factor);
void tiltUpAroundViewCenter(float deltaPitch);
void rotateAroundViewCenter(float deltaYaw);
void setCameraHeadingAngle(float angle);
void moveView(float tx, float ty);
void zoom( float factor );
void tiltUpAroundViewCenter( float deltaPitch );
void rotateAroundViewCenter( float deltaYaw );
void setCameraHeadingAngle( float angle );
void moveView( float tx, float ty );

private:
void rotateCamera( float diffPitch, float diffYaw );
Expand Down
2 changes: 1 addition & 1 deletion src/app/3d/qgs3dmapcanvas.h
Expand Up @@ -76,7 +76,7 @@ class Qgs3DMapCanvas : public QWidget
/**
* Set the visibility of on-screen navigation widget.
*/
void setOnScreenNavigationVisibility(bool visibility);
void setOnScreenNavigationVisibility( bool visibility );

signals:
//! Emitted when the 3D map canvas was successfully saved as image
Expand Down

0 comments on commit a89119e

Please sign in to comment.