Ejemplo n.º 1
0
 def mouse_scroll(self, widget, event):
     """ Function doc """
     if self.ctrl:
         if event.direction == Gdk.ScrollDirection.UP:
             self.model_mat = cam.my_glTranslatef(self.model_mat,
                                                  [0.0, 0.0, -self.scroll])
         if event.direction == Gdk.ScrollDirection.DOWN:
             self.model_mat = cam.my_glTranslatef(self.model_mat,
                                                  [0.0, 0.0, self.scroll])
     else:
         #pos_z = self.get_cam_pos()[2]
         pos_z = self.cam_pos[2]
         if event.direction == Gdk.ScrollDirection.UP:
             self.z_near -= self.scroll
             self.z_far += self.scroll
         if event.direction == Gdk.ScrollDirection.DOWN:
             if (self.z_far - self.scroll) >= (self.min_zfar):
                 if (self.z_far - self.scroll) > (self.z_near +
                                                  self.scroll):
                     self.z_near += self.scroll
                     self.z_far -= self.scroll
         if (self.z_near >= self.min_znear):
             self.proj_mat = cam.my_glPerspectivef(self.fov, self.var,
                                                   self.z_near, self.z_far)
         else:
             if self.z_far < (self.min_zfar + self.min_znear):
                 self.z_near -= self.scroll
                 self.z_far = self.min_znear + self.min_zfar
             self.proj_mat = cam.my_glPerspectivef(self.fov, self.var,
                                                   self.min_znear,
                                                   self.z_far)
     self.queue_draw()
Ejemplo n.º 2
0
    def render(self, area, context):
        if self.flag:
            self.load_shaders()
        GL.glClearColor(0.0, 0.0, 0.0, 1.0)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glUseProgram(self.program)

        global degrees
        model = view = proj = np.identity(4, dtype=np.float32)
        model = cam.my_glRotateYf(model, degrees)
        view = cam.my_glTranslatef(view, np.array([0, 0, -3],
                                                  dtype=np.float32))
        aloc = self.glarea.get_allocation()
        w = np.float32(aloc.width)
        h = np.float32(aloc.height)
        proj = cam.my_gluPerspectivef(proj, 30, w / h, 0.1, 10.0)

        self.model = GL.glGetUniformLocation(self.program, 'model_mat')
        GL.glUniformMatrix4fv(self.model, 1, GL.GL_FALSE, model)
        self.view = GL.glGetUniformLocation(self.program, 'view_mat')
        GL.glUniformMatrix4fv(self.view, 1, GL.GL_FALSE, view)
        self.proj = GL.glGetUniformLocation(self.program, 'projection_mat')
        GL.glUniformMatrix4fv(self.proj, 1, GL.GL_FALSE, proj)

        GL.glBindVertexArray(self.vertex_array_object)
        if self.coords is None:
            pass
        else:
            GL.glDrawArrays(GL.GL_POINTS, 0, int(len(self.coords) / 3))

        GL.glBindVertexArray(0)
        GL.glUseProgram(0)
        degrees += 1
        if degrees >= 360:
            degrees = np.float32(0)
Ejemplo n.º 3
0
 def _pan_view(self, x, y):
     """ Function doc """
     px, py, pz = self.get_viewport_pos(x, y)
     pan_mat = cam.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 = cam.my_glMultiplyMatricesf(self.model_mat, pan_mat)
     self.drag_pos_x = px
     self.drag_pos_y = py
     self.drag_pos_z = pz
     return True
Ejemplo n.º 4
0
 def initialize(self, widget):
     aloc = self.get_allocation()
     w = np.float32(aloc.width)
     h = np.float32(aloc.height)
     self.model_mat = np.identity(4, dtype=np.float32)
     self.view_mat = cam.my_glTranslatef(np.identity(4, dtype=np.float32), np.array([0,0,-3],dtype=np.float32))
     self.proj_mat = cam.my_gluPerspectivef(np.identity(4, dtype=np.float32), 30, w/h, 0.1, 10.0)
     self.degrees = np.float32(0)
     self.set_has_depth_buffer(True)
     self.set_has_alpha(True)
     self.gl_programs = True
     # Here are the test programs and flags
     self.gl_program_diamonds = None
     self.gl_program_circles = None
     self.diamonds = True
     self.circles = True
