From 93473ef9f40bef4ba0e0f302860a75286fe3a715 Mon Sep 17 00:00:00 2001 From: chavlin Date: Wed, 11 Dec 2024 11:08:25 -0500 Subject: [PATCH] add camera.set_position --- yt_idv/cameras/trackball_camera.py | 4 ++++ yt_idv/tests/test_yt_idv.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/yt_idv/cameras/trackball_camera.py b/yt_idv/cameras/trackball_camera.py index aae1d1f..65d00fe 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.view_matrix = get_lookat_matrix(self.position, self.focus, self.up) diff --git a/yt_idv/tests/test_yt_idv.py b/yt_idv/tests/test_yt_idv.py index 144cd3e..07f68e5 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)