Ejemplo n.º 1
0
    def draw_arrow(self, color):

        # Set material
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color)
        #glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color)
        #glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1, 1, 1, 0.0])
        #glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20)

        # Draw cylinder
        quad = gluNewQuadric()
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        gluCylinder(quad, self.size / 30, self.size / 30,
                    self.size * 0.8, 20, 20)

        # Move to the arrowhead position
        glTranslatef(0, 0, self.size * 0.8)

        # Draw arrowhead
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        gluCylinder(quad, self.size / 15, 0,
                    self.size * 0.2, 20, 20)

        # Revert to the original position
        glTranslatef(0, 0, -self.size * 0.8)
Ejemplo n.º 2
0
    def render(self):
        glPushMatrix()
        glMultMatrixf(numpy.transpose(self.translation))
        glMultMatrixf(self.scalemat)
        cur_color = color.COLORS[self.color_index]
        glColor3f(cur_color[0], cur_color[1], cur_color[2])
        if self.selected:  # emit light if the node is selected
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.3, 0.3, 0.3])
        glCallList(self.call_list)
        if self.selected:
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0])

        glPopMatrix()
Ejemplo n.º 3
0
    def render(self):
        """ renders the item to the screen """
        glPushMatrix()
        glMultMatrixf(numpy.transpose(self.translation_matrix))
        glMultMatrixf(self.scaling_matrix)
        cur_color = color.COLORS[self.color_index]
        glColor3f(cur_color[0], cur_color[1], cur_color[2])
        if self.selected:  # emit light if the node is selected
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.3, 0.3, 0.3])

        self.render_self()

        if self.selected:
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0])
        glPopMatrix()
Ejemplo n.º 4
0
    def init_opengl(self, width, height, x, y):
        glutInit()
        glutInitWindowPosition(x, y)
        glutInitWindowSize(width, height)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE)
        glutCreateWindow("Rainbow Alga")
        glutDisplayFunc(self.render)
        glutIdleFunc(self.render)
        glutReshapeFunc(self.resize)

        glutMouseFunc(self.mouse)
        glutMotionFunc(self.drag)
        glutKeyboardFunc(self.keyboard)
        glutSpecialFunc(self.special_keyboard)

        glClearDepth(1.0)
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 3000)
        glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)


        # Lighting
        light_ambient = (0.0, 0.0, 0.0, 1.0)
        light_diffuse = (1.0, 1.0, 1.0, 1.0)
        light_specular = (1.0, 1.0, 1.0, 1.0)
        light_position = (-100.0, 100.0, 100.0, 0.0)

        mat_ambient = (0.7, 0.7, 0.7, 1.0)
        mat_diffuse = (0.8, 0.8, 0.8, 1.0)
        mat_specular = (1.0, 1.0, 1.0, 1.0)
        high_shininess = (100)

        glEnable(GL_LIGHT0)
        glEnable(GL_NORMALIZE)
        glEnable(GL_COLOR_MATERIAL)
        glEnable(GL_LIGHTING)

        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse)
        glLightfv(GL_LIGHT0, GL_SPECULAR,  light_specular)
        glLightfv(GL_LIGHT0, GL_POSITION, light_position)

        glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient)
        glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse)
        glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular)
        glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess)

        # Transparency
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Ejemplo n.º 5
0
    def apply(self, face=GL_FRONT_AND_BACK):
        '''Apply the material on current context'''
        if self.texture:
            self.texture.enable()
            self.texture.bind()
            glEnable(GL_COLOR_MATERIAL)

        glMaterialfv(face, GL_DIFFUSE, self.diffuse + [self.opacity])
        glMaterialfv(face, GL_AMBIENT, self.ambient + [self.opacity])
        glMaterialfv(face, GL_SPECULAR, self.specular + [self.opacity])
        glMaterialfv(face, GL_EMISSION, self.emission + [self.opacity])
        glMaterialf(face, GL_SHININESS, self.shininess)
        glColorMaterial(face, GL_AMBIENT_AND_DIFFUSE)