Ejemplo n.º 5
0
    def render(self, area, context):
        if self.flag:
            self.load_shaders()
        GL.glClearColor(0.0, 0.0, 0.0, 1.0)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        #print self.program, 'rendereing'
        GL.glUseProgram(self.program)

        global degrees
        model = np.identity(4, dtype=np.float32)
        view = np.identity(4, dtype=np.float32)
        proj = np.identity(4, dtype=np.float32)
        model = cam.my_glRotateYf(model, degrees)
        view = cam.my_glTranslatef(view, np.array([0, 0, -3],
                                                  dtype=np.float32))
        aloc = self.glarea.get_allocation()
        w = np.float32(aloc.width)
        h = np.float32(aloc.height)
        proj = cam.my_gluPerspectivef(proj, 30, w / h, 0.1, 10.0)

        self.model = GL.glGetUniformLocation(self.program, 'model_mat')
        GL.glUniformMatrix4fv(self.model, 1, GL.GL_FALSE, model)
        self.view = GL.glGetUniformLocation(self.program, 'view_mat')
        GL.glUniformMatrix4fv(self.view, 1, GL.GL_FALSE, view)
        self.proj = GL.glGetUniformLocation(self.program, 'projection_mat')
        GL.glUniformMatrix4fv(self.proj, 1, GL.GL_FALSE, proj)

        # Extern line
        u_linewidth = 2
        # Intern line
        u_antialias = 2
        u_size = 1
        uni_ulinewidth = GL.glGetUniformLocation(self.program, 'u_linewidth')
        GL.glUniform1fv(uni_ulinewidth, 1, u_linewidth)
        uni_uantialias = GL.glGetUniformLocation(self.program, 'u_antialias')
        GL.glUniform1fv(uni_uantialias, 1, u_antialias)
        uni_usize = GL.glGetUniformLocation(self.program, 'u_size')
        GL.glUniform1fv(uni_usize, 1, u_size)

        GL.glBindVertexArray(self.vertex_array_object)
        if self.coords is None:
            pass
        else:
            GL.glDrawArrays(GL.GL_POINTS, 0, len(self.coords) / 3)
        GL.glBindVertexArray(0)
        GL.glUseProgram(0)
Ejemplo n.º 6
0
 def _zoom_view(self, dy):
     """ Function doc """
     delta = (((self.z_far - self.z_near) / 2.0) + self.z_near) / 200.0
     move_z = dy * delta
     moved_mat = cam.my_glTranslatef(self.view_mat, [0.0, 0.0, move_z])
     moved_pos = cam.get_xyz_coords(moved_mat)
     if moved_pos[2] > 0.101:
         self.view_mat = moved_mat
         self.z_near -= move_z
         self.z_far -= move_z
         if self.z_near >= self.min_znear:
             self.proj_mat = cam.my_glPerspectivef(self.fov, self.var,
                                                   self.z_near, self.z_far)
         else:
             if self.z_far < (self.min_zfar + self.min_znear):
                 self.z_near += move_z
                 self.z_far = self.min_zfar + self.min_znear
             self.proj_mat = cam.my_glPerspectivef(self.fov, self.var,
                                                   self.min_znear,
                                                   self.z_far)
     else:
         pass
     return True
