Skip to content

Commit

Permalink
Merge pull request #385 from Tucchhaa/wasd_control
Browse files Browse the repository at this point in the history
Camera: use WASD+EQ and arrows+Page Up/Down for movement
  • Loading branch information
yungyuc authored Jul 26, 2024
2 parents 1b21957 + 3fb9c0e commit fde3636
Show file tree
Hide file tree
Showing 9 changed files with 881 additions and 28 deletions.
2 changes: 2 additions & 0 deletions cpp/modmesh/view/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(MODMESH_VIEW_PYMODHEADERS
${CMAKE_CURRENT_SOURCE_DIR}/RManager.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RParameter.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RAxisMark.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RCameraController.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RPythonConsoleDockWidget.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RStaticMesh.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RAction.hpp
Expand All @@ -23,6 +24,7 @@ set(MODMESH_VIEW_PYMODSOURCES
${CMAKE_CURRENT_SOURCE_DIR}/RManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RParameter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RAxisMark.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RCameraController.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RPythonConsoleDockWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RStaticMesh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RAction.cpp
Expand Down
19 changes: 8 additions & 11 deletions cpp/modmesh/view/R3DWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,7 @@ R3DWidget::R3DWidget(Qt3DExtras::Qt3DWindow * window, RScene * scene, QWidget *
{
m_view->setRootEntity(m_scene);

// Set up the camera.
Qt3DRender::QCamera * camera = m_view->camera();
camera->lens()->setPerspectiveProjection(45.0f, 16.0f / 9.0f, 0.1f, 1000.0f);
camera->setPosition(QVector3D(0.0f, 0.0f, 10.0f));
camera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));

// Set up the camera control.
auto * control = m_scene->controller();
control->setCamera(camera);
control->setLinearSpeed(50.0f);
control->setLookSpeed(180.0f);
resetCamera(m_view->camera());

if (Toggle::instance().fixed().get_show_axis())
{
Expand Down Expand Up @@ -96,6 +86,12 @@ void R3DWidget::updateWorld(std::shared_ptr<WorldFp64> const & world)
new RWorld(world, m_scene);
}

void R3DWidget::closeAndDestroy()
{
this->close();
this->deleteLater();
}

void R3DWidget::resizeEvent(QResizeEvent * event)
{
QWidget::resizeEvent(event);
Expand All @@ -112,6 +108,7 @@ void R3DWidget::resetCamera(Qt3DRender::QCamera * camera,
camera->lens()->setPerspectiveProjection(45.0f, 16.0f / 9.0f, 0.1f, 1000.0f);
camera->setPosition(QVector3D(positionX, positionY, positionZ));
camera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));
camera->setUpVector(QVector3D(0.f, 1.f, 0.f));

// Set up the camera control.
auto * control = m_scene->controller();
Expand Down
21 changes: 6 additions & 15 deletions cpp/modmesh/view/R3DWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,13 @@
#include <Qt3DCore/QEntity>
#include <Qt3DRender/QCamera>

#include <QAbstractCameraController>
#include <QOrbitCameraController>
#include <QFirstPersonCameraController>
#include <modmesh/view/RCameraController.hpp>

#include <QResizeEvent>

namespace modmesh
{

class RFirstPersonCameraController
: public Qt3DExtras::QFirstPersonCameraController
{
using Qt3DExtras::QFirstPersonCameraController::QFirstPersonCameraController;
}; /* end class RFirstPersonCameraController */

class ROrbitCameraController
: public Qt3DExtras::QOrbitCameraController
{
using Qt3DExtras::QOrbitCameraController::QOrbitCameraController;
}; /* end class ROrbitCameraController */

class RScene
: public Qt3DCore::QEntity
{
Expand Down Expand Up @@ -111,6 +97,9 @@ class R3DWidget
Qt3DExtras::Qt3DWindow * view() { return m_view; }
RScene * scene() { return m_scene; }
Qt3DRender::QCamera * camera() { return m_view->camera(); }
Qt3DExtras::QAbstractCameraController * qtCameraController() { return m_scene->controller(); }
CameraController * cameraController() { return dynamic_cast<CameraController *>(m_scene->controller()); }

void resetCamera(Qt3DRender::QCamera * camera,
float positionX = 0.0f,
float positionY = 0.0f,
Expand All @@ -122,6 +111,8 @@ class R3DWidget
void updateMesh(std::shared_ptr<StaticMesh> const & mesh);
void updateWorld(std::shared_ptr<WorldFp64> const & world);

void closeAndDestroy();

std::shared_ptr<StaticMesh> mesh() const { return m_mesh; }

private:
Expand Down
Loading

0 comments on commit fde3636

Please sign in to comment.