@@ -70,18 +70,11 @@ def __init__(
7070 self ._camera = camera
7171 self ._controller = controller
7272
73- self .controller .add_default_event_handlers (
73+ self .controller .add_camera (self .camera )
74+ self .controller .register_events (
7475 self .viewport ,
75- self .camera
7676 )
7777
78- # camera.far and camera.near clipping planes get
79- # wonky with setting controller.distance = 0
80- if isinstance (self .camera , OrthographicCamera ):
81- self .controller .distance = 0
82- # also set a initial zoom
83- self .controller .zoom (0.8 / self .controller .zoom_value )
84-
8578 self .renderer .add_event_handler (self .set_viewport_rect , "resize" )
8679
8780 # list of hex id strings for all graphics managed by this PlotArea
@@ -158,7 +151,6 @@ def set_viewport_rect(self, *args):
158151
159152 def render (self ):
160153 # does not flush
161- self .controller .update_camera (self .camera )
162154 self .viewport .render (self .scene , self .camera )
163155
164156 for child in self .children :
@@ -213,17 +205,7 @@ def _check_graphic_name_exists(self, name):
213205 if name in graphic_names :
214206 raise ValueError (f"graphics must have unique names, current graphic names are:\n { graphic_names } " )
215207
216- def _refresh_camera (self ):
217- self .controller .update_camera (self .camera )
218- if sum (self .renderer .logical_size ) > 0 :
219- scene_lsize = self .viewport .rect [2 ], self .viewport .rect [3 ]
220- else :
221- scene_lsize = (1 , 1 )
222-
223- self .camera .set_view_size (* scene_lsize )
224- self .camera .update_projection_matrix ()
225-
226- def center_graphic (self , graphic : Graphic , zoom : float = 1.3 ):
208+ def center_graphic (self , graphic : Graphic , zoom : float = 1.35 ):
227209 """
228210 Center the camera w.r.t. the passed graphic
229211
@@ -236,17 +218,14 @@ def center_graphic(self, graphic: Graphic, zoom: float = 1.3):
236218 zoom the camera after centering
237219
238220 """
239- if not isinstance (self .camera , OrthographicCamera ):
240- warn ("`center_graphic()` not yet implemented for `PerspectiveCamera`" )
241- return
242221
243- self ._refresh_camera ( )
222+ self .camera . show_object ( graphic . world_object )
244223
245- self .controller .show_object (self .camera , graphic .world_object )
224+ # camera.show_object can cause the camera width and height to increase so apply a zoom to compensate
225+ # probably because camera.show_object uses bounding sphere
226+ self .camera .zoom = zoom
246227
247- self .controller .zoom (zoom )
248-
249- def center_scene (self , zoom : float = 1.3 ):
228+ def center_scene (self , zoom : float = 1.35 ):
250229 """
251230 Auto-center the scene, does not scale.
252231
@@ -259,15 +238,11 @@ def center_scene(self, zoom: float = 1.3):
259238 if not len (self .scene .children ) > 0 :
260239 return
261240
262- if not isinstance (self .camera , OrthographicCamera ):
263- warn ("`center_scene()` not yet implemented for `PerspectiveCamera`" )
264- return
265-
266- self ._refresh_camera ()
241+ self .camera .show_object (self .scene )
267242
268- self . controller . show_object ( self . camera , self . scene )
269-
270- self .controller .zoom ( zoom )
243+ # camera. show_object can cause the camera width and height to increase so apply a zoom to compensate
244+ # probably because camera.show_object uses bounding sphere
245+ self .camera .zoom = zoom
271246
272247 def auto_scale (self , maintain_aspect : bool = False , zoom : float = 0.8 ):
273248 """
@@ -303,9 +278,7 @@ def auto_scale(self, maintain_aspect: bool = False, zoom: float = 0.8):
303278 self .camera .width = width
304279 self .camera .height = height
305280
306- # self.controller.distance = 0
307-
308- self .controller .zoom (zoom / self .controller .zoom_value )
281+ self .camera .zoom = zoom
309282
310283 def remove_graphic (self , graphic : Graphic ):
311284 """
0 commit comments