MCPcopy Create free account
hub / github.com/SpectacularAI/sdk / CameraControls2D

Class CameraControls2D

python/cli/visualization/visualizer.py:54–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52 self.prevLookAtTarget = None
53
54class CameraControls2D:
55 def __init__(self):
56 self.zoomSpeed = 1.0
57 self.translateSpeed = 1.0
58 self.reset()
59
60 def reset(self):
61 self.lastMousePos = None
62 self.draggingRight = False
63 self.camera_pos = np.array([0.0, 0.0, 0.0])
64 self.zoom = 1.0
65
66 def update(self, event):
67 if event.type == pygame.MOUSEBUTTONDOWN:
68 if event.button == 3: # Right mouse button
69 self.draggingRight = True
70 elif event.button == 4: # Scroll up
71 self.zoom *= 0.95 * self.zoomSpeed
72 elif event.button == 5: # Scroll down
73 self.zoom *= 1.05 * self.zoomSpeed
74 self.lastMousePos = pygame.mouse.get_pos()
75 elif event.type == pygame.MOUSEBUTTONUP:
76 if event.button == 1:
77 self.draggingLeft = False
78 elif event.button == 3:
79 self.draggingRight = False
80 elif event.type == pygame.MOUSEMOTION:
81 if self.draggingRight:
82 # Drag to move
83 mouse_pos = pygame.mouse.get_pos()
84 dx = mouse_pos[0] - self.lastMousePos[0]
85 dy = mouse_pos[1] - self.lastMousePos[1]
86 self.camera_pos[0] += 0.01 * dx * self.translateSpeed
87 self.camera_pos[1] += 0.01 * dy * self.translateSpeed
88 self.lastMousePos = pygame.mouse.get_pos()
89
90 def transformViewMatrix(self, viewMatrix):
91 viewMatrix[:3, 3] += self.camera_pos
92 return viewMatrix
93
94class CameraControls3D:
95 def __init__(self):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected