示例#1
0
 def _line(self, r1, r2):
     glColor(1, 1, 1)
     glLineWidth(1)
     glBegin(GL_LINES)
     glVertex3f(r1[0], r1[1], 0.0)
     glVertex3f(r2[0], r2[1], 0.0)
     glEnd()
 def plano_vertical_arriba(self):
     if self.programa.ajustes.ver_plano_vertical.isChecked():
         glBegin(GL_QUADS)
         glColor(self.programa.ajustes.color_plano_vertical)
         for vertex in range(4):
             glVertex(self.vertices_plano_vertical_arriba[vertex])
         glEnd()
示例#3
0
    def __gen_gl_code(faces, mtls, normals, vertices, texcoords):
        gl_list = glGenLists(1)
        glNewList(gl_list, GL_COMPILE)
        glEnable(GL_TEXTURE_2D)
        glFrontFace(GL_CCW)
        for face in faces:
            face_vertices, face_normals, texture_coords, material = face

            try:
                mtl = mtls[material]
                if 'texture_Kd' in mtl:
                    # use diffuse texmap
                    glBindTexture(GL_TEXTURE_2D, mtl['texture_Kd'])
                else:
                    # just use diffuse colour
                    glColor(mtl['Kd'])
            except KeyError:
                print("Key error" + str(material))
                glColor((1, 1, 1))

            glBegin(GL_POLYGON)
            for i in range(len(face_vertices)):
                if face_normals[i] > 0:
                    glNormal3fv(normals[face_normals[i] - 1])
                if texture_coords[i] > 0:
                    glTexCoord2fv(texcoords[texture_coords[i] - 1])
                glVertex3fv(vertices[face_vertices[i] - 1])
            glEnd()
        glDisable(GL_TEXTURE_2D)
        glEndList()
        return gl_list
示例#4
0
文件: view.py 项目: eriknelson/gam3
    def paint(self):
        glPushMatrix()

        position = self.player.getPosition()
        glTranslate(position.x, position.y, position.z)
        glRotate(self.player.orientation.y, 0.0, 1.0, 0.0)
        # Slide back because the pyramid below is centered at 0.5, 0, 0.5
        # instead of at the origin.  Without this it rotates around its corner
        # instead of around its center.
        glTranslate(-0.5, 0, -0.5)

        glColor(1.0, 1.0, 1.0)

        glBegin(GL_TRIANGLES)
        glVertex3f(0.5, 0.0, 0.5)
        glVertex3f(0.0, 1.0, 0.0)
        glVertex3f(1.0, 1.0, 0.0)

        glVertex3f(0.5, 0.0, 0.5)
        glVertex3f(1.0, 1.0, 0.0)
        glVertex3f(1.0, 1.0, 1.0)

        glVertex3f(0.5, 0.0, 0.5)
        glVertex3f(1.0, 1.0, 1.0)
        glVertex3f(0.0, 1.0, 1.0)

        glVertex3f(0.5, 0.0, 0.5)
        glVertex3f(0.0, 1.0, 1.0)
        glVertex3f(0.0, 1.0, 0.0)
        glEnd()

        glPopMatrix()
示例#5
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)
示例#6
0
 def _line(self, r1, r2):
     glColor(1, 1, 1)
     glLineWidth(1)
     glBegin(GL_LINES)
     glVertex3f(r1[0], r1[1], 0.0)
     glVertex3f(r2[0], r2[1], 0.0)
     glEnd()
 def plano_horizontal_detras(self):
     if self.programa.ajustes.ver_plano_horizontal.isChecked():
         glBegin(GL_QUADS)
         glColor(self.programa.ajustes.color_plano_horizontal)
         for vertex in range(4):
             glVertex(self.vertices_plano_horizontal_detras[vertex])
         glEnd()
 def bordes_plano_horizontal(self):
     if self.programa.ajustes.ver_plano_horizontal.isChecked():
         glLineWidth(1)
         glColor(self.programa.ajustes.color_plano_horizontal)
         glBegin(GL_LINE_LOOP)
         for vertex in range(4):
             glVertex(self.vertices_borde_plano_horizontal[vertex])
         glEnd()