Ejemplo n.º 7
0
 def initialize(self, widget):
     """ Function doc """
     aloc = self.get_allocation()
     self.width = np.float32(aloc.width)
     self.height = np.float32(aloc.height)
     self.z_near = 1.0
     self.z_far = 9.0
     self.min_znear = 0.1
     self.min_zfar = 1.1
     self.model_mat = np.identity(4, dtype=np.float32)
     self.view_mat = cam.my_glTranslatef(np.identity(4, dtype=np.float32),
                                         [0, 0, -5])
     self.cam_pos = self.get_cam_pos()
     #----------------------------------------------------------------------#
     #self.top = self.z_near * np.degrees(np.tan(np.pi*30/360))
     #self.bottom = -self.top
     #self.right = self.top * self.width / self.height
     #self.left = -self.right
     #self.proj_mat = cam.my_gluFrustumf(self.left, self.right, self.bottom, self.top, self.z_near, self.z_far)
     #----------------------------------------------------------------------#
     self.fov = 20.0  # Field Of View = fov
     self.var = self.width / self.height  # Viewport Aspect Ratio
     self.proj_mat = cam.my_glPerspectivef(self.fov, self.var, self.z_near,
                                           self.z_far)
     self.set_has_depth_buffer(True)
     self.set_has_alpha(True)
     self.gl_programs = True
     self.right = self.width / self.height
     self.left = -self.right
     self.top = 1.0
     self.bottom = -1.0
     self.scroll = 0.3
     self.edit_points = []
     self.editing = False
     self.mouse_rotate = False
     self.mouse_pan = False
     self.mouse_zoom = False
     self.mouse_x = 0
     self.mouse_y = 0
     self.drag_pos_x = 0
     self.drag_pos_y = 0
     self.drag_pos_z = 0
     self.dx = 0.0
     self.dy = 0.0
     self.start_time = time.perf_counter()
     self.ctrl = False
     self.shift = False
     self.bckgrnd_color = np.array([0.0, 0.0, 0.0, 1.0], dtype=np.float32)
     self.light_position = np.array([-2.5, 2.5, 2.5], dtype=np.float32)
     self.light_color = np.array([1.0, 1.0, 1.0, 1.0], dtype=np.float32)
     self.light_ambient_coef = 0.5
     self.light_shininess = 5.5
     self.light_intensity = np.array([0.6, 0.6, 0.6], dtype=np.float32)
     self.light_specular_color = np.array([1.0, 1.0, 1.0], dtype=np.float32)
     # Here are the test programs and flags
     self.gl_program_dots = None
     self.dots_vao = None
     self.dots_vbos = None
     self.dots_elemns = None
     self.dots = False
     self.gl_program_diamonds = None
     self.diamonds_vao = None
     self.diamonds_vbos = None
     self.diamonds_elemns = None
     self.diamonds = False
     self.gl_program_circles = None
     self.circles_vao = None
     self.circles_vbos = None
     self.circles_elemns = None
     self.circles = False
     self.gl_program_lines = None
     self.lines_vao = None
     self.lines_vbos = None
     self.lines_elemns = None
     self.lines = False
     self.gl_program_antialias = None
     self.antialias_vao = None
     self.antialias_vbos = None
     self.antialias_elemns = None
     self.antialias = False
     self.antialias_length = 0.03
     self.gl_program_pseudospheres = None
     self.pseudospheres_vao = None
     self.pseudospheres_vbos = None
     self.pseudospheres_elemns = None
     self.pseudospheres = False
     self.gl_program_geom_cones = None
     self.geom_cones_vao = None
     self.geom_cones_vbos = None
     self.geom_cones_elemns = None
     self.geom_cones = False
     self.gl_program_arrow = None
     self.arrow_vao = None
     self.arrow_vbos = None
     self.arrow_elemns = None
     self.arrow = False
     self.gl_program_select_box = None
     self.select_box_vao = None
     self.select_box_vbos = None
     self.select_box_elemns = None
     self.select_box = False
     self.gl_program_edit_mode = None
     self.edit_mode_vao = None
     self.edit_mode_vbos = None
     self.edit_mode_elemns = None
     self.modified_points = False
     self.gl_program_texture = None
     self.texture_vao = None
     self.texture_vbos = None
     self.texture_elemns = None
     self.texture = False
     self.tex = None