Esempio n. 1
0
 def set_view_up_direction(self, viewer_up):
     if abs(viewer_up.y) < 0.999:
         cp = cross_product(viewer_up, Vector3(0, 0, 0))
         cp = normalized(cp)
         self.geo_to_viewer_transform = create_rotation(math.acos(viewer_up.y), cp)
     else:
         self.geo_to_viewer_transform = create_identity()
         
     self.must_update_transformed_orientation = True
Esempio n. 2
0
 def begin_drawing(self, gl):
     '''
     Sets OpenGL state for rapid drawing
     '''
     self.texture_ref.bind(gl)
     gl.glShadeModel(gl.GL_FLAT)
     
     ########################################################################## added Blending
     gl.glEnable(gl.GL_BLEND)
     gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     
     gl.glEnable(gl.GL_ALPHA_TEST)
     gl.glAlphaFunc(gl.GL_GREATER, 0.5)
     gl.glEnable(gl.GL_TEXTURE_2D)
     
     # We're going to do the transformation on the CPU, so set the matrices 
     # to the identity
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glPushMatrix()
     gl.glLoadIdentity()
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glPushMatrix()
     gl.glLoadIdentity()
     gl.glOrtho(0, self.render_state.screen_width,
                 0, self.render_state.screen_height,
                 -1, 1)
     
     # equivalent of a call to GLBuffer.unbind(gl)
     gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
     gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, 0)
     
     gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
     gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
     gl.glDisableClientState(gl.GL_COLOR_ARRAY)
 
     rs = self.render_state
     
     view_width = rs.screen_width
     view_height = rs.screen_height
     
     rotation = create_rotation(rs.up_angle, rs.look_dir)
     self.label_offset = multiply_MV(rotation, rs.up_dir)
 
     # If a label isn't within the field of view angle from the target vector, it can't
     # be on the screen.  Compute the cosine of this angle so we can quickly identify these.
     DEGREES_TO_RADIANS = math.pi / 180.0
     self.dot_product_threshold = math.cos(rs.radius_of_view * DEGREES_TO_RADIANS * \
                                         (1 + view_width / float(view_height)) * 0.5)
Esempio n. 3
0
    def begin_drawing(self, gl):
        '''
        Sets OpenGL state for rapid drawing
        '''
        self.texture_ref.bind(gl)
        gl.glShadeModel(gl.GL_FLAT)

        ########################################################################## added Blending
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        gl.glEnable(gl.GL_ALPHA_TEST)
        gl.glAlphaFunc(gl.GL_GREATER, 0.5)
        gl.glEnable(gl.GL_TEXTURE_2D)

        # We're going to do the transformation on the CPU, so set the matrices
        # to the identity
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        gl.glOrtho(0, self.render_state.screen_width, 0,
                   self.render_state.screen_height, -1, 1)

        # equivalent of a call to GLBuffer.unbind(gl)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
        gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, 0)

        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
        gl.glDisableClientState(gl.GL_COLOR_ARRAY)

        rs = self.render_state

        view_width = rs.screen_width
        view_height = rs.screen_height

        rotation = create_rotation(rs.up_angle, rs.look_dir)
        self.label_offset = multiply_MV(rotation, rs.up_dir)

        # If a label isn't within the field of view angle from the target vector, it can't
        # be on the screen.  Compute the cosine of this angle so we can quickly identify these.
        DEGREES_TO_RADIANS = math.pi / 180.0
        self.dot_product_threshold = math.cos(rs.radius_of_view * DEGREES_TO_RADIANS * \
                                            (1 + view_width / float(view_height)) * 0.5)