def _rotate_view(self, dx, dy, x, y): """ Function doc """ dist = np.linalg.norm(self.cam_pos) if dist < 25: factor = 36.0 elif dist < 50: factor = 18.0 else: factor = 12.0 angle = math.sqrt(dx**2 + dy**2) / float(self.width + 1) * factor * dist if self.ctrl: if abs(dx) >= abs(dy): if (y - self.height / 2.0) < 0: rot_mat = mop.my_glRotatef(np.identity(4), angle, [0.0, 0.0, dx]) else: rot_mat = mop.my_glRotatef(np.identity(4), angle, [0.0, 0.0, -dx]) else: if (x - self.width / 2.0) < 0: rot_mat = mop.my_glRotatef(np.identity(4), angle, [0.0, 0.0, -dy]) else: rot_mat = mop.my_glRotatef(np.identity(4), angle, [0.0, 0.0, dy]) else: rot_mat = mop.my_glRotatef(np.identity(4), angle, [-dy, -dx, 0.0]) self.model_mat = mop.my_glMultiplyMatricesf(self.model_mat, rot_mat) return True
def _rotate_view(self, dx, dy, x, y): """ Function doc """ dist = np.linalg.norm(self.cam_pos) if dist < 25: factor = 36.0 elif dist < 50: factor = 18.0 else: factor = 12.0 angle = math.sqrt(dx**2+dy**2)/float(self.width+1)*factor*dist if self.ctrl: if abs(dx) >= abs(dy): if (y-self.height/2.0) < 0: rot_mat = mop.my_glRotatef(np.identity(4), angle, [0.0, 0.0, dx]) else: rot_mat = mop.my_glRotatef(np.identity(4), angle, [0.0, 0.0, -dx]) else: if (x-self.width/2.0) < 0: rot_mat = mop.my_glRotatef(np.identity(4), angle, [0.0, 0.0, -dy]) else: rot_mat = mop.my_glRotatef(np.identity(4), angle, [0.0, 0.0, dy]) else: rot_mat = mop.my_glRotatef(np.identity(4), angle, [-dy, -dx, 0.0]) self.model_mat = mop.my_glMultiplyMatricesf(self.model_mat, rot_mat) return True
def get_cam_pos(self): """ Returns the position of the camera in XYZ coordinates The type of data returned is 'numpy.ndarray'. """ modelview = mop.my_glMultiplyMatricesf(self.model_mat, self.view_mat) crd_xyz = -1 * np.mat(modelview[:3, :3]) * np.mat(modelview[3, :3]).T return crd_xyz.A1
def get_cam_pos(self): """ Returns the position of the camera in XYZ coordinates The type of data returned is 'numpy.ndarray'. """ modelview = mop.my_glMultiplyMatricesf(self.model_mat, self.view_mat) crd_xyz = -1 * np.mat(modelview[:3,:3]) * np.mat(modelview[3,:3]).T return crd_xyz.A1
def get_view_matrix(self): """ Function doc """ orient = self.get_orientation() trans = mop.my_glTranslatef(np.identity(4, dtype=np.float32), -self.position) view = mop.my_glMultiplyMatricesf(trans, orient) return view
def _pan_view(self, x, y): """ Function doc """ px, py, pz = self.get_viewport_pos(x, y) pan_mat = mop.my_glTranslatef(np.identity( 4, dtype=np.float32), [(px - self.drag_pos_x) * self.z_far / 10.0, (py - self.drag_pos_y) * self.z_far / 10.0, (pz - self.drag_pos_z) * self.z_far / 10.0]) self.model_mat = mop.my_glMultiplyMatricesf(self.model_mat, pan_mat) self.drag_pos_x = px self.drag_pos_y = py self.drag_pos_z = pz return True
def _pan_view(self, x, y): """ Function doc """ px, py, pz = self.get_viewport_pos(x, y) pan_mat = mop.my_glTranslatef(np.identity(4, dtype=np.float32), [(px-self.drag_pos_x)*self.z_far/10.0, (py-self.drag_pos_y)*self.z_far/10.0, (pz-self.drag_pos_z)*self.z_far/10.0]) self.model_mat = mop.my_glMultiplyMatricesf(self.model_mat, pan_mat) self.drag_pos_x = px self.drag_pos_y = py self.drag_pos_z = pz return True
def mouse_motion(self, widget, event): x = event.x y = event.y state = event.state dx = x - self.mouse_x dy = y - self.mouse_y if (dx == 0 and dy == 0): return self.mouse_x, self.mouse_y = x, y changed = False if self.mouse_rotate: angle = math.sqrt(dx**2 + dy**2) / float(self.width + 1) * 180.0 self.model_mat = mop.my_glRotatef(self.model_mat, angle, [-dy, -dx, 0]) #self.update_normal_mat() changed = True elif self.mouse_pan: px, py, pz = self.pos(x, y) pan_matrix = mop.my_glTranslatef( np.identity(4, dtype=np.float32), [(px - self.drag_pos_x) * self.glcamera.z_far / 10, (py - self.drag_pos_y) * self.glcamera.z_far / 10, (pz - self.drag_pos_z) * self.glcamera.z_far / 10]) self.model_mat = mop.my_glMultiplyMatricesf( self.model_mat, pan_matrix) #self.update_normal_mat() self.drag_pos_x = px self.drag_pos_y = py self.drag_pos_z = pz changed = True elif self.mouse_zoom: delta = (((self.glcamera.z_far - self.glcamera.z_near) / 2) + self.glcamera.z_near) / 200 direction = mop.my_glForwardVectorAbs( self.glcamera.get_view_matrix()) #self.model_mat = mop.my_glTranslatef(self.model_mat, -dy*delta*direction) self.glcamera.move_position(dy * delta * direction) changed = True if changed: self.queue_draw()
def get_matrix(self): """ Function doc """ return mop.my_glMultiplyMatricesf(self.get_projection_matrix(), self.get_view_matrix())