Ejemplo n.º 6
0
    def apply(self, face=GL_FRONT_AND_BACK):
        '''Apply the material on current context'''
        if self.texture:
            self.texture.enable()
            self.texture.bind()
            glEnable(GL_COLOR_MATERIAL)

        glMaterialfv(face, GL_DIFFUSE, self.diffuse + [self.opacity])
        glMaterialfv(face, GL_AMBIENT, self.ambient + [self.opacity])
        glMaterialfv(face, GL_SPECULAR, self.specular + [self.opacity])
        glMaterialfv(face, GL_EMISSION, self.emission + [self.opacity])
        glMaterialf(face, GL_SHININESS, self.shininess)
        glColorMaterial(face, GL_AMBIENT_AND_DIFFUSE)
Ejemplo n.º 7
0
    def _set_color(color: List[float]):
        """Modifies the OpenGL state's active material with a specific color
        used on the specular & diffuse channels, with limited ambient.

        This function must be invoked inside the OpenGL render loop.

        :param color: the color to use for the material
        """
        glColor(color)
        glMaterialfv(GL_FRONT, GL_AMBIENT, [color[0] * 0.1, color[1] * 0.1, color[2] * 0.1, 1.0])
        glMaterialfv(GL_FRONT, GL_DIFFUSE, color)
        glMaterialfv(GL_FRONT, GL_SPECULAR, color)

        glMaterialfv(GL_FRONT, GL_SHININESS, 10.0)
Ejemplo n.º 8
0
    def _make_list( self ):
        """generate opengl display list to draw triangles in mesh
        """
        # get available list name
        self.list_name = glGenLists( 1 )

        # start new display list
        glNewList( self.list_name, GL_COMPILE )

        # set material
        glMaterialfv( GL_FRONT, GL_SPECULAR, self.specular )
	glMaterialfv( GL_FRONT, GL_SHININESS, self.shininess )
        glMaterialfv( GL_FRONT, GL_DIFFUSE, self.diffuse )
        
        # start list of triangles in mesh
        glBegin( GL_TRIANGLES )

        # for each triangle give normal and 3 vertices
        for triangle in self.triangles:
            glNormal3f( *triangle[0] )
            for i in range( 1, 4 ):
                glVertex3f( *triangle[i] )
        
        glEnd()
        glEndList()
Ejemplo n.º 9
0
    def InitGL(self):
        glClearColor(0.0, 0.0, 0.0, 1)
        glColor3f(1, 0, 0)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_LIGHT1)

        glLightfv(GL_LIGHT0, GL_POSITION, vec(.5, .5, 1, 0))
        glLightfv(GL_LIGHT0, GL_SPECULAR, vec(.5, .5, 0.5, 1))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(1, 1, 1, 1))
        glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 0, .5, 0))
        glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.5, .5, .5, 1))
        glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1, 1, 1, 1))

        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
                     vec(0.5, 0, 0.3, 1))
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1))
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80)
        glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0.1, 0.1, 0.1, 0.9))

        glLightfv(GL_LIGHT0, GL_POSITION, vec(0.0, 200.0, 100.0, 1))
        glLightfv(GL_LIGHT1, GL_POSITION, vec(0.0, -200.0, 100.0, 1))
Ejemplo n.º 10
0
    def render(self):
        if self.list < 0:
            self.list = glGenLists(1)
            glNewList(self.list, GL_COMPILE)

            for n, f in enumerate(self.faces):
                glMaterialfv(GL_FRONT, GL_DIFFUSE, self.colors[n])
                glMaterialfv(GL_FRONT, GL_SPECULAR, self.colors[n])
                glMaterialf(GL_FRONT, GL_SHININESS, 50.0)
                glColor4fv(self.colors[n])

                glBegin(GL_POLYGON)
                if self.colors[n][0] > 0:
                    glNormal3fv(self.normals[n])

                for i in f:
                    if self.colors[n][1] > 0:
                        glNormal3fv(self.vnormals[i])
                    glVertex3fv(self.vertices[i])
                glEnd()
            glEndList()
        glCallList(self.list)
