MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / FreeCameraController

Class FreeCameraController

dm_control/viewer/viewer.py:340–457  ·  view source on GitHub ↗

Implements the free camera behavior.

Source from the content-addressed store, hash-verified

338
339
340class FreeCameraController:
341 """Implements the free camera behavior."""
342
343 def __init__(self, viewport, camera, pointer, selection_service, **unused):
344 """Instance initializer.
345
346 Args:
347 viewport: Instance of mujoco_viewer.Viewport.
348 camera: Instance of mujoco_viewer.SceneCamera.
349 pointer: A pointer that moves around the screen and is used to point at
350 bodies. Implements a single attribute - 'position' - that returns a
351 2-component vector of pointer's screen space position.
352 selection_service: An instance of a class implementing a
353 'selected_body_id' property.
354 **unused: Other optional parameters not used by this class.
355 """
356 del unused # Unused.
357 self._viewport = viewport
358 self._camera = camera
359 self._pointer = pointer
360 self._selection_service = selection_service
361 self._active = True
362 self._tracked_body_idx = -1
363 self._action = util.AtomicAction()
364
365 def activate(self):
366 """Activates the controller."""
367 self._active = True
368 self._update_camera_mode()
369
370 def deactivate(self):
371 """Deactivates the controller."""
372 self._active = False
373 self._action = util.AtomicAction()
374
375 def set_pan_vertical_mode(self, enable):
376 """Starts/ends the camera panning action along the vertical plane.
377
378 Args:
379 enable: A boolean flag, True to start the action, False to end it.
380 """
381 if self._active:
382 if enable:
383 self._action.begin(mujoco.mjtMouse.mjMOUSE_MOVE_V)
384 else:
385 self._action.end(mujoco.mjtMouse.mjMOUSE_MOVE_V)
386
387 def set_pan_horizontal_mode(self, enable):
388 """Starts/ends the camera panning action along the horizontal plane.
389
390 Args:
391 enable: A boolean flag, True to start the action, False to end it.
392 """
393 if self._active:
394 if enable:
395 self._action.begin(mujoco.mjtMouse.mjMOUSE_MOVE_H)
396 else:
397 self._action.end(mujoco.mjtMouse.mjMOUSE_MOVE_H)

Callers 1

initializeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…