示例#9
0
 def _rectangle(self, r1, r2):
     glColor(1, 1, 1)
     glLineWidth(1)
     glBegin(GL_LINE_LOOP)
     glVertex3f(r1[0], r1[1], 0.0)
     glVertex3f(r2[0], r1[1], 0.0)
     glVertex3f(r2[0], r2[1], 0.0)
     glVertex3f(r1[0], r2[1], 0.0)
     glEnd()
示例#10
0
文件: view.py 项目: eriknelson/gam3
    def paint(self):
        if self.quad is None:
            self.quad = gluNewQuadric()

        glPushMatrix()
        glColor(self.color.red, self.color.green, self.color.blue)
        glTranslate(self.center.x, self.center.y, self.center.z)
        gluSphere(self.quad, self.radius, 25, 25)
        glPopMatrix()
示例#11
0
 def _rectangle(self, r1, r2):
     glColor(1, 1, 1)
     glLineWidth(1)
     glBegin(GL_LINE_LOOP)
     glVertex3f(r1[0], r1[1], 0.0)
     glVertex3f(r2[0], r1[1], 0.0)
     glVertex3f(r2[0], r2[1], 0.0)
     glVertex3f(r1[0], r2[1], 0.0)
     glEnd()
 def traza_v_recta(self, recta):
     if self.programa.ajustes.rectas_trazas_v.isChecked():
         if recta.traza_v != "Contenida en PV" and recta.ver_traza_vertical.isChecked(
         ):
             if recta.traza_v[0] < 500 and recta.traza_v[1] < 500:
                 glColor(0, 1, 0, 1)
                 glBegin(GL_POINTS)
                 glVertex(recta.traza_v)
                 glEnd()
                 glColor(recta.color)
 def dibujar_circunferencias(self):
     for i in range(self.programa.lista_circunferencias.count()):
         circ = self.programa.lista_circunferencias.itemWidget(
             self.programa.lista_circunferencias.item(i))
         if circ.render.isChecked():
             glColor(circ.color)
             glBegin(GL_LINE_LOOP)
             for punto in circ.puntos:
                 glVertex(*punto)
             glEnd()
 def traza_h_recta(self, recta):
     if self.programa.ajustes.rectas_trazas_h.isChecked():
         if recta.traza_h != "Contenida en PH" and recta.ver_traza_horizontal.isChecked(
         ):
             if recta.traza_h[0] < 500 and recta.traza_h[2] < 500:
                 glColor(1, 0, 0, 1)
                 glBegin(GL_POINTS)
                 glVertex(recta.traza_h)
                 glEnd()
                 glColor(recta.color)
示例#15
0
 def render(self):
     x, y, z = (self.boxHalfExtents.x, self.boxHalfExtents.y, self.boxHalfExtents.z)
     o = self.motion.getWorldTransform().getOrigin()
     glColor(0, 0, 255)
     glTranslate(o.x, o.y, o.z)
     glBegin(GL_TRIANGLE_STRIP)
     glVertex(-x, y, -z)
     glVertex(x, y, -z)
     glVertex(-x, y, z)
     glVertex(x, y, z)
     glEnd()
示例#16
0
    def render(self):
        glColor(0, 1, 1)
        glPushMatrix()
        glTranslate(*self.p)

        if self.skel.m < 10.0:
            glutSolidSphere(0.02, 4, 2)
        else:
            glutSolidSphere(0.06, 4, 2)

        glPopMatrix()
示例#17
0
    def gl_draw(self):
        # if hasattr(self, 'highlight_bg_color') and self in self.get_root().find_widget(mouse.get_pos()).all_parents():
        #    color = self.highlight_bg_color
        # else:
        color = tuple(self.bg_color) + (1.0,)

        glEnable(GL_BLEND)
        glColor(color[0], color[1], color[2], color[3])
        glVertexPointer(2, GL_FLOAT, 0, array([-1, -1, -1, 1, 1, 1, 1, -1], dtype='float32'))
        glDrawArrays(GL_QUADS, 0, 4)
        glDisable(GL_BLEND)
 def dibujar_puntos(self, cuadrante: str):
     for i in range(self.programa.lista_puntos.count()):
         punto = self.programa.lista_puntos.itemWidget(
             self.programa.lista_puntos.item(i))
         if punto.render.isChecked() and punto.cuadrante == cuadrante:
             glColor(punto.color)
             glPointSize(punto.grosor)
             glEnable(GL_POINT_SMOOTH)
             glBegin(GL_POINTS)
             glVertex(punto.x, punto.y, punto.z)
             glEnd()
示例#19
0
    def gl_draw(self):
        #if hasattr(self, 'highlight_bg_color') and self in self.get_root().find_widget(mouse.get_pos()).all_parents():
        #    color = self.highlight_bg_color
        #else:
        color = tuple(self.bg_color) + (1.0,)

        glEnable(GL_BLEND)
        glColor(color[0], color[1], color[2], color[3])
        glVertexPointer(2, GL_FLOAT, 0, array([-1, -1, -1, 1, 1, 1, 1, -1], dtype='float32'))
        glDrawArrays(GL_QUADS, 0, 4)
        glDisable(GL_BLEND)
示例#20
0
 def render(self):
     o = self.motion.getWorldTransform().getOrigin()
     glColor(0, 0, 255)
     glTranslate(o.x, o.y, o.z)
     glBegin(GL_TRIANGLES)
     for i in range(len(self.groundIndices)):
         base = self.groundIndices[i] * 3
         x = self.groundVertices[base]
         y = self.groundVertices[base + 1]
         z = self.groundVertices[base + 2]
         glVertex(x, y, z)
     glEnd()
示例#21
0
 def render(self):
     x, y, z = (self.boxHalfExtents.x, self.boxHalfExtents.y,
                self.boxHalfExtents.z)
     o = self.motion.getWorldTransform().getOrigin()
     glColor(0, 0, 255)
     glTranslate(o.x, o.y, o.z)
     glBegin(GL_TRIANGLE_STRIP)
     glVertex(-x, y, -z)
     glVertex(x, y, -z)
     glVertex(-x, y, z)
     glVertex(x, y, z)
     glEnd()
示例#22
0
 def render(self):
     o = self.motion.getWorldTransform().getOrigin()
     glColor(0, 0, 255)
     glTranslate(o.x, o.y, o.z)
     glBegin(GL_TRIANGLES)
     for i in range(len(self.groundIndices)):
         base = self.groundIndices[i] * 3
         x = self.groundVertices[base]
         y = self.groundVertices[base + 1]
         z = self.groundVertices[base + 2]
         glVertex(x, y, z)
     glEnd()
示例#23
0
 def draw_faces(position: Tuple[int, int], size: Tuple[float, float, float],
                face_color: Tuple[float, float, float]):
     pos_x, pos_y = position
     size_x, size_y, size_z = size
     glColor(face_color)
     for face in Draw.faces:
         glBegin(GL_POLYGON)
         for vertex in face:
             glVertex3f(Draw.vertices[vertex, 0] * size_x + pos_x,
                        -(Draw.vertices[vertex, 1] * size_y + pos_y),
                        Draw.vertices[vertex, 2] * size_z)
         glEnd()
示例#24
0
 def draw_border(position: Tuple[int, int], size: Tuple[float, float,
                                                        float],
                 border_color: Tuple[float, float, float]):
     pos_x, pos_y = position
     size_x, size_y, size_z = size
     glBegin(GL_LINES)
     glColor(border_color)
     for edge in Draw.edges:
         for vertex in edge:
             glVertex3f(Draw.vertices[vertex, 0] * size_x + pos_x,
                        -(Draw.vertices[vertex, 1] * size_y + pos_y),
                        Draw.vertices[vertex, 2] * size_z)
     glEnd()
示例#25
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)
示例#26
0
    def draw(self):
        glDisable(GL_LIGHTING)

        glLineWidth(self._width)
        glColor(*self._color)

        glEnableClientState(GL_VERTEX_ARRAY)

        if self._vbo:
            with self._vbo:
                glVertexPointerf(self._vbo)
                glDrawArrays(GL_LINE_STRIP, 0, len(self._vbo))

        glDisableClientState(GL_VERTEX_ARRAY)

        glEnable(GL_LIGHTING)
示例#27
0
    def display(self):
        self.world.drawGL()

        glDisable(GL_LIGHTING)
        glLineWidth(2.0)

        glEnableClientState(GL_VERTEX_ARRAY)

        for (color, vbo) in self.trace_vbos:
            glColor(*color)
            with vbo:
                glVertexPointerf(vbo)
                glDrawArrays(GL_LINE_STRIP, 0, len(vbo))

        glDisableClientState(GL_VERTEX_ARRAY)

        glEnable(GL_LIGHTING)
示例#28
0
    def paintGL(self):
        """
        Drawing routing
        """
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()

        #Draw spiral in 'immediate mode'
        #WARNING: You should not be doing the spiral calculation inside the loop
        #even if you are using glBegin/glEnd, sin/cos are fairly expensive functions
        #For now left here to make code simpler
        radius = 1.0
        x = radius * math.sin(0)
        y = radius * math.cos(0)
        glColor(0.0, 1.0, 0.0)

        glBegin(GL_LINE_STRIP)
        for deg in range(1000):
            glVertex(x, y, 0.0)
            rad = math.radians(deg)
            radius -= 0.001
            x = radius * math.sin(rad)
            y = radius * math.cos(rad)
        glEnd()

        glEnableClientState(GL_VERTEX_ARRAY)

        #TODO: Use list comprehension
        spiral_array = []

        #Second spiral using "array immediate mode" (i.e vertex arrays)
        radius = 0.8
        x = radius * math.sin(0)
        y = radius * math.cos(0)

        glColor(1.0, 0.0, 0.0)
        for deg in range(820):
            spiral_array.append([x, y])
            rad = math.radians(deg)
            radius -= 0.001
            x = radius * math.sin(rad)
            y = radius * math.cos(rad)

        glVertexPointerf(spiral_array)
        glDrawArrays(GL_LINE_STRIP, 0, len(spiral_array))
        glFlush()
示例#29
0
    def draw(self):
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glMultMatrixf(self._pose.T)

        glDisable(GL_LIGHTING)

        if self._bounds:
            glColor(*self._color)
            glLineWidth(self._width)
            gldraw.box(self._bounds[0],
                       self._bounds[1],
                       lighting=False,
                       filled=False)

        glEnable(GL_LIGHTING)

        glPopMatrix()
示例#30
0
    def draw_x_switch(position: Tuple[int, int], color: Tuple[float, float,
                                                              float]):

        glPushMatrix()
        glTranslate(0.5 + position[0], -0.5 - position[1], 0)

        height = 0.15
        # glColor(Cube.colors['light_blue'])
        if len(Draw.x_switch_pt) == 0:
            width = 0.15
            size = 0.25
            Draw.x_switch_pt = [(-width, 0), (-(width + size), -size),
                                (-(width + size), -(width + size)),
                                (-size, -(width + size)), (0, -width),
                                (size, -(width + size)),
                                (width + size, -(width + size)),
                                (width + size, -size), (width, 0),
                                (width + size, size),
                                (width + size, width + size),
                                (size, width + size), (0, width),
                                (-size, width + size),
                                (-(width + size), width + size),
                                (-(width + size), size)]

        glColor(color)
        glBegin(GL_QUAD_STRIP)
        for x, y in Draw.x_switch_pt:
            glVertex3f(x, y, height)
            glVertex3f(x, y, 0)
        glVertex3f(Draw.x_switch_pt[0][0], Draw.x_switch_pt[0][1], height)
        glVertex3f(Draw.x_switch_pt[0][0], Draw.x_switch_pt[0][1], 0)
        glEnd()

        glLineWidth(3)
        glColor(Draw.colors['gray'])
        # -0.2, 0 -> -0.8, 0.6
        glBegin(GL_POLYGON)
        for x, y in Draw.x_switch_pt:
            glVertex3f(x, y, height)
        glEnd()
        glLineWidth(1)

        glPopMatrix()
示例#31
0
    def render(self):
        # Set the cube color, applies to all vertices till next call
        glColor(self.color)

        # Adjust all the vertices so that the cube is at self.position
        vertices = []
        for v in self.vertices:
            vertices.append( tuple(Vector3(v) + self.position))

        # Draw all 6 faces of the cube
        glBegin(GL_QUADS)
        for face_no in range(self.num_faces):
            glNormal3dv(self.normals[face_no])
            v1, v2, v3, v4 = self.vertex_indices[face_no]
            glVertex(vertices[v1])
            glVertex(vertices[v2])
            glVertex(vertices[v3])
            glVertex(vertices[v4])

        glEnd()
示例#32
0
 def display(self,factor) :
   ''' Function to display the localview axes. '''
   
   right_arrow = self.right.add_vertex(self.pos,self.right.mult_vector(factor,self.right))
   up_arrow = self.up.add_vertex(self.pos,self.up.mult_vector(factor,self.up))
   sight_arrow = self.sight.add_vertex(self.pos,self.sight.mult_vector(factor,self.sight))
   
   glLineWidth(4)
   
   glColor(255,0,0)
   glBegin(GL_LINES)
   glVertex(self.pos.get_vertex())
   glVertex(right_arrow.get_vertex())
   glEnd()
   
   glColor(0,255,0)
   glBegin(GL_LINES)
   glVertex(self.pos.get_vertex())
   glVertex(up_arrow.get_vertex())
   glEnd()
   
   glColor(0,0,255)
   glBegin(GL_LINES)
   glVertex(self.pos.get_vertex())
   glVertex(sight_arrow.get_vertex())
   glEnd()
示例#33
0
def main():
    pygame.init()
    pygame.display.set_mode((1024, 768),
                            pygame.locals.OPENGL | pygame.locals.DOUBLEBUF)

    glEnable(GL_DEPTH_TEST)
    gluPerspective(60.0, 640.0 / 480.0, 0.5, 1000.0)
    glTranslate(0, -15, -60)

    objects = []
    dynamicsWorld = DiscreteDynamicsWorld()
    debug = DebugDraw()
    dynamicsWorld.setDebugDrawer(debug)

    b1 = Ball(Vector3(-30, 0, 0), (255, 0, 0))
    b1.body.applyCentralImpulse(Vector3(30, 40, 0))
    objects.append(b1)

    b2 = Ball(Vector3(+30, 0, 0), (0, 255, 0))
    b2.body.applyCentralImpulse(Vector3(-30, 40, 0))
    objects.append(b2)

    for o in objects:
        dynamicsWorld.addRigidBody(o.body)

    while True:
        step(dynamicsWorld)

        debug.reset()
        dynamicsWorld.debugDrawWorld()
        glBegin(GL_LINES)
        for line in debug.lines:
            glColor(*line[6:])
            glVertex(*line[:3])
            glVertex(*line[3:6])
        if debug.contacts:
            print 'Contact!', debug.contacts
        glEnd()

        render(objects)
示例#34
0
def main():
    pygame.init()
    pygame.display.set_mode(
        (1024, 768), pygame.locals.OPENGL | pygame.locals.DOUBLEBUF)

    glEnable(GL_DEPTH_TEST)
    gluPerspective(60.0, 640.0 / 480.0, 0.5, 1000.0)
    glTranslate(0, -15, -60)

    objects = []
    dynamicsWorld = DiscreteDynamicsWorld()
    debug = DebugDraw()
    dynamicsWorld.setDebugDrawer(debug)

    b1 = Ball(Vector3(-30, 0, 0), (255, 0, 0))
    b1.body.applyCentralImpulse(Vector3(30, 40, 0))
    objects.append(b1)

    b2 = Ball(Vector3(+30, 0, 0), (0, 255, 0))
    b2.body.applyCentralImpulse(Vector3(-30, 40, 0))
    objects.append(b2)

    for o in objects:
        dynamicsWorld.addRigidBody(o.body)

    while True:
        step(dynamicsWorld)

        debug.reset()
        dynamicsWorld.debugDrawWorld()
        glBegin(GL_LINES)
        for line in debug.lines:
            glColor(*line[6:])
            glVertex(*line[:3])
            glVertex(*line[3:6])
        if debug.contacts:
            print 'Contact!', debug.contacts
        glEnd()

        render(objects)
 def dibujar_planos(self, cuadrante: str):
     for i in range(self.programa.lista_planos.count()):
         plano = self.programa.lista_planos.itemWidget(
             self.programa.lista_planos.item(i))
         if plano.render.isChecked():
             glBegin(GL_TRIANGLE_FAN)
             glColor(plano.color)
             if plano.infinito.isChecked():
                 puntos = plano.partes[cuadrante]
                 for j in puntos:
                     glVertex(j)
                 glEnd()
                 glLineWidth(2)
                 glBegin(GL_LINE_LOOP)
                 for j in plano.limites:
                     glVertex(j)
                 glEnd()
             else:
                 glVertex(plano.puntos[0])
                 glVertex(plano.puntos[1])
                 glVertex(plano.puntos[2])
                 glEnd()
示例#36
0
    def draw_round_switch(position: Tuple[int, int], color: Tuple[float, float,
                                                                  float]):

        glPushMatrix()
        glTranslate(0.5 + position[0], -0.5 - position[1], 0)
        glColor(color)

        radius = 0.4
        height = 0.15
        angle = 0.0
        angle_stepsize = 0.1
        # glColor(Cube.colors['light_blue'])
        glBegin(GL_QUAD_STRIP)
        while angle < 2 * pi:
            x = radius * cos(angle)
            y = radius * sin(angle)
            glVertex3f(x, y, height - 0.01)
            glVertex3f(x, y, 0.0)
            angle += angle_stepsize

        glVertex3f(radius, 0.0, height - 0.01)
        glVertex3f(radius, 0.0, 0.0)
        glEnd()

        # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        glLineWidth(3)
        glColor(Draw.colors['gray'])
        glBegin(GL_POLYGON)
        angle = 0.0
        while angle < 2 * pi:
            x = radius * cos(angle)
            y = radius * sin(angle)
            glVertex3f(x, y, height)
            angle += angle_stepsize
        glVertex3f(radius, 0.0, height)
        glEnd()
        glLineWidth(1)

        glPopMatrix()
示例#37
0
文件: opengl.py 项目: matqr/vector
    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)
示例#38
0
    def drawCross(self, point, size, color, gap=7, angled=False):
        """ Draw colored cross to mark tracked features """
        x = point[0] * 1.0 / self.width
        y = point[1] * 1.0 / self.height

        dx = size * .5 / self.width
        dy = size * .5 / self.height

        glColor(*color)
        if angled:
            # diagonal line 1
            GL.glBegin(GL.GL_LINES)
            GL.glVertex(x - dx, y - dy, 0.0)
            GL.glVertex(x + dx, y + dy, 0.0)
            GL.glEnd()

            # diagonal line 2
            GL.glBegin(GL.GL_LINES)
            GL.glVertex(x - dx, y + dy, 0.0)
            GL.glVertex(x + dx, y - dy, 0.0)
            GL.glEnd()

        else:
            # vertical line
            GL.glBegin(GL.GL_LINES)
            GL.glVertex(x - dx, y, 0.0)
            GL.glVertex(x + dx, y, 0.0)
            GL.glEnd()

            # horizontal line
            GL.glBegin(GL.GL_LINES)
            GL.glVertex(x, y + dy, 0.0)
            GL.glVertex(x, y - dy, 0.0)
            GL.glEnd()

        GL.glFlush()
示例#39
0
    def drawCross(self, point, size, color, gap=7, angled=False):
        """ Draw colored cross to mark tracked features """
        x = point[0]*1.0/self.width
        y = point[1]*1.0/self.height

        dx = size*.5/self.width
        dy = size*.5/self.height

        glColor(*color)
        if angled:
            # diagonal line 1
            GL.glBegin(GL.GL_LINES)
            GL.glVertex(x-dx, y-dy, 0.0)
            GL.glVertex(x+dx, y+dy, 0.0)
            GL.glEnd()

            # diagonal line 2
            GL.glBegin(GL.GL_LINES)
            GL.glVertex(x-dx, y+dy, 0.0)
            GL.glVertex(x+dx, y-dy, 0.0)
            GL.glEnd()

        else:
            # vertical line
            GL.glBegin(GL.GL_LINES)
            GL.glVertex(x-dx, y, 0.0)
            GL.glVertex(x+dx, y, 0.0)
            GL.glEnd()

            # horizontal line
            GL.glBegin(GL.GL_LINES)
            GL.glVertex(x, y+dy, 0.0)
            GL.glVertex(x, y-dy, 0.0)
            GL.glEnd()

        GL.glFlush()
示例#40
0
 def render(self):
     glLineWidth(3.0)
     glColor(0.7, 0.0, 0.0, 1.0)
     gltools.glMove([0.0, 0.0, 0.0])
     glBegin(GL_LINE_STRIP)
     for p in [self.p1, self.C, self.p2]:
         glVertex(p)
     glEnd()
     glColor(0.545, 0.000, 0.000, 1.0)
     gltools.glMove(self.p1)
     glutSolidSphere(0.03, 4, 2)
     glColor(1.000, 0.843, 0.000, 1.0)
     gltools.glMove(self.C)
     glutSolidSphere(0.03, 4, 2)
     glColor(0.294, 0.000, 0.510, 1.0)
     gltools.glMove(self.p2)
     glutSolidSphere(0.03, 4, 2)
     glLineWidth(1.0)
示例#41
0
    def draw_tool_chain(self):
        font_scale = 0.00015
        glMatrixMode(GL_MODELVIEW)

        glColor(0, 0, 0)
        glLineWidth(5)
        glBegin(GL_LINE_STRIP)
        for point in self.points:
            glVertex3f(point[0], point[1], 0.0)
        glEnd()

        glColor(1, 1, 1)
        glLineWidth(1)
        glBegin(GL_LINE_STRIP)
        for point in self.points:
            glVertex3f(point[0], point[1], 0.0)
        glEnd()

        if len(self.model_objects) == 4 and \
           self.model_objects[0] == self.model_objects[3]:
            num = 3
        else:
            num = 4

        glColor(0, 0, 0)
        glLineWidth(9)
        for index, point in enumerate(self.points[:num]):
            glPushMatrix()
            glTranslate(point[0], point[1], 0.0)
            glScaled(font_scale, font_scale, 1)
            glRectf(-10, -20, 114, 130)
            glPopMatrix()

        glColor(1, 1, 1)
        glLineWidth(1)
        for index, point in enumerate(self.points[:num]):
            glPushMatrix()
            glTranslate(point[0], point[1], 0.0)
            glScaled(font_scale, font_scale, 1)
            glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, ord(str(index+1)))
            glPopMatrix()
示例#42
0
    def draw_tool_chain(self):
        font_scale = 0.00015
        glMatrixMode(GL_MODELVIEW)

        glColor(0, 0, 0)
        glLineWidth(5)
        glBegin(GL_LINE_STRIP)
        for point in self.points:
            glVertex3f(point[0], point[1], 0.0)
        glEnd()

        glColor(1, 1, 1)
        glLineWidth(1)
        glBegin(GL_LINE_STRIP)
        for point in self.points:
            glVertex3f(point[0], point[1], 0.0)
        glEnd()

        if len(self.model_objects) == 4 and \
           self.model_objects[0] == self.model_objects[3]:
            num = 3
        else:
            num = 4

        glColor(0, 0, 0)
        glLineWidth(9)
        for index, point in enumerate(self.points[:num]):
            glPushMatrix()
            glTranslate(point[0], point[1], 0.0)
            glScaled(font_scale, font_scale, 1)
            glRectf(-10, -20, 114, 130)
            glPopMatrix()

        glColor(1, 1, 1)
        glLineWidth(1)
        for index, point in enumerate(self.points[:num]):
            glPushMatrix()
            glTranslate(point[0], point[1], 0.0)
            glScaled(font_scale, font_scale, 1)
            glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, ord(str(index + 1)))
            glPopMatrix()
示例#43
0
    def on_draw(self):
         
        glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA)

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        
        glTranslate(self.translatex, self.translatey, self.depth)
        
        if self.autoRun:
            glRotate(self.rotx,  0, 1, 0)
        
        else:
            # Perform arcball rotation.
            glScale(1,-1,1)
            glMultMatrixf(self.arcball.transform)
            glScale(1,-1,1)
        
        with displayListify("cubeTranslate") as shouldLeave:
            if shouldLeave: raise LeaveWith
                
            # Scale the co-ordinates so that they are correct
            glScale(2/128, 2/128, 2/128)
            
            glColor(0.25, 0.25, 0.25, 1)
            glutWireCube(255)
            
            glTranslate(-128, -128, -128)
        
        with displayListify("allPoints") as shouldLeave:
            if shouldLeave: raise LeaveWith
            
            with SaveMatrix():
                # Flip the co-ordinates and translate upwards
                glScale(1,-1,1)
                glColor(0.25, 0.25, 0.25, 0.5)
                glTranslate(0,-255,0)
                glPointSize(pointSize)
                for dat in reversed(vLists):
                    glTranslate(0., 0., 1./nChunks*255)
                    dat.draw(GL_POINTS)

        with displayListify("axisLabels") as shouldLeave:
            if shouldLeave: raise LeaveWith
        #if True:
            with SaveMatrix():
                glTranslate(128,0,0)
                self.makeLabel("End").draw()
                
                glTranslate(0,0,255)
                self.makeLabel("Beginning").draw()
                
                with SaveMatrix():
                    glTranslate(-128,128,0)
                    glRotate(90,0,0,1)
                    self.makeLabel("Byte 1").draw()
                
                glTranslate(0,255,0)
                self.makeLabel("Byte 2").draw()
        
        with displayListify("fileName") as shouldLeave:
            if shouldLeave: raise LeaveWith
            glLoadIdentity()
            
            with SaveMatrix():
                glColor(1,0,0)
                glTranslate(0,-2.2,-4)
                glScale(1/64, 1/64, 1/64)
                l = self.makeLabel(basename(currentInputFile))
                l.color = (0, 128, 230, 255)
                l.draw()
        
        glTranslate(0,0,-1)
        
        if self.autoRun:
        
            if self.rotx > 360 - 45:
                vlist = vertex_list(4, ('v2i', (-1, -1, 1, -1, 1, 1, -1, 1)))
                glColor(0,0,0,(self.rotx-(360-45))/45)
                vlist.draw(GL_QUADS)
                
            if self.rotx < 45:
                vlist = vertex_list(4, ('v2i', (-1, -1, 1, -1, 1, 1, -1, 1)))
                glColor(0,0,0,1-(self.rotx/45))
                vlist.draw(GL_QUADS)