Ejemplo n.º 11
0
    def _apply_material(material: dict):
        """Utility function to apply a specific MTL material to the current
        OpenGL rendering state.

        :param material: A dictionary of MTL attributes defining a material.
        """
        def _as_rgba(color):
            if len(color) >= 4:
                return color
            # RGB - add alpha defaulted to 1
            return color + [1.0]

        if 'texture_Kd' in material:
            # use diffuse texture map
            glBindTexture(GL_TEXTURE_2D, material['texture_Kd'])
        else:
            # No texture map
            glBindTexture(GL_TEXTURE_2D, 0)

        # Diffuse light
        mtl_kd_rgba = _as_rgba(material['Kd'])
        glColor(mtl_kd_rgba)

        # Ambient light
        if 'Ka' in material:
            mtl_ka_rgba = _as_rgba(material['Ka'])
            glMaterialfv(GL_FRONT, GL_AMBIENT, mtl_ka_rgba)
            glMaterialfv(GL_FRONT, GL_DIFFUSE, mtl_kd_rgba)
        else:
            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mtl_kd_rgba)

        # Specular light
        if 'Ks' in material:
            mtl_ks_rgba = _as_rgba(material['Ks'])
            glMaterialfv(GL_FRONT, GL_SPECULAR, mtl_ks_rgba)
            if 'Ns' in material:
                specular_exponent = material['Ns']
                glMaterialfv(GL_FRONT, GL_SHININESS, specular_exponent)
Ejemplo n.º 12
0
def apply_material(color, glprefs = None):
    # todo: move into glprefs.py (see comment above for why)
    """
    In the current GL context,
    set material parameters based on the given color (length 3 or 4) and
    the material-related prefs values in glprefs (which defaults to
    drawing_globals.glprefs).
    """
    if glprefs is None:
        glprefs = drawing_globals.glprefs
        pass
    
    #bruce 051215: make sure color is a tuple, and has length exactly 4, for all
    # uses inside this function, assuming callers pass sequences of length 3 or
    # 4. Needed because glMaterial requires four-component vector and PyOpenGL
    # doesn't check. [If this is useful elsewhere, we can split it into a
    # separate function.]
    color = tuple(color)
    if len(color) == 3:
        color = color + (1.0,) # usual case
    elif len(color) != 4:
        # should never happen; if it does, this assert will always fail
        assert len(color) in [3,4], \
               "color tuples must have length 3 or 4, unlike %r" % (color,)

    glColor4fv(color)          # For drawing lines with lighting disabled.

    if not glprefs.enable_specular_highlights:
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color)
        # glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (0,0,0,1))
        return

    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color)

    whiteness = glprefs.specular_whiteness
    brightness = glprefs.specular_brightness
    if whiteness == 1.0:
        specular = (1.0, 1.0, 1.0, 1.0) # optimization
    else:
        if whiteness == 0.0:
            specular = color # optimization
        else:
            # assume color[3] (alpha) is not passed or is always 1.0
            c1 = 1.0 - whiteness
            specular = ( c1 * color[0] + whiteness,
                         c1 * color[1] + whiteness,
                         c1 * color[2] + whiteness, 1.0 )
    if brightness != 1.0:
        specular = ( specular[0] * brightness,
                     specular[1] * brightness,
                     specular[2] * brightness, 1.0 )
            #e Could optimize by merging this with above 3 cases (or, of course,
            #  by doing it in C, which we'll do eventually.)
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular)

    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS,
                glprefs.specular_shininess)
    return
