Skip to content

Commit

Permalink
camera default values api + test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tucchhaa committed Aug 23, 2024
1 parent c288a98 commit dcf2bc8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 6 deletions.
10 changes: 5 additions & 5 deletions cpp/modmesh/view/RCameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ void CameraController::reset()
{
camera()->lens()->setPerspectiveProjection(45.0f, 16.0f / 9.0f, 0.1f, 1000.0f);

setPosition(QVector3D(0.0f, 0.0f, 10.0f));
setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));
setUpVector(QVector3D(0.f, 1.f, 0.f));
setPosition(m_default_position);
setViewCenter(m_default_view_center);
setUpVector(m_default_up_vector);

setLinearSpeed(50.0f);
setLookSpeed(180.0f);
setLinearSpeed(m_default_linear_speed);
setLookSpeed(m_default_look_speed);
}

RFirstPersonCameraController::RFirstPersonCameraController(QNode * parent)
Expand Down
12 changes: 12 additions & 0 deletions cpp/modmesh/view/RCameraController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ class CameraController

void reset();

void setDefaultPosition(QVector3D value) { m_default_position = value; }
void setDefaultViewCenter(QVector3D value) { m_default_view_center = value; }
void setDefaultUpVector(QVector3D value) { m_default_up_vector = value; }
void setDefaultLinearSpeed(float value) { m_default_linear_speed = value; }
void setDefaultLookSpeed(float value) { m_default_look_speed = value; }

protected:
RCameraInputListener * m_listener = nullptr;

Expand All @@ -167,6 +173,12 @@ class CameraController
{
return dynamic_cast<Qt3DExtras::QAbstractCameraController *>(this);
}

QVector3D m_default_position = QVector3D(0.0f, 0.0f, 10.0f);
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
Expand Down
43 changes: 42 additions & 1 deletion cpp/modmesh/view/wrap_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,48 @@ class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapRCameraController
},
py::arg("x"),
py::arg("y"),
py::arg("z"));
py::arg("z"))
.def(
"setDefaultPosition",
[](wrapped_type & self, float x, float y, float z)
{
self.setDefaultPosition(QVector3D(x, y, z));
},
py::arg("x"),
py::arg("y"),
py::arg("z"))
.def(
"setDefaultViewCenter",
[](wrapped_type & self, float x, float y, float z)
{
self.setDefaultViewCenter(QVector3D(x, y, z));
},
py::arg("x"),
py::arg("y"),
py::arg("z"))
.def(
"setDefaultUpVector",
[](wrapped_type & self, float x, float y, float z)
{
self.setDefaultUpVector(QVector3D(x, y, z));
},
py::arg("x"),
py::arg("y"),
py::arg("z"))
.def(
"setDefaultLinearSpeed",
[](wrapped_base_type & self, float value)
{
self.setDefaultLinearSpeed(value);
},
py::arg("value"))
.def(
"setDefaultLookSpeed",
[](wrapped_base_type & self, float value)
{
self.setDefaultLookSpeed(value);
},
py::arg("value"));
}
};

Expand Down
21 changes: 21 additions & 0 deletions tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def setUpClass(cls):
cls.up_vector = cls.controller.upVector
cls.set_up_vector = cls.controller.setUpVector

cls.set_default_pos = cls.controller.setDefaultPosition
cls.set_default_view_center = cls.controller.setDefaultViewCenter
cls.set_default_up_vector = cls.controller.setDefaultUpVector
cls.set_default_linear_speed = cls.controller.setDefaultLinearSpeed
cls.set_default_look_speed = cls.controller.setDefaultLookSpeed

@classmethod
def tearDownClass(cls):
cls.widget.close_and_destroy()
Expand Down Expand Up @@ -147,6 +153,21 @@ def test_vector_get_set(self):
self.set_up_vector(x=7, y=8, z=9)
self.assertEqual(self.up_vector(), (7, 8, 9))

def test_default_values(self):
self.set_default_pos(x=1, y=2, z=3)
self.set_default_view_center(x=4, y=5, z=6)
self.set_default_up_vector(x=7, y=8, z=9)
self.set_default_linear_speed(123.0)
self.set_default_look_speed(456.0)

self.resetCamera()

self.assertEqual(self.pos(), (1, 2, 3))
self.assertEqual(self.view_center(), (4, 5, 6))
self.assertEqual(self.up_vector(), (7, 8, 9))
self.assertEqual(self.linear_speed(), 123.0)
self.assertEqual(self.look_speed(), 456.0)


@unittest.skipIf(GITHUB_ACTIONS, "GUI is not available in GitHub Actions")
class ViewFPSCameraTC(ViewCameraTB, unittest.TestCase):
Expand Down

0 comments on commit dcf2bc8

Please sign in to comment.