示例#44
0
 def render(self):
     o = self.motion.getWorldTransform().getOrigin()
     glColor(*self.color)
     glTranslate(o.x, o.y, o.z)
     gluSphere(self.quad, self.radius, 25, 25)
示例#45
0
    def render(self):
        glPushMatrix()
        # gltools.render_axis(10)
        # Draw chess board
        gltools.glMove([0.0, -0.01, 0.0])
        # gltools.render_chessboard(10, 20.0)
        gltools.render_floor(20, 40.0)

        # Draw skeleton
        gltools.glMove([0, 0, 0])
        glPushMatrix()
        M_s = [1.0, 0.0, 0.0, 0.0,
               1.0, 0.0, -1.0, 0.0,
               0.0, 0.0, 1.0, 0.0,
               0.0, -0.001, 0.0, 1.0]
        glMultMatrixf(M_s)
        glColor(0.0, 0.0, 0.0, 1.0)
        gl.glEnable(gl.GL_LIGHTING)
        self.skel.render_with_color(0.0, 0.0, 0.0)
        gl.glEnable(gl.GL_LIGHTING)
        glPopMatrix()

        gltools.glMove([0, 0, 0])
        self.skel.render()

        gltools.glMove([0, 0, 0])
        glColor(1, 0, 0)
        # gltools.render_arrow(self.skel.C,
        #                      self.skel.C + 0.2 * self.tip.projected_Cdot())

        # # Draw TIP
        # tip_index = self.history.get_frame()['tip_index']
        # tips = self.tip_controller.tips
        # for i in range(tip_index, len(tips)):
        #     tips[i].render()

        # for c in self.prob.contacts:
        #     c.render()

        # Draw contacts
        gltools.glMove([0, 0, 0])
        # glColor(0.7, 0.0, 0.3)
        # for c in self.history.get_frame()['contacts']:
        #     gltools.render_arrow(c[0:3], c[0:3] - 0.001 * c[3:6])

        if self.history.get_frame()['t'] < 10.0:
            gltools.glMove([0, 0, 0])
            q = self.cfg.saved_target_point
            d = self.cfg.force()
            d[0] = 0.0
            len_d = np.linalg.norm(d)
            d /= len_d
            l = len_d * 0.025 + 0.020

            # d[0] = 0.0
            # len_d = np.linalg.norm(d)
            # d /= len_d
            # len_d /= 60.0
            # l = len_d * 0.025

            p = q - l * d
            # p[0] = q[0]
            # gltools.render_arrow2([0, 0.4, 0], [0, 0.4, 0.4])
            rb = 0.01 * (len_d * 0.025 + 1.0)
            hw = 0.015 * (len_d * 0.05 + 1.0)
            hl = 0.015 * (len_d * 0.05 + 1.0)
            rb *= 0.5
            hw *= 0.5
            # rb *= 2.0
            # hw *= 2.0
            gltools.render_arrow2(p, q, rb, hw, hl)

        glPopMatrix()