Ejemplo n.º 13
0
def apply_material(color, glprefs=None):
    # todo: move into glprefs.py (see comment above for why)
    """
    In the current GL context,
    set material parameters based on the given color (length 3 or 4) and
    the material-related prefs values in glprefs (which defaults to
    drawing_globals.glprefs).
    """
    if glprefs is None:
        glprefs = drawing_globals.glprefs
        pass

    #bruce 051215: make sure color is a tuple, and has length exactly 4, for all
    # uses inside this function, assuming callers pass sequences of length 3 or
    # 4. Needed because glMaterial requires four-component vector and PyOpenGL
    # doesn't check. [If this is useful elsewhere, we can split it into a
    # separate function.]
    color = tuple(color)
    if len(color) == 3:
        color = color + (1.0, )  # usual case
    elif len(color) != 4:
        # should never happen; if it does, this assert will always fail
        assert len(color) in [3,4], \
               "color tuples must have length 3 or 4, unlike %r" % (color,)

    glColor4fv(color)  # For drawing lines with lighting disabled.

    if not glprefs.enable_specular_highlights:
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color)
        # glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (0,0,0,1))
        return

    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color)

    whiteness = glprefs.specular_whiteness
    brightness = glprefs.specular_brightness
    if whiteness == 1.0:
        specular = (1.0, 1.0, 1.0, 1.0)  # optimization
    else:
        if whiteness == 0.0:
            specular = color  # optimization
        else:
            # assume color[3] (alpha) is not passed or is always 1.0
            c1 = 1.0 - whiteness
            specular = (c1 * color[0] + whiteness, c1 * color[1] + whiteness,
                        c1 * color[2] + whiteness, 1.0)
    if brightness != 1.0:
        specular = (specular[0] * brightness, specular[1] * brightness,
                    specular[2] * brightness, 1.0)
        #e Could optimize by merging this with above 3 cases (or, of course,
        #  by doing it in C, which we'll do eventually.)
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular)

    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, glprefs.specular_shininess)
    return
Ejemplo n.º 14
0
    def renderizar(self):
        glBegin(GL_LINES)

        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, self.cor)
        glMaterialfv(GL_FRONT, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0))
        glMaterialfv(GL_FRONT, GL_SPECULAR, 1.0, 1.0, 1.0, 1.0)
        glMateriali(GL_FRONT, GL_SHININESS, 128)

        for aresta in Cubo.arestas:
            for ponto in aresta:
                glVertex3fv(self.vertices[ponto])
        glEnd()
Ejemplo n.º 15
0
    def handle_draw( self ):
        """draw a teapot
        """
        #print "handle draw 0"
        glMaterialfv( GL_FRONT, GL_SPECULAR, self.specular )
	glMaterialfv( GL_FRONT, GL_SHININESS, self.shininess )
        glMaterialfv( GL_FRONT, GL_DIFFUSE, self.diffuse )

        if self.teapot:
            glutSolidTeapot( 10.0 )
        else:
            glutSolidSphere( 10.0, 12, 12 )
Ejemplo n.º 16
0
    def display(self, color: List[float], draw_solid: bool):
        """Displays the cube with a specific color.

        :param color: Color to display the cube.
        :param draw_solid: Whether to draw solid polygons (False to draw wireframe).
        """
        glColor(color)

        if draw_solid:
            ambient_color = [color[0] * 0.1, color[1] * 0.1, color[2] * 0.1, 1.0]
        else:
            ambient_color = color
        glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_color)
        glMaterialfv(GL_FRONT, GL_DIFFUSE, color)
        glMaterialfv(GL_FRONT, GL_SPECULAR, color)

        glMaterialfv(GL_FRONT, GL_SHININESS, 10.0)

        if draw_solid:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        self.display_by_key(self._display_list_name)
Ejemplo n.º 17
0
    def draw( self ):
        """draw a cube using glut solid cube
        """
        # save current matrix
        glPushMatrix()

        # set material
        glMaterialfv( GL_FRONT, GL_SPECULAR, self.specular )
	glMaterialfv( GL_FRONT, GL_SHININESS, self.shininess )
        glMaterialfv( GL_FRONT, GL_DIFFUSE, self.diffuse )

        # move to centroid
        glTranslatef( *self.centroid )

        # draw cube
        glutSolidCube( self.size )

        # restore matrix
        glPopMatrix()
