Skip to content

Commit

Permalink
Merge pull request #156 from yt-project/camera-adjust
Browse files Browse the repository at this point in the history
Add some camera adjustments
  • Loading branch information
chrishavlin authored Dec 9, 2024
2 parents c1d36ab + 000bfc9 commit e093d4e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions yt_idv/cameras/base_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class BaseCamera(traitlets.HasTraits):
up = traittypes.Array(np.array([0.0, 0.0, 1.0])).valid(
ndarray_shape(3), ndarray_ro()
)
scroll_delta = traitlets.Float(0.1)
fov = traitlets.Float(45.0)
near_plane = traitlets.Float(0.001)
far_plane = traitlets.Float(20.0)
Expand Down
2 changes: 1 addition & 1 deletion yt_idv/rendering_contexts/pyglet_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def on_mouse_scroll(self, x, y, scroll_x, scroll_y):

camera = self.scene.camera # current camera
dpos = (
0.1
camera.scroll_delta
* (camera.position - camera.focus)
/ np.linalg.norm(camera.position - camera.focus)
)
Expand Down
29 changes: 29 additions & 0 deletions yt_idv/simple_gui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

import imgui
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -72,6 +74,14 @@ def render_camera(self, scene):
if not imgui.tree_node("Camera"):
return
changed = False
with imgui.begin_group():
imgui.text("Log of Scroll Delta")
_, scroll_delta = imgui.slider_float(
"value", math.log10(scene.camera.scroll_delta), -3.0, 0.0
)
if _:
scene.camera.scroll_delta = 10**scroll_delta
changed = True
with scene.camera.hold_trait_notifications():
for attr in ("position", "up", "focus"):
arr = getattr(scene.camera, attr)
Expand Down Expand Up @@ -101,10 +111,29 @@ def render_camera(self, scene):
scene.camera.position = np.array([0.499, 0.499, 0.499])
scene.camera.focus = np.array([0.5, 0.5, 0.5])
changed = True
imgui.same_line()
if imgui.button("Outside"):
scene.camera.position = np.array([1.5, 1.5, 1.5])
scene.camera.focus = np.array([0.5, 0.5, 0.5])
changed = True
imgui.same_line()
if imgui.button("X Up"):
scene.camera.position = np.array([0.5, 1.5, 0.5])
scene.camera.focus = np.array([0.5, 0.5, 0.5])
scene.camera.up = np.array([1.0, 0.0, 0.0])
changed = True
imgui.same_line()
if imgui.button("Y Up"):
scene.camera.position = np.array([0.5, 0.5, 1.5])
scene.camera.focus = np.array([0.5, 0.5, 0.5])
scene.camera.up = np.array([0.0, 1.0, 0.0])
changed = True
imgui.same_line()
if imgui.button("Z Up"):
scene.camera.position = np.array([1.5, 0.5, 0.5])
scene.camera.focus = np.array([0.5, 0.5, 0.5])
scene.camera.up = np.array([0.0, 0.0, 1.0])
changed = True
if changed:
scene.camera._update_matrices()
imgui.tree_pop()
Expand Down

0 comments on commit e093d4e

Please sign in to comment.