diff --git a/src/widgets/3dview/CMakeLists.txt b/src/widgets/3dview/CMakeLists.txt
--- a/src/widgets/3dview/CMakeLists.txt
+++ b/src/widgets/3dview/CMakeLists.txt
@@ -1,5 +1,6 @@
set(3d_SRCS
axisgnomonentity.cpp
+ cameracontroller.cpp
fileloader.cpp
gcodeto4d.cpp
gridmesh.cpp
diff --git a/src/widgets/3dview/SceneEntity.qml b/src/widgets/3dview/SceneEntity.qml
--- a/src/widgets/3dview/SceneEntity.qml
+++ b/src/widgets/3dview/SceneEntity.qml
@@ -39,7 +39,7 @@
viewCenter: Qt.vector3d( 10.0, 10.0, 0.0 )
}
- FirstPersonCameraController { camera: camera }
+ CameraController { camera: camera }
components: [
RenderSettings {
diff --git a/src/widgets/3dview/cameracontroller.h b/src/widgets/3dview/cameracontroller.h
new file mode 100644
--- /dev/null
+++ b/src/widgets/3dview/cameracontroller.h
@@ -0,0 +1,35 @@
+/* Atelier KDE Printer Host for 3D Printing
+ Copyright (C) <2018>
+ Author: Kevin Ottens - ervin@kde.org
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3 of
+ the License or any later version accepted by the membership of
+ KDE e.V. (or its successor approved by the membership of KDE
+ e.V.), which shall act as a proxy defined in Section 14 of
+ version 3 of the license.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+
+#pragma once
+
+#include
+
+class CameraController : public Qt3DExtras::QAbstractCameraController
+{
+ Q_OBJECT
+public:
+ explicit CameraController(Qt3DCore::QNode *parent = nullptr);
+ ~CameraController();
+
+private:
+ void moveCamera(const QAbstractCameraController::InputState &state, float dt) override;
+};
diff --git a/src/widgets/3dview/cameracontroller.cpp b/src/widgets/3dview/cameracontroller.cpp
new file mode 100644
--- /dev/null
+++ b/src/widgets/3dview/cameracontroller.cpp
@@ -0,0 +1,66 @@
+/* Atelier KDE Printer Host for 3D Printing
+ Copyright (C) <2018>
+ Author: Kevin Ottens - ervin@kde.org
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3 of
+ the License or any later version accepted by the membership of
+ KDE e.V. (or its successor approved by the membership of KDE
+ e.V.), which shall act as a proxy defined in Section 14 of
+ version 3 of the license.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+
+#include "cameracontroller.h"
+
+#include
+
+namespace
+{
+inline float clampInputs(float input1, float input2)
+{
+ float axisValue = input1 + input2;
+ return (axisValue < -1) ? -1 : (axisValue > 1) ? 1 : axisValue;
+}
+
+inline float zoomDistance(QVector3D firstPoint, QVector3D secondPoint)
+{
+ return (secondPoint - firstPoint).lengthSquared();
+}
+}
+
+CameraController::CameraController(QNode *parent)
+ : Qt3DExtras::QAbstractCameraController(parent)
+{
+}
+
+CameraController::~CameraController()
+{
+}
+
+void CameraController::moveCamera(const Qt3DExtras::QAbstractCameraController::InputState &state, float dt)
+{
+ auto cam = camera();
+ if (!cam) {
+ return;
+ }
+
+ // Mouse
+ if (state.leftMouseButtonActive) {
+ cam->pan(state.rxAxisValue * lookSpeed() * dt);
+ cam->tilt(state.ryAxisValue * lookSpeed() * dt);
+ }
+
+ // Keyboard
+ cam->panAboutViewCenter((state.txAxisValue * lookSpeed()) * dt, QVector3D(0.0f, 0.0f, 1.0f));
+ cam->translate(QVector3D(0.0f, 0.0f, state.tyAxisValue * linearSpeed() * dt),
+ Qt3DRender::QCamera::DontTranslateViewCenter);
+}
diff --git a/src/widgets/3dview/viewer3d.cpp b/src/widgets/3dview/viewer3d.cpp
--- a/src/widgets/3dview/viewer3d.cpp
+++ b/src/widgets/3dview/viewer3d.cpp
@@ -30,6 +30,7 @@
#include
#include "axisgnomonentity.h"
+#include "cameracontroller.h"
#include "gridmesh.h"
#include "viewer3d.h"
#include "linemesh.h"
@@ -41,6 +42,7 @@
Q_INIT_RESOURCE(viewer3d);
qmlRegisterType("Atelier", 1, 0, "AxisGnomonEntity");
+ qmlRegisterType("Atelier", 1, 0, "CameraController");
qmlRegisterType("Atelier", 1, 0, "GridMesh");
qmlRegisterType("Atelier", 1, 0, "LineMesh");