Ejemplo n.º 18
0
 def paintGL(self):
     """
     Drawing routine
     """
     if self._fatal_error: return
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     GL.glEnable(GL.GL_NORMALIZE)
     amb = [0., 0.0, 0.0, 1.]
     spec = [1.0, 1., 1., 1]
     shine = 80.
     glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, amb)
     glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, shine)
     glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, spec)
     GL.glMatrixMode(GL.GL_MODELVIEW)
     GL.glPushMatrix()
     GL.glScalef(self.zoom, self.zoom, self.zoom)
     #glRotate(self.rotation[0], 1., 0., 0.)
     #glRotate(self.rotation[1], 0., 1., 0.)
     mx=np.zeros([4,4])
     mx[0:3,0:3] = self.rotation
     mx[3,3]=1.
     GL.glMultMatrixf(mx)
     
     for index, coords in self.coords.items():
         if coords is None:
             continue
         if index == 1:
             color = [0.65, 0.0, 0.0, 1.]
         if index == 2:
             color = [0.00, 0.65, 0., 1.]
         GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color)
         try:
             self.system.draw(coords, index)
         except NotImplementedError:
             self._fatal_error = True
             raise
     
     GL.glPopMatrix()    
     GL.glFlush()
Ejemplo n.º 19
0
    def paintGL(self):
        """
        Drawing routine
        """
        if self._fatal_error: return
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glEnable(GL.GL_NORMALIZE)
        amb = [0., 0.0, 0.0, 1.]
        spec = [1.0, 1., 1., 1]
        shine = 80.
        glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, amb)
        glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, shine)
        glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, spec)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        GL.glScalef(self.zoom, self.zoom, self.zoom)
        #glRotate(self.rotation[0], 1., 0., 0.)
        #glRotate(self.rotation[1], 0., 1., 0.)
        mx = np.zeros([4, 4])
        mx[0:3, 0:3] = self.rotation
        mx[3, 3] = 1.
        GL.glMultMatrixf(mx)

        for index, coords in self.coords.items():
            if coords is None:
                continue
            if index == 1:
                color = [0.65, 0.0, 0.0, 1.]
            if index == 2:
                color = [0.00, 0.65, 0., 1.]
            GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color)
            try:
                self.system.draw(coords, index)
            except NotImplementedError:
                self._fatal_error = True
                raise

        GL.glPopMatrix()
        GL.glFlush()
Ejemplo n.º 20
0
 def apply_material(self):
     # Set material
     glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, self.ambient_color)
     glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, self.diffuse_color)
     glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1, 1, 1, 0.0])
     glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20)
Ejemplo n.º 21
0
 def material(cls, face: MaterialFace,
              material_parameter: MaterialParameter, value):
     if isinstance(value, Iterable):
         glMaterialfv(face.value, material_parameter.value, value)
     else:
         glMaterialf(face.value, material_parameter.value, value)
Ejemplo n.º 22
0
    def display(self):
        if self.knowledge_base:
            # update the world
            if self.knowledge_base.shelf_xform:
                # load the shelf once a transform is available
                if not self.shelf:
                    self.shelf = self.world.loadRigidObject("klampt_models/north_shelf/shelf_with_bins.obj")
                    logger.info("spawned shelf model")
                self.shelf.setTransform(*self.knowledge_base.shelf_xform)

            if self.knowledge_base.order_bin_xform:
                # load the order bin once a transform is available
                if not self.order_bin:
                    self.order_bin = self.world.loadRigidObject("klampt_models/apc_bin/apc_bin.obj")
                    logger.info("spawned order bin model")
                self.order_bin.setTransform(*self.knowledge_base.order_bin_xform)

            # spawn/update objects
            for (name, xform) in self.knowledge_base.object_xforms.items():
                # load the object once a transform is availale
                if name not in self.objects:
                    body = self.world.loadRigidObject("klampt_models/items/{0}/{0}.obj".format(name))
                    logger.info("spawned {} model".format(name))

                    # load the point cloud
                    if name in self.knowledge_base.object_clouds:
                        self.n += 1
                        display_list = glGenLists(self.n)

                        # compile the display list
                        glNewList(display_list, GL_COMPILE)
                        glDisable(GL_LIGHTING)
                        glBegin(GL_POINTS)
                        points = self.knowledge_base.object_clouds[name]
                        for point in points:
                            if len(point) == 2:
                                xyz = point[0]
                                rgb = point[1]
                            else:
                                xyz = point[:3]
                                if len(point) == 4:
                                    rgb = point[3]
                                elif len(point) > 3:
                                    rgb = point[3:6]
                                else:
                                    rgb = None

                            if rgb is not None:
                                glColor3f(*map(lambda x: x / 255.0, rgb))
                            else:
                                glColor3f(*colors[i % len(colors)])
                            glVertex3f(*xyz[:3])
                        glEnd()
                        glEndList()
                        logging.debug("compiled {} points for {}".format(len(points), name))
                    else:
                        display_list = None

                    self.objects[name] = {"body": body, "display_list": display_list}

                # self.objects[name]['body'].setTransform(*xform)

            # delete objects
            for (name, props) in self.objects.items():
                if name not in self.knowledge_base.object_xforms:
                    # remove the object
                    # XXX: cannot actually delete object... so move it far away... very far away
                    props["body"].setTransform(so3.identity(), [1e3, 1e3, 1e3])
                    del self.objects[name]

        # update the robot state
        if self.robot_state:
            try:
                self.robot.setConfig(self.robot_state.sensed_config)
            except TypeError as e:
                logger.error("error visualizing config: {}".format(self.robot_state.sensed_config))
                logger.error(traceback.format_exc())
                sys.exit(-1)

        self.world.drawGL()

        # draw commanded configurations
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, [0, 1, 0, 0.5])

        if self.robot_state:
            qi = self.robot.getConfig()
            self.robot.setConfig(self.robot_state.commanded_config)
            self.robot.drawGL(False)
            self.robot.setConfig(qi)

        glDisable(GL_BLEND)

        # draw the point clouds
        glPointSize(2)
        for (name, props) in self.objects.items():
            if "display_list" in props:
                glCallList(props["display_list"])

        # draw gripper link transforms
        for name in ["left_gripper", "right_gripper"]:
            gldraw.xform_widget(self.robot.getLink(name).getTransform(), 0.1, 0.01)
        # draw axis-aligned axes for reference
        gldraw.xform_widget((so3.identity(), [0, 0, 1]), 0.1, 0.01)
        # draw local origins of objects
        if self.knowledge_base:
            for xform in self.knowledge_base.object_xforms.values():
                gldraw.xform_widget(xform, 0.1, 0.01)
Ejemplo n.º 23
0
 def inicializar_renderizacao():
     glBegin(GL_QUADS)
     glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, Esfera.cor)
     glMaterialfv(GL_FRONT, GL_SPECULAR, 0.4, 0.4, 0.4, 0.2)
     glMateriali(GL_FRONT, GL_SHININESS, 128)
Ejemplo n.º 24
0
    def __draw_visualisations(self, triangles, frame, leds_vertices,
                              intensities):

        # dict_properties = getPropertiesFile("../properties/default.properties")
        # _frame_objfilename = dict_properties['FrameModel']['frame.objfilename']
        # _frame_scale = float(dict_properties['FrameModel']['frame.scale'])
        _frame_objfilename = property_to_string(section="FrameModel",
                                                key="frame.objfilename")
        _frame_scale = property_to_number(section="FrameModel",
                                          key="frame.scale",
                                          vmin=0,
                                          vmax=None,
                                          vtype=float)

        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, (0.0, 0.0, 0.0, 1))
        glMaterialfv(GL_FRONT, GL_SPECULAR, (0, 0, 0, .2))
        glMaterialf(GL_FRONT, GL_SHININESS, 20)
        draw_wire_frame_of_obj_from_filename(_frame_objfilename,
                                             scale=float(_frame_scale) * 1.04)
        # if not EvaluatorGeneric.warned:
        #     print("Frame has n mounting points available:"+str(len(frame)))
        #     EvaluatorGeneric.warned=True

        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, (.2, 0.2, 0.2, 1))
        glMaterialfv(GL_FRONT, GL_SPECULAR, (1, 0, 0, .2))
        glMaterialf(GL_FRONT, GL_SHININESS, 20)
        for j in range(len(frame)):
            draw_point(frame[j], size=8) if frame[j] is not None else None

        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, (1.0, 0.0, 0.0, 1))
        glMaterialfv(GL_FRONT, GL_SPECULAR, (1, 0, 0, .2))
        glMaterialf(GL_FRONT, GL_SHININESS, 20)
        for i in range(len(leds_vertices)):
            led = leds_vertices[i]
            draw_wire_sphere(vertex=led, size=0.35,
                             scale=1) if led is not None else None

        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, (0.2, 0.2, 0.6, 1))
        glMaterialfv(GL_FRONT, GL_SPECULAR, (1, 1, 1, .2))
        glMaterialf(GL_FRONT, GL_SHININESS, 99)
        for tri in triangles:
            make_triangle_face(tri)
Ejemplo n.º 25
0
    def display(self):

        glLoadIdentity()
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        gluLookAt(self.cam_pos.x, self.cam_pos.y, self.cam_pos.z,
                  self.cam_focus.x, self.cam_focus.y, self.cam_focus.z, 0, 1,
                  0)

        self.level.draw()

        glLoadIdentity()

        gluLookAt(0, -0.5, 2.5, 0, 0, 0, 0, 1, 0)

        wdth = 0.3
        glTranslate(
            0.0 -
            (len(self.level.solomon.current_state.keys()) - 1) * wdth / 2.0,
            -1.3, 0)

        if debug == True:
            for k in self.level.solomon.current_state.keys():
                col = "red"
                if self.level.solomon.current_state[k]: col = "green"
                glMaterialfv(GL_FRONT, GL_DIFFUSE, colours[col])
                glutSolidCube(wdth - 0.02)
                glTranslate(wdth, 0, 0)
                glPushMatrix()
                #glLoadIdentity()
                glScale(0.005, 0.01, -0.01)
                glTranslate(-90, 4, -20)
                #glTranslate(-180,-70,0)
                glTranslate(-wdth, 0, 0)
                self.letters.drawString(k[:4])
                glPopMatrix()

        glLoadIdentity()

        gluLookAt(0, -0.5, 2.5, 0, 0, 0, 0, 1, 0)

        wdth = 0.2

        joystick_actions = [x for x in dir(self.joystick) if x[0:2] == "is"]
        glTranslate(0.0 - (len(joystick_actions) - 1) * wdth / 2.0, -1.0, 0)

        if debug == True:
            for k in joystick_actions:
                #print(k)
                col = "red"
                if getattr(self.joystick, k)(self.keys): col = "green"
                glMaterialfv(GL_FRONT, GL_DIFFUSE, colours[col])
                glutSolidCube(wdth - 0.02)
                glTranslate(wdth, 0, 0)
                glPushMatrix()
                #glLoadIdentity()
                glScale(0.005, 0.01, -0.01)
                glTranslate(-45, 0, -20)
                #glTranslate(-180,-70,0)
                glTranslate(-wdth, 0, 0)
                self.letters.drawString(k[2:4])
                glPopMatrix()

        glLoadIdentity()

        gluLookAt(0, 0, 2.5, 0, 0, 0, 0, 1, 0)

        glScale(0.01, 0.01, -0.01)
        glTranslate(-180, -70, 0)

        if debug == True:
            self.letters.drawString('X:' + str(self.level.solomon.x) + ' Y:' +
                                    str(self.level.solomon.y))
            glTranslate(0, 0 - 15, 0)
            gx, gy = int(self.level.solomon.x), int(self.level.solomon.y)
            self.letters.drawString('G {0} on: {1} below: {2}'.format(
                str((gx, gy)), self.level.grid[gy][gx],
                self.level.grid[gy - 1][gx]))
            glTranslate(0, 0 - 15, 0)
            self.letters.drawString('')

        glutSwapBuffers()
Ejemplo n.º 26
0
 def apply_material(self):
     # Set material
     glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, self.ambient_color)
     glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, self.diffuse_color)
     glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1, 1, 1, 0.0])
     glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20)