From 7371831f317d86bd41173f31ee4cb86f7c4d551a Mon Sep 17 00:00:00 2001 From: chavlin Date: Wed, 11 Dec 2024 11:08:25 -0500 Subject: [PATCH] add camera.set_position --- .gitignore | 3 ++- examples/amr_osmesa.py | 4 ++++ yt_idv/cameras/trackball_camera.py | 4 ++++ yt_idv/tests/test_yt_idv.py | 9 +++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 19283ec1..5532662c 100644 --- a/.gitignore +++ b/.gitignore @@ -111,8 +111,9 @@ ENV/ .vscode/ .idea/ -# Screenshots +# Screenshots and examples snap_*.png +examples/*.png # pytest outputs report.html diff --git a/examples/amr_osmesa.py b/examples/amr_osmesa.py index 3be5a775..c01a44a3 100644 --- a/examples/amr_osmesa.py +++ b/examples/amr_osmesa.py @@ -15,3 +15,7 @@ image = rc.run() yt.write_bitmap(image, "step2.png") + +rc.scene.camera.set_position([1.0, 1.5, 3.0]) +image = rc.run() +yt.write_bitmap(image, "step3_set_position.png") diff --git a/yt_idv/cameras/trackball_camera.py b/yt_idv/cameras/trackball_camera.py index aae1d1ff..f4fd10a3 100644 --- a/yt_idv/cameras/trackball_camera.py +++ b/yt_idv/cameras/trackball_camera.py @@ -86,3 +86,7 @@ def offset_position(self, dpos=None): def _compute_matrices(self): pass + + def set_position(self, pos): + self.position = pos + self._update_matrices() diff --git a/yt_idv/tests/test_yt_idv.py b/yt_idv/tests/test_yt_idv.py index 144cd3e6..07f68e59 100644 --- a/yt_idv/tests/test_yt_idv.py +++ b/yt_idv/tests/test_yt_idv.py @@ -62,6 +62,15 @@ def test_snapshots(osmesa_fake_amr, image_store): image_store(osmesa_fake_amr) +def test_camera_position(osmesa_fake_amr, image_store): + """Check that we can update the camera position""" + vm = osmesa_fake_amr.scene.camera.view_matrix + osmesa_fake_amr.scene.camera.set_position([0.5, 2.0, 3.0]) + # check that the view matrix has changed + assert np.sum(np.abs(vm - osmesa_fake_amr.scene.camera.view_matrix)) > 0.0 + image_store(osmesa_fake_amr) + + def test_depth_buffer_toggle(osmesa_fake_amr, image_store): osmesa_fake_amr.scene.components[0].use_db = True image_store(osmesa_fake_amr)