-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Camera Controller: expose complete API to python #418
Changes from all commits
c288a98
dcf2bc8
f527710
24f2312
09842d0
3adeb70
42161b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,19 +49,17 @@ namespace modmesh | |
class RScene | ||
: public Qt3DCore::QEntity | ||
{ | ||
|
||
public: | ||
|
||
explicit RScene(Qt3DCore::QNode * parent = nullptr) | ||
: Qt3DCore::QEntity(parent) | ||
, m_controller(new ROrbitCameraController(this)) | ||
explicit RScene(QNode * parent = nullptr) | ||
: QEntity(parent) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good to separate the |
||
{ | ||
m_controller = new ROrbitCameraController(this); | ||
} | ||
|
||
Qt3DExtras::QAbstractCameraController const * controller() const { return m_controller; } | ||
Qt3DExtras::QAbstractCameraController * controller() { return m_controller; } | ||
RCameraController * controller() const { return m_controller; } | ||
|
||
void setCameraController(Qt3DExtras::QAbstractCameraController * controller) | ||
void setCameraController(RCameraController * controller) | ||
{ | ||
m_controller->deleteLater(); | ||
m_controller = controller; | ||
|
@@ -73,7 +71,7 @@ class RScene | |
|
||
private: | ||
|
||
Qt3DExtras::QAbstractCameraController * m_controller = nullptr; | ||
RCameraController * m_controller; | ||
|
||
}; /* end class RScene */ | ||
|
||
|
@@ -97,10 +95,8 @@ 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() const; | ||
RCameraController * cameraController() const { return m_scene->controller(); } | ||
|
||
QPixmap grabPixmap() const { return m_view->screen()->grabWindow(m_view->winId()); } | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,10 +29,8 @@ | |
*/ | ||
|
||
#include <modmesh/view/common_detail.hpp> // Must be the first include. | ||
|
||
#include <QOrbitCameraController> | ||
#include <QFirstPersonCameraController> | ||
#include <QCamera> | ||
#include <QAbstractCameraController> | ||
|
||
#include <Qt3DLogic/QFrameAction> | ||
#include <Qt3DInput/QActionInput> | ||
|
@@ -128,77 +126,97 @@ class RCameraInputListener : public Qt3DCore::QEntity | |
Qt3DInput::QButtonAxisInput * m_keyboard_tz_neg_input; | ||
}; /* end class RCameraInputListener */ | ||
|
||
class CameraController | ||
class RCameraController : public Qt3DExtras::QAbstractCameraController | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
virtual ~CameraController() = default; | ||
explicit RCameraController(Qt3DCore::QNode * parent = nullptr) | ||
: QAbstractCameraController(parent) | ||
{ | ||
} | ||
|
||
virtual void updateCameraPosition(const CameraInputState & state, float dt) = 0; | ||
void moveCamera(const InputState & state, float dt) override | ||
{ | ||
// Do nothing in QAbstractCameraController's moveCamera | ||
} | ||
|
||
virtual void moveCamera(const CameraInputState & state, float dt) = 0; | ||
|
||
virtual Qt3DRender::QCamera * getCamera() = 0; | ||
Qt3DRender::QCamera * camera() const { return QAbstractCameraController::camera(); } | ||
void setCamera(Qt3DRender::QCamera * camera) { QAbstractCameraController::setCamera(camera); } | ||
|
||
virtual float getLinearSpeed() = 0; | ||
float linearSpeed() const { return QAbstractCameraController::linearSpeed(); } | ||
void setLinearSpeed(float value) { QAbstractCameraController::setLinearSpeed(value); } | ||
|
||
virtual float getLookSpeed() = 0; | ||
float lookSpeed() const { return QAbstractCameraController::lookSpeed(); } | ||
void setLookSpeed(float value) { QAbstractCameraController::setLookSpeed(value); } | ||
|
||
virtual CameraControllerType getType() = 0; | ||
|
||
QVector3D position() { return getCamera()->position(); } | ||
QVector3D position() const { return camera()->position(); } | ||
void setPosition(const QVector3D & value) const { camera()->setPosition(value); } | ||
|
||
QVector3D viewVector() const { return camera()->viewVector(); } | ||
|
||
QVector3D viewCenter() const { return camera()->viewCenter(); } | ||
void setViewCenter(const QVector3D & value) const { camera()->setViewCenter(value); } | ||
|
||
QVector3D viewVector() { return getCamera()->viewVector(); } | ||
QVector3D upVector() const { return camera()->upVector(); } | ||
void setUpVector(const QVector3D & value) const { camera()->setUpVector(value); } | ||
|
||
QVector3D viewCenter() { return getCamera()->viewCenter(); } | ||
void reset(); | ||
|
||
QVector3D upVector() { return getCamera()->upVector(); } | ||
QVector3D defaultPosition() const { return m_default_position; } | ||
void setDefaultPosition(QVector3D value) { m_default_position = value; } | ||
|
||
QVector3D defaultViewCenter() const { return m_default_view_center; } | ||
void setDefaultViewCenter(QVector3D value) { m_default_view_center = value; } | ||
|
||
QVector3D defaultUpVector() const { return m_default_up_vector; } | ||
void setDefaultUpVector(QVector3D value) { m_default_up_vector = value; } | ||
|
||
float defaultLinearSpeed() const { return m_default_linear_speed; } | ||
void setDefaultLinearSpeed(float value) { m_default_linear_speed = value; } | ||
|
||
float defaultLookSpeed() const { return m_default_look_speed; } | ||
void setDefaultLookSpeed(float value) { m_default_look_speed = value; } | ||
Comment on lines
+170
to
+183
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new props in |
||
|
||
protected: | ||
RCameraInputListener * m_listener = nullptr; | ||
|
||
private: | ||
Qt3DExtras::QAbstractCameraController * asQtCameraController() | ||
{ | ||
return dynamic_cast<Qt3DExtras::QAbstractCameraController *>(this); | ||
} | ||
QVector3D m_default_position = QVector3D(0.0f, 0.0f, 10.0f); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why (0, 0, 10)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because meshes are placed at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can guess that, but my point is, better to have some comments for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To put the camera outside the mesh, it is not good to hard-code the default value of the member We do not have a reasonably large number of mesh examples for the default location to show disadvantage.
I concur, but it's OK to leave it here and deal with it in the future. As we make the code more useful, some meshes will cover the position sooner or later. We will immediately know and fix it. |
||
QVector3D m_default_view_center = QVector3D(0.0f, 0.0f, 0.0f); | ||
QVector3D m_default_up_vector = QVector3D(0.0f, 1.0f, 0.0f); | ||
float m_default_linear_speed = 50.0f; | ||
float m_default_look_speed = 180.0f; | ||
}; /* end class CameraController */ | ||
|
||
class RFirstPersonCameraController : public Qt3DExtras::QFirstPersonCameraController | ||
, public CameraController | ||
class RFirstPersonCameraController : public RCameraController | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit RFirstPersonCameraController(QNode * parent = nullptr); | ||
|
||
Qt3DRender::QCamera * getCamera() override { return camera(); } | ||
float getLinearSpeed() override { return linearSpeed(); } | ||
float getLookSpeed() override { return lookSpeed(); } | ||
|
||
private: | ||
static constexpr auto lookSpeedFactorOnShiftPressed = 0.2f; | ||
|
||
void moveCamera(const InputState & state, float dt) override {} | ||
|
||
void updateCameraPosition(const CameraInputState & input, float dt) override; | ||
void moveCamera(const CameraInputState & input, float dt) override; | ||
|
||
CameraControllerType getType() override { return CameraControllerType::FirstPerson; } | ||
}; /* end class RFirstPersonCameraController */ | ||
|
||
class ROrbitCameraController : public Qt3DExtras::QOrbitCameraController | ||
, public CameraController | ||
class ROrbitCameraController : public RCameraController | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ROrbitCameraController(QNode * parent = nullptr); | ||
|
||
Qt3DRender::QCamera * getCamera() override { return camera(); } | ||
float getLinearSpeed() override { return linearSpeed(); } | ||
float getLookSpeed() override { return lookSpeed(); } | ||
|
||
private: | ||
void moveCamera(const InputState & state, float dt) override {} | ||
|
||
void updateCameraPosition(const CameraInputState & input, float dt) override; | ||
void moveCamera(const CameraInputState & input, float dt) override; | ||
|
||
void zoom(float zoomValue) const; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resetCamera
moved toCameraController
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving it to
CameraController
makes it more testable. I like it.