def render(self): rect = self.get_rect() width = rect.width height = rect.height functions.mjv_addGeoms(self.model, self.data, self.vopt, None, CAT_ALL, self.scn) functions.mjv_updateCamera(self.model, self.data, self.cam, self.scn) functions.mjv_moveCamera(self.model, 5, width / height, height / height, self.scn, self.cam) functions.mjr_render(rect, self.scn, self.con)
def autoscale(self): self.cam.lookat[0] = self.model.stat.center[0] self.cam.lookat[1] = self.model.stat.center[1] self.cam.lookat[2] = self.model.stat.center[2] self.cam.distance = 1.0 * self.model.stat.extent self.cam.fixedcamid = -1 self.cam.trackbodyid = -1 if self.window: width, height = glfw.get_framebuffer_size(self.window) functions.mjv_moveCamera(self.model, MjMOUSE_ZOOM, width, height, self.scn, self.cam)
def handle_scroll(self, window, x_offset, y_offset): # require model if not self.model: return # get current window size width, height = glfw.get_framebuffer_size(window) # scroll self.gui_lock.acquire() functions.mjv_moveCamera(mjconstants.MOUSE_ZOOM, 0, (-20 * y_offset), byref(self.cam), width, height) self.gui_lock.release()
def handle_mouse_move(self, window, xpos, ypos): # no buttons down: nothing to do if not self._button_left_pressed \ and not self._button_middle_pressed \ and not self._button_right_pressed: return # compute mouse displacement, save dx = int(self._scale * xpos) - self._last_mouse_x dy = int(self._scale * ypos) - self._last_mouse_y self._last_mouse_x = int(self._scale * xpos) self._last_mouse_y = int(self._scale * ypos) # require model if not self.model: return # get current window size width, height = glfw.get_framebuffer_size(self.window) # get shift key state mod_shift = glfw.get_key(window, glfw.KEY_LEFT_SHIFT) == glfw.PRESS \ or glfw.get_key(window, glfw.KEY_RIGHT_SHIFT) == glfw.PRESS # determine action based on mouse button action = None if self._button_right_pressed: action = mjconstants.MOUSE_MOVE_H if mod_shift else mjconstants.MOUSE_MOVE_V elif self._button_left_pressed: action = mjconstants.MOUSE_ROTATE_H if mod_shift else mjconstants.MOUSE_ROTATE_V else: action = mjconstants.MOUSE_ZOOM self.gui_lock.acquire() functions.mjv_moveCamera(action, dx, dy, byref(self.cam), width, height) self.gui_lock.release()