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()
コード例 #2
0
def drawline_worker(params):
    """
    Draw a line.  Receive parameters through a sequence so that this
    function and its parameters can be passed to another function for
    deferment.  Right now this is only ColorSorter.schedule (see below)
    """
    (endpt1, endpt2, dashEnabled, stipleFactor, width, isSmooth) = params

    ###glDisable(GL_LIGHTING)
    ###glColor3fv(color)
    if dashEnabled: 
        glLineStipple(stipleFactor, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)
    if width != 1:
        glLineWidth(width)
    if isSmooth:
        glEnable(GL_LINE_SMOOTH)
    glBegin(GL_LINES)
    glVertex(endpt1[0], endpt1[1], endpt1[2])
    glVertex(endpt2[0], endpt2[1], endpt2[2])
    glEnd()
    if isSmooth:
        glDisable(GL_LINE_SMOOTH)
    if width != 1:
        glLineWidth(1.0) # restore default state
    if dashEnabled: 
        glDisable(GL_LINE_STIPPLE)
    ###glEnable(GL_LIGHTING)
    return
コード例 #3
0
 def draw_quad_strip(self, *data):
     glBegin(GL_QUAD_STRIP)
     for normal, vectors in data:
         glNormal3fv(normal)
         for vector in vectors:
             glVertex(vector)
     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()
コード例 #5
0
 def draw_polygon(self, *data):
     glBegin(GL_POLYGON)
     for normal, vectors in data:
         glNormal3fv(normal)
         for vector in vectors:
             glVertex(vector)
     glEnd()
コード例 #6
0
 def draw_triangle_strip(self, *data):
     glBegin(GL_TRIANGLE_STRIP)
     for normal, vectors in data:
         glNormal3fv(normal)
         for vector in vectors:
             glVertex(vector)
     glEnd()
コード例 #7
0
ファイル: vis_backends.py プロジェクト: molmod/zeobuilder
 def draw_triangle_strip(self, *data):
     glBegin(GL_TRIANGLE_STRIP)
     for normal, vectors in data:
         glNormal3fv(normal)
         for vector in vectors:
             glVertex(vector)
     glEnd()
コード例 #8
0
ファイル: vis_backends.py プロジェクト: molmod/zeobuilder
 def draw_polygon(self, *data):
     glBegin(GL_POLYGON)
     for normal, vectors in data:
         glNormal3fv(normal)
         for vector in vectors:
             glVertex(vector)
     glEnd()
コード例 #9
0
ファイル: vis_backends.py プロジェクト: molmod/zeobuilder
 def draw_quad_strip(self, *data):
     glBegin(GL_QUAD_STRIP)
     for normal, vectors in data:
         glNormal3fv(normal)
         for vector in vectors:
             glVertex(vector)
     glEnd()
コード例 #10
0
def drawline_worker(params):
    """
    Draw a line.  Receive parameters through a sequence so that this
    function and its parameters can be passed to another function for
    deferment.  Right now this is only ColorSorter.schedule (see below)
    """
    (endpt1, endpt2, dashEnabled, stipleFactor, width, isSmooth) = params

    ###glDisable(GL_LIGHTING)
    ###glColor3fv(color)
    if dashEnabled:
        glLineStipple(stipleFactor, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)
    if width != 1:
        glLineWidth(width)
    if isSmooth:
        glEnable(GL_LINE_SMOOTH)
    glBegin(GL_LINES)
    glVertex(endpt1[0], endpt1[1], endpt1[2])
    glVertex(endpt2[0], endpt2[1], endpt2[2])
    glEnd()
    if isSmooth:
        glDisable(GL_LINE_SMOOTH)
    if width != 1:
        glLineWidth(1.0)  # restore default state
    if dashEnabled:
        glDisable(GL_LINE_STIPPLE)
    ###glEnable(GL_LIGHTING)
    return
 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()
 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)
 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_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()
コード例 #16
0
ファイル: trimeshbouncing.py プロジェクト: dgym/pybullet
 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()
コード例 #17
0
ファイル: trimeshbouncing.py プロジェクト: krisfris/pybullet
 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()
コード例 #18
0
ファイル: Guides.py プロジェクト: alaindomissy/nanoengineer
    def drawLine(self, pt1, pt2):
        """
        Draws ruler lines that are 1 pixel wide.
        """
        if 0:  # Used for debugging.
            return

        glBegin(GL_LINES)
        glVertex(pt1[0], pt1[1], pt1[2])
        glVertex(pt2[0], pt2[1], pt2[2])
        glEnd()
        return
コード例 #19
0
 def drawLine(self, pt1, pt2):
     """
     Draws ruler lines that are 1 pixel wide.
     """
     if 0: # Used for debugging.
         return
     
     glBegin(GL_LINES)
     glVertex(pt1[0], pt1[1], pt1[2])
     glVertex(pt2[0], pt2[1], pt2[2])
     glEnd()
     return
コード例 #20
0
ファイル: test_drawing.py プロジェクト: foulowl/nanoengineer
def draw_cylinder_axes():
    # Overdraw with the cylinder axes.
    glDisable(GL_DEPTH_TEST)
    glBegin(GL_LINES)
    for endpt1, endpt2 in test_endpoints:
        glColor3i(0, 0, 0)
        glVertex(endpt1)
        glColor3i(255,255,255)
        glVertex(endpt2)
        continue
    glEnd()
    glEnable(GL_DEPTH_TEST)
    return
コード例 #21
0
ファイル: test_drawing.py プロジェクト: vcsrc/nanoengineer
def draw_cylinder_axes():
    # Overdraw with the cylinder axes.
    glDisable(GL_DEPTH_TEST)
    glBegin(GL_LINES)
    for endpt1, endpt2 in test_endpoints:
        glColor3i(0, 0, 0)
        glVertex(endpt1)
        glColor3i(255, 255, 255)
        glVertex(endpt2)
        continue
    glEnd()
    glEnable(GL_DEPTH_TEST)
    return
コード例 #22
0
ファイル: drawers.py プロジェクト: ematvey/NanoEngineer-1
def drawrectangle(pt1, pt2, rt, up, color):
    """
    Draws a (hollow) rectangle outline of the given I{color}.

    @param pt1: First corner of the rectangle.
    @type  pt1: Point

    @param pt1: Opposite corner of the rectangle.
    @type  pt1: Point

    @param rt: Right vector of the glpane.
    @type  rt: Unit vector

    @param up: Right vector of the glpane.
    @type  up: Unit vector

    @param color: Color
    @type  color: color
    """
    glColor3f(color[0], color[1], color[2])
    glDisable(GL_LIGHTING)
    c2 = pt1 + rt * Numeric.dot(rt, pt2 - pt1)
    c3 = pt1 + up * Numeric.dot(up, pt2 - pt1)
    glBegin(GL_LINE_LOOP)
    glVertex(pt1[0], pt1[1], pt1[2])
    glVertex(c2[0], c2[1], c2[2])
    glVertex(pt2[0], pt2[1], pt2[2])
    glVertex(c3[0], c3[1], c3[2])
    glEnd()
    glEnable(GL_LIGHTING)
コード例 #23
0
ファイル: drawers.py プロジェクト: vcsrc/nanoengineer
def drawrectangle(pt1, pt2, rt, up, color):
    """
    Draws a (hollow) rectangle outline of the given I{color}.

    @param pt1: First corner of the rectangle.
    @type  pt1: Point

    @param pt1: Opposite corner of the rectangle.
    @type  pt1: Point

    @param rt: Right vector of the glpane.
    @type  rt: Unit vector

    @param up: Right vector of the glpane.
    @type  up: Unit vector

    @param color: Color
    @type  color: color
    """
    glColor3f(color[0], color[1], color[2])
    glDisable(GL_LIGHTING)
    c2 = pt1 + rt * Numeric.dot(rt, pt2 - pt1)
    c3 = pt1 + up * Numeric.dot(up, pt2 - pt1)
    glBegin(GL_LINE_LOOP)
    glVertex(pt1[0], pt1[1], pt1[2])
    glVertex(c2[0], c2[1], c2[2])
    glVertex(pt2[0], pt2[1], pt2[2])
    glVertex(c3[0], c3[1], c3[2])
    glEnd()
    glEnable(GL_LIGHTING)
コード例 #24
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()
コード例 #25
0
ファイル: tip.py プロジェクト: sehoonha/pydart_private
 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)
コード例 #26
0
ファイル: demolib.py プロジェクト: olsoneric/pybullet
 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()
コード例 #27
0
ファイル: demolib.py プロジェクト: krisfris/pybullet
 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()
コード例 #28
0
ファイル: debugdraw.py プロジェクト: krisfris/pybullet
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)
コード例 #29
0
ファイル: debugdraw.py プロジェクト: dgym/pybullet
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)
コード例 #30
0
ファイル: drawers.py プロジェクト: ematvey/NanoEngineer-1
def drawAxis(color, pos1, pos2, width = 2): #Ninad 060907
    """
    Draw chunk or jig axis
    """
    #ninad060907 Note that this is different than draw 
    # I may need this function to draw axis line. see its current implementation
    # in branch "ninad_060908_drawAxis_notAsAPropOfObject"
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glLineStipple(3, 0x1C47) # dash-dot-dash line
    glEnable(GL_LINE_STIPPLE)
    if width != 1:
        glLineWidth(width)
    glBegin(GL_LINES)
    glVertex(pos1[0], pos1[1], pos1[2])
    glVertex(pos2[0], pos2[1], pos2[2])
    glEnd()
    if width != 1:
        glLineWidth(1.0) # restore default state
    glDisable(GL_LINE_STIPPLE)
    glEnable(GL_LIGHTING)
    return
コード例 #31
0
ファイル: Font3D.py プロジェクト: vcsrc/nanoengineer
 def drawSequence(seq, tfm=tfmgen(i)):
     if len(seq) == 0:
         return  # a space character has an empty sequence
     if type(seq[0][0]) is not types.IntType:
         # handle multi-stroke characters
         for x in seq:
             drawSequence(x)
         return
     seq = map(lambda tpl: apply(tfm, tpl), seq)
     for i in range(len(seq) - 1):
         pos1, pos2 = seq[i], seq[i + 1]
         if self.glBegin:
             # This is what we do for grid planes, where "somebody"
             # is drawGPGrid in drawers.py.
             # Somebody has already taken care of glBegin(GL_LINES).
             # TODO: explain this in docstring.
             glVertex(pos1[0], pos1[1], pos1[2])
             glVertex(pos2[0], pos2[1], pos2[2])
             # Somebody has already taken care of glEnd().
         else:
             # This is what we do for dimensions.
             drawline(color, seq[i], seq[i + 1])
 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()
コード例 #33
0
ファイル: drawers.py プロジェクト: vcsrc/nanoengineer
def drawAxis(color, pos1, pos2, width=2):  #Ninad 060907
    """
    Draw chunk or jig axis
    """
    #ninad060907 Note that this is different than draw
    # I may need this function to draw axis line. see its current implementation
    # in branch "ninad_060908_drawAxis_notAsAPropOfObject"
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glLineStipple(3, 0x1C47)  # dash-dot-dash line
    glEnable(GL_LINE_STIPPLE)
    if width != 1:
        glLineWidth(width)
    glBegin(GL_LINES)
    glVertex(pos1[0], pos1[1], pos1[2])
    glVertex(pos2[0], pos2[1], pos2[2])
    glEnd()
    if width != 1:
        glLineWidth(1.0)  # restore default state
    glDisable(GL_LINE_STIPPLE)
    glEnable(GL_LIGHTING)
    return
コード例 #34
0
ファイル: Font3D.py プロジェクト: ematvey/NanoEngineer-1
 def drawSequence(seq, tfm=tfmgen(i)):
     if len(seq) == 0:
         return  # a space character has an empty sequence
     if type(seq[0][0]) is not types.IntType:
         # handle multi-stroke characters
         for x in seq:
             drawSequence(x)
         return
     seq = map(lambda tpl: apply(tfm,tpl), seq)
     for i in range(len(seq) - 1):
         pos1, pos2 = seq[i], seq[i+1]
         if self.glBegin:
             # This is what we do for grid planes, where "somebody"
             # is drawGPGrid in drawers.py.
             # Somebody has already taken care of glBegin(GL_LINES).
             # TODO: explain this in docstring.
             glVertex(pos1[0], pos1[1], pos1[2])
             glVertex(pos2[0], pos2[1], pos2[2])
             # Somebody has already taken care of glEnd().
         else:
             # This is what we do for dimensions.
             drawline(color, seq[i], seq[i+1])
コード例 #35
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()
コード例 #36
0
def setup_drawer():
    """
    Set up the usual constant display lists in the current OpenGL context.

    WARNING: THIS IS ONLY CORRECT IF ONLY ONE GL CONTEXT CONTAINS DISPLAY LISTS
    -- or more precisely, only the GL context this has last been called in (or
    one which shares its display lists) will work properly with the routines in
    drawer.py, since the allocated display list names are stored in globals set
    by this function, but in general those names might differ if this was called
    in different GL contexts.
    """
    #bruce 060613 added docstring, cleaned up display list name allocation
    # bruce 071030 renamed from setup to setup_drawer

    spherelistbase = glGenLists(numSphereSizes)
    sphereList = []
    for i in range(numSphereSizes):
        sphereList += [spherelistbase + i]
        glNewList(sphereList[i], GL_COMPILE)
        glBegin(GL_TRIANGLE_STRIP)  # GL_LINE_LOOP to see edges.
        stripVerts = getSphereTriStrips(i)
        for vertNorm in stripVerts:
            glNormal3fv(vertNorm)
            glVertex3fv(vertNorm)
            continue
        glEnd()
        glEndList()
        continue
    drawing_globals.sphereList = sphereList

    # Sphere triangle-strip vertices for each level of detail.
    # (Cache and re-use the work of making them.)
    # Can use in converter-wrappered calls like glVertexPointerfv,
    # but the python arrays are re-copied to C each time.
    sphereArrays = []
    for i in range(numSphereSizes):
        sphereArrays += [getSphereTriStrips(i)]
        continue
    drawing_globals.sphereArrays = sphereArrays

    # Sphere glDrawArrays triangle-strip vertices for C calls.
    # (Cache and re-use the work of converting a C version.)
    # Used in thinly-wrappered calls like glVertexPointer.
    sphereCArrays = []
    for i in range(numSphereSizes):
        CArray = numpy.array(sphereArrays[i], dtype=numpy.float32)
        sphereCArrays += [CArray]
        continue
    drawing_globals.sphereCArrays = sphereCArrays

    # Sphere indexed vertices.
    # (Cache and re-use the work of making the indexes.)
    # Can use in converter-wrappered calls like glDrawElementsui,
    # but the python arrays are re-copied to C each time.
    sphereElements = []  # Pairs of lists (index, verts) .
    for i in range(numSphereSizes):
        sphereElements += [indexVerts(sphereArrays[i], .0001)]
        continue
    drawing_globals.sphereElements = sphereElements

    # Sphere glDrawElements index and vertex arrays for C calls.
    sphereCIndexTypes = []  # numpy index unsigned types.
    sphereGLIndexTypes = []  # GL index types for drawElements.
    sphereCElements = []  # Pairs of numpy arrays (Cindex, Cverts) .
    for i in range(numSphereSizes):
        (index, verts) = sphereElements[i]
        if len(index) < 256:
            Ctype = numpy.uint8
            GLtype = GL_UNSIGNED_BYTE
        else:
            Ctype = numpy.uint16
            GLtype = GL_UNSIGNED_SHORT
            pass
        sphereCIndexTypes += [Ctype]
        sphereGLIndexTypes += [GLtype]
        sphereCIndex = numpy.array(index, dtype=Ctype)
        sphereCVerts = numpy.array(verts, dtype=numpy.float32)
        sphereCElements += [(sphereCIndex, sphereCVerts)]
        continue
    drawing_globals.sphereCIndexTypes = sphereCIndexTypes
    drawing_globals.sphereGLIndexTypes = sphereGLIndexTypes
    drawing_globals.sphereCElements = sphereCElements

    if glGetString(GL_EXTENSIONS).find("GL_ARB_vertex_buffer_object") >= 0:

        # A GLBufferObject version for glDrawArrays.
        sphereArrayVBOs = []
        for i in range(numSphereSizes):
            vbo = GLBufferObject(GL_ARRAY_BUFFER_ARB, sphereCArrays[i],
                                 GL_STATIC_DRAW)
            sphereArrayVBOs += [vbo]
            continue
        drawing_globals.sphereArrayVBOs = sphereArrayVBOs

        # A GLBufferObject version for glDrawElements indexed verts.
        sphereElementVBOs = []  # Pairs of (IBO, VBO)
        for i in range(numSphereSizes):
            ibo = GLBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB,
                                 sphereCElements[i][0], GL_STATIC_DRAW)
            vbo = GLBufferObject(GL_ARRAY_BUFFER_ARB, sphereCElements[i][1],
                                 GL_STATIC_DRAW)
            sphereElementVBOs += [(ibo, vbo)]
            continue
        drawing_globals.sphereElementVBOs = sphereElementVBOs

        ibo.unbind()
        vbo.unbind()
        pass

    #bruce 060415
    drawing_globals.wiresphere1list = wiresphere1list = glGenLists(1)
    glNewList(wiresphere1list, GL_COMPILE)
    didlines = {}  # don't draw each triangle edge more than once

    def shoulddoline(v1, v2):
        # make sure not list (unhashable) or Numeric array (bug in __eq__)
        v1 = tuple(v1)
        v2 = tuple(v2)
        if (v1, v2) not in didlines:
            didlines[(v1, v2)] = didlines[(v2, v1)] = None
            return True
        return False

    def doline(v1, v2):
        if shoulddoline(v1, v2):
            glVertex3fv(v1)
            glVertex3fv(v2)
        return

    glBegin(GL_LINES)
    ocdec = getSphereTriangles(1)
    for tri in ocdec:
        #e Could probably optim this more, e.g. using a vertex array or VBO or
        #  maybe GL_LINE_STRIP.
        doline(tri[0], tri[1])
        doline(tri[1], tri[2])
        doline(tri[2], tri[0])
    glEnd()
    glEndList()

    drawing_globals.CylList = CylList = glGenLists(1)
    glNewList(CylList, GL_COMPILE)
    glBegin(GL_TRIANGLE_STRIP)
    for (vtop, ntop, vbot, nbot) in drawing_globals.cylinderEdges:
        glNormal3fv(nbot)
        glVertex3fv(vbot)
        glNormal3fv(ntop)
        glVertex3fv(vtop)
    glEnd()
    glEndList()

    drawing_globals.CapList = CapList = glGenLists(1)
    glNewList(CapList, GL_COMPILE)
    glNormal3fv(drawing_globals.cap0n)
    glBegin(GL_POLYGON)
    for p in drawing_globals.drum0:
        glVertex3fv(p)
    glEnd()
    glNormal3fv(drawing_globals.cap1n)
    glBegin(GL_POLYGON)
    #bruce 060609 fix "ragged edge" bug in this endcap: drum1 -> drum2
    for p in drawing_globals.drum2:
        glVertex3fv(p)
    glEnd()
    glEndList()

    drawing_globals.diamondGridList = diamondGridList = glGenLists(1)
    glNewList(diamondGridList, GL_COMPILE)
    glBegin(GL_LINES)
    for p in drawing_globals.digrid:
        glVertex(p[0])
        glVertex(p[1])
    glEnd()
    glEndList()

    drawing_globals.lonsGridList = lonsGridList = glGenLists(1)
    glNewList(lonsGridList, GL_COMPILE)
    glBegin(GL_LINES)
    for p in drawing_globals.lonsEdges:
        glVertex(p[0])
        glVertex(p[1])
    glEnd()
    glEndList()

    drawing_globals.CubeList = CubeList = glGenLists(1)
    glNewList(CubeList, GL_COMPILE)
    glBegin(GL_QUAD_STRIP)
    # note: CubeList has only 4 faces of the cube; only suitable for use in
    # wireframes; see also solidCubeList [bruce 051215 comment reporting
    # grantham 20051213 observation]
    glVertex((-1, -1, -1))
    glVertex((1, -1, -1))
    glVertex((-1, 1, -1))
    glVertex((1, 1, -1))
    glVertex((-1, 1, 1))
    glVertex((1, 1, 1))
    glVertex((-1, -1, 1))
    glVertex((1, -1, 1))
    glVertex((-1, -1, -1))
    glVertex((1, -1, -1))
    glEnd()
    glEndList()

    drawing_globals.solidCubeList = solidCubeList = glGenLists(1)
    glNewList(solidCubeList, GL_COMPILE)
    glBegin(GL_QUADS)
    for i in xrange(len(drawing_globals.cubeIndices)):
        avenormals = V(0, 0, 0)  #bruce 060302 fixed normals for flat shading
        for j in xrange(4):
            nTuple = tuple(
                drawing_globals.cubeNormals[drawing_globals.cubeIndices[i][j]])
            avenormals += A(nTuple)
        avenormals = norm(avenormals)
        for j in xrange(4):
            vTuple = tuple(drawing_globals.cubeVertices[
                drawing_globals.cubeIndices[i][j]])
            #bruce 060302 made size compatible with glut.glutSolidCube(1.0)
            vTuple = A(vTuple) * 0.5
            glNormal3fv(avenormals)
            glVertex3fv(vTuple)
    glEnd()
    glEndList()

    drawing_globals.rotSignList = rotSignList = glGenLists(1)
    glNewList(rotSignList, GL_COMPILE)
    glBegin(GL_LINE_STRIP)
    for ii in xrange(len(drawing_globals.rotS0n)):
        glVertex3fv(tuple(drawing_globals.rotS0n[ii]))
    glEnd()
    glBegin(GL_LINE_STRIP)
    for ii in xrange(len(drawing_globals.rotS1n)):
        glVertex3fv(tuple(drawing_globals.rotS1n[ii]))
    glEnd()
    glBegin(GL_TRIANGLES)
    for v in drawing_globals.arrow0Vertices + drawing_globals.arrow1Vertices:
        glVertex3f(v[0], v[1], v[2])
    glEnd()
    glEndList()

    drawing_globals.linearArrowList = linearArrowList = glGenLists(1)
    glNewList(linearArrowList, GL_COMPILE)
    glBegin(GL_TRIANGLES)
    for v in drawing_globals.linearArrowVertices:
        glVertex3f(v[0], v[1], v[2])
    glEnd()
    glEndList()

    drawing_globals.linearLineList = linearLineList = glGenLists(1)
    glNewList(linearLineList, GL_COMPILE)
    glEnable(GL_LINE_SMOOTH)
    glBegin(GL_LINES)
    glVertex3f(0.0, 0.0, -drawing_globals.halfHeight)
    glVertex3f(0.0, 0.0, drawing_globals.halfHeight)
    glEnd()
    glDisable(GL_LINE_SMOOTH)
    glEndList()

    drawing_globals.circleList = circleList = glGenLists(1)
    glNewList(circleList, GL_COMPILE)
    glBegin(GL_LINE_LOOP)
    for ii in range(60):
        x = cos(ii * 2.0 * pi / 60)
        y = sin(ii * 2.0 * pi / 60)
        glVertex3f(x, y, 0.0)
    glEnd()
    glEndList()

    # piotr 080405
    drawing_globals.filledCircleList = filledCircleList = glGenLists(1)
    glNewList(filledCircleList, GL_COMPILE)
    glBegin(GL_POLYGON)
    for ii in range(60):
        x = cos(ii * 2.0 * pi / 60)
        y = sin(ii * 2.0 * pi / 60)
        glVertex3f(x, y, 0.0)
    glEnd()
    glEndList()

    drawing_globals.lineCubeList = lineCubeList = glGenLists(1)
    glNewList(lineCubeList, GL_COMPILE)
    glBegin(GL_LINES)
    cvIndices = [
        0, 1, 2, 3, 4, 5, 6, 7, 0, 3, 1, 2, 5, 6, 4, 7, 0, 4, 1, 5, 2, 6, 3, 7
    ]
    for i in cvIndices:
        glVertex3fv(tuple(drawing_globals.cubeVertices[i]))
    glEnd()
    glEndList()

    # Debug Preferences
    from utilities.debug_prefs import debug_pref, Choice_boolean_True
    from utilities.debug_prefs import Choice_boolean_False
    choices = [Choice_boolean_False, Choice_boolean_True]

    # 20060314 grantham
    initial_choice = choices[drawing_globals.allow_color_sorting_default]
    drawing_globals.allow_color_sorting_pref = debug_pref(
        "Use Color Sorting?",
        initial_choice,
        prefs_key=drawing_globals.allow_color_sorting_prefs_key)
    #bruce 060323 removed non_debug = True for A7 release, changed default
    #value to False (far above), and changed its prefs_key so developers
    #start with the new default value.
    #russ 080225: Added.
    initial_choice = choices[drawing_globals.use_color_sorted_dls_default]
    drawing_globals.use_color_sorted_dls_pref = debug_pref(
        "Use Color-sorted Display Lists?",
        initial_choice,
        prefs_key=drawing_globals.use_color_sorted_dls_prefs_key)
    #russ 080225: Added.
    initial_choice = choices[drawing_globals.use_color_sorted_vbos_default]
    drawing_globals.use_color_sorted_vbos_pref = debug_pref(
        "Use Color-sorted Vertex Buffer Objects?",
        initial_choice,
        prefs_key=drawing_globals.use_color_sorted_vbos_prefs_key)

    #russ 080403: Added drawing variant selection
    variants = [
        "0. OpenGL 1.0 - glBegin/glEnd tri-strips vertex-by-vertex.",
        "1. OpenGL 1.1 - glDrawArrays from CPU RAM.",
        "2. OpenGL 1.1 - glDrawElements indexed arrays from CPU RAM.",
        "3. OpenGL 1.5 - glDrawArrays from graphics RAM VBO.",
        "4. OpenGL 1.5 - glDrawElements, verts in VBO, index in CPU.",
        "5. OpenGL 1.5 - VBO/IBO buffered glDrawElements."
    ]
    drawing_globals.use_drawing_variant = debug_pref(
        "GLPane: drawing method",
        Choice(names=variants,
               values=range(len(variants)),
               defaultValue=drawing_globals.use_drawing_variant_default),
        prefs_key=drawing_globals.use_drawing_variant_prefs_key)

    # temporarily always print this, while default setting might be in flux,
    # and to avoid confusion if the two necessary prefs are set differently
    # [bruce 080305]
    if (drawing_globals.allow_color_sorting_pref
            and drawing_globals.use_color_sorted_dls_pref):
        print "\nnote: this session WILL use color sorted display lists"
    else:
        print "\nnote: this session will NOT use color sorted display lists"
    if (drawing_globals.allow_color_sorting_pref
            and drawing_globals.use_color_sorted_vbos_pref):
        print "note: this session WILL use", \
              "color sorted Vertex Buffer Objects\n"
    else:
        print "note: this session will NOT use", \
              "color sorted Vertex Buffer Objects\n"

    # 20060313 grantham Added use_c_renderer debug pref, can
    # take out when C renderer used by default.
    if drawing_globals.quux_module_import_succeeded:
        initial_choice = choices[drawing_globals.use_c_renderer_default]
        drawing_globals.use_c_renderer = (debug_pref(
            "Use native C renderer?",
            initial_choice,
            prefs_key=drawing_globals.use_c_renderer_prefs_key))
        #bruce 060323 removed non_debug = True for A7 release, and changed
        # its prefs_key so developers start over with the default value.

    #initTexture('C:\\Huaicai\\atom\\temp\\newSample.png', 128,128)
    return  # from setup_drawer
コード例 #37
0
ファイル: setup_draw.py プロジェクト: ematvey/NanoEngineer-1
def setup_drawer():
    """
    Set up the usual constant display lists in the current OpenGL context.

    WARNING: THIS IS ONLY CORRECT IF ONLY ONE GL CONTEXT CONTAINS DISPLAY LISTS
    -- or more precisely, only the GL context this has last been called in (or
    one which shares its display lists) will work properly with the routines in
    drawer.py, since the allocated display list names are stored in globals set
    by this function, but in general those names might differ if this was called
    in different GL contexts.
    """
    #bruce 060613 added docstring, cleaned up display list name allocation
    # bruce 071030 renamed from setup to setup_drawer

    spherelistbase = glGenLists(numSphereSizes)
    sphereList = []
    for i in range(numSphereSizes):
        sphereList += [spherelistbase+i]
        glNewList(sphereList[i], GL_COMPILE)
        glBegin(GL_TRIANGLE_STRIP) # GL_LINE_LOOP to see edges.
        stripVerts = getSphereTriStrips(i)
        for vertNorm in stripVerts:
            glNormal3fv(vertNorm)
            glVertex3fv(vertNorm)
            continue
        glEnd()
        glEndList()
        continue
    drawing_globals.sphereList = sphereList

    # Sphere triangle-strip vertices for each level of detail.
    # (Cache and re-use the work of making them.)
    # Can use in converter-wrappered calls like glVertexPointerfv,
    # but the python arrays are re-copied to C each time.
    sphereArrays = []
    for i in range(numSphereSizes):
        sphereArrays += [getSphereTriStrips(i)]
        continue
    drawing_globals.sphereArrays = sphereArrays

    # Sphere glDrawArrays triangle-strip vertices for C calls.
    # (Cache and re-use the work of converting a C version.)
    # Used in thinly-wrappered calls like glVertexPointer.
    sphereCArrays = []
    for i in range(numSphereSizes):
        CArray = numpy.array(sphereArrays[i], dtype=numpy.float32)
        sphereCArrays += [CArray]
        continue
    drawing_globals.sphereCArrays = sphereCArrays

    # Sphere indexed vertices.
    # (Cache and re-use the work of making the indexes.)
    # Can use in converter-wrappered calls like glDrawElementsui,
    # but the python arrays are re-copied to C each time.
    sphereElements = []             # Pairs of lists (index, verts) .
    for i in range(numSphereSizes):
        sphereElements += [indexVerts(sphereArrays[i], .0001)]
        continue
    drawing_globals.sphereElements = sphereElements

    # Sphere glDrawElements index and vertex arrays for C calls.
    sphereCIndexTypes = []          # numpy index unsigned types.
    sphereGLIndexTypes = []         # GL index types for drawElements.
    sphereCElements = []            # Pairs of numpy arrays (Cindex, Cverts) .
    for i in range(numSphereSizes):
        (index, verts) = sphereElements[i]
        if len(index) < 256:
            Ctype = numpy.uint8
            GLtype = GL_UNSIGNED_BYTE
        else:
            Ctype = numpy.uint16
            GLtype = GL_UNSIGNED_SHORT
            pass
        sphereCIndexTypes += [Ctype]
        sphereGLIndexTypes += [GLtype]
        sphereCIndex = numpy.array(index, dtype=Ctype)
        sphereCVerts = numpy.array(verts, dtype=numpy.float32)
        sphereCElements += [(sphereCIndex, sphereCVerts)]
        continue
    drawing_globals.sphereCIndexTypes = sphereCIndexTypes
    drawing_globals.sphereGLIndexTypes = sphereGLIndexTypes
    drawing_globals.sphereCElements = sphereCElements

    if glGetString(GL_EXTENSIONS).find("GL_ARB_vertex_buffer_object") >= 0:

        # A GLBufferObject version for glDrawArrays.
        sphereArrayVBOs = []
        for i in range(numSphereSizes):
            vbo = GLBufferObject(GL_ARRAY_BUFFER_ARB,
                                 sphereCArrays[i], GL_STATIC_DRAW)
            sphereArrayVBOs += [vbo]
            continue
        drawing_globals.sphereArrayVBOs = sphereArrayVBOs

        # A GLBufferObject version for glDrawElements indexed verts.
        sphereElementVBOs = []              # Pairs of (IBO, VBO)
        for i in range(numSphereSizes):
            ibo = GLBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB,
                                 sphereCElements[i][0], GL_STATIC_DRAW)
            vbo = GLBufferObject(GL_ARRAY_BUFFER_ARB,
                                 sphereCElements[i][1], GL_STATIC_DRAW)
            sphereElementVBOs += [(ibo, vbo)]
            continue
        drawing_globals.sphereElementVBOs = sphereElementVBOs

        ibo.unbind()
        vbo.unbind()
        pass

    #bruce 060415
    drawing_globals.wiresphere1list = wiresphere1list = glGenLists(1)
    glNewList(wiresphere1list, GL_COMPILE)
    didlines = {} # don't draw each triangle edge more than once

    def shoulddoline(v1,v2):
        # make sure not list (unhashable) or Numeric array (bug in __eq__)
        v1 = tuple(v1)
        v2 = tuple(v2)
        if (v1,v2) not in didlines:
            didlines[(v1,v2)] = didlines[(v2,v1)] = None
            return True
        return False
    def doline(v1,v2):
        if shoulddoline(v1,v2):
            glVertex3fv(v1)
            glVertex3fv(v2)
        return
    glBegin(GL_LINES)
    ocdec = getSphereTriangles(1)
    for tri in ocdec:
        #e Could probably optim this more, e.g. using a vertex array or VBO or
        #  maybe GL_LINE_STRIP.
        doline(tri[0], tri[1])
        doline(tri[1], tri[2])
        doline(tri[2], tri[0])
    glEnd()
    glEndList()

    drawing_globals.CylList = CylList = glGenLists(1)
    glNewList(CylList, GL_COMPILE)
    glBegin(GL_TRIANGLE_STRIP)
    for (vtop, ntop, vbot, nbot) in drawing_globals.cylinderEdges:
        glNormal3fv(nbot)
        glVertex3fv(vbot)
        glNormal3fv(ntop)
        glVertex3fv(vtop)
    glEnd()
    glEndList()

    drawing_globals.CapList = CapList = glGenLists(1)
    glNewList(CapList, GL_COMPILE)
    glNormal3fv(drawing_globals.cap0n)
    glBegin(GL_POLYGON)
    for p in drawing_globals.drum0:
        glVertex3fv(p)
    glEnd()
    glNormal3fv(drawing_globals.cap1n)
    glBegin(GL_POLYGON)
    #bruce 060609 fix "ragged edge" bug in this endcap: drum1 -> drum2
    for p in drawing_globals.drum2:
        glVertex3fv(p)
    glEnd()
    glEndList()

    drawing_globals.diamondGridList = diamondGridList = glGenLists(1)
    glNewList(diamondGridList, GL_COMPILE)
    glBegin(GL_LINES)
    for p in drawing_globals.digrid:
        glVertex(p[0])
        glVertex(p[1])
    glEnd()
    glEndList()

    drawing_globals.lonsGridList = lonsGridList = glGenLists(1)
    glNewList(lonsGridList, GL_COMPILE)
    glBegin(GL_LINES)
    for p in drawing_globals.lonsEdges:
        glVertex(p[0])
        glVertex(p[1])
    glEnd()
    glEndList()

    drawing_globals.CubeList = CubeList = glGenLists(1)
    glNewList(CubeList, GL_COMPILE)
    glBegin(GL_QUAD_STRIP)
    # note: CubeList has only 4 faces of the cube; only suitable for use in
    # wireframes; see also solidCubeList [bruce 051215 comment reporting
    # grantham 20051213 observation]
    glVertex((-1,-1,-1))
    glVertex(( 1,-1,-1))
    glVertex((-1, 1,-1))
    glVertex(( 1, 1,-1))
    glVertex((-1, 1, 1))
    glVertex(( 1, 1, 1))
    glVertex((-1,-1, 1))
    glVertex(( 1,-1, 1))
    glVertex((-1,-1,-1))
    glVertex(( 1,-1,-1))
    glEnd()
    glEndList()

    drawing_globals.solidCubeList = solidCubeList = glGenLists(1)
    glNewList(solidCubeList, GL_COMPILE)
    glBegin(GL_QUADS)
    for i in xrange(len(drawing_globals.cubeIndices)):
        avenormals = V(0,0,0) #bruce 060302 fixed normals for flat shading 
        for j in xrange(4) :    
            nTuple = tuple(
                drawing_globals.cubeNormals[drawing_globals.cubeIndices[i][j]])
            avenormals += A(nTuple)
        avenormals = norm(avenormals)
        for j in xrange(4) :    
            vTuple = tuple(
                drawing_globals.cubeVertices[drawing_globals.cubeIndices[i][j]])
            #bruce 060302 made size compatible with glut.glutSolidCube(1.0)
            vTuple = A(vTuple) * 0.5
            glNormal3fv(avenormals)
            glVertex3fv(vTuple)
    glEnd()
    glEndList()                

    drawing_globals.rotSignList = rotSignList = glGenLists(1)
    glNewList(rotSignList, GL_COMPILE)
    glBegin(GL_LINE_STRIP)
    for ii in xrange(len(drawing_globals.rotS0n)):
        glVertex3fv(tuple(drawing_globals.rotS0n[ii]))
    glEnd()
    glBegin(GL_LINE_STRIP)
    for ii in xrange(len(drawing_globals.rotS1n)):
        glVertex3fv(tuple(drawing_globals.rotS1n[ii]))
    glEnd()
    glBegin(GL_TRIANGLES)
    for v in drawing_globals.arrow0Vertices + drawing_globals.arrow1Vertices:
        glVertex3f(v[0], v[1], v[2])
    glEnd()
    glEndList()

    drawing_globals.linearArrowList = linearArrowList = glGenLists(1)
    glNewList(linearArrowList, GL_COMPILE)
    glBegin(GL_TRIANGLES)
    for v in drawing_globals.linearArrowVertices:
        glVertex3f(v[0], v[1], v[2])
    glEnd()
    glEndList()

    drawing_globals.linearLineList = linearLineList = glGenLists(1)
    glNewList(linearLineList, GL_COMPILE)
    glEnable(GL_LINE_SMOOTH)
    glBegin(GL_LINES)
    glVertex3f(0.0, 0.0, -drawing_globals.halfHeight)
    glVertex3f(0.0, 0.0, drawing_globals.halfHeight)
    glEnd()
    glDisable(GL_LINE_SMOOTH)
    glEndList()

    drawing_globals.circleList = circleList = glGenLists(1)
    glNewList(circleList, GL_COMPILE)
    glBegin(GL_LINE_LOOP)
    for ii in range(60):
        x = cos(ii*2.0*pi/60)
        y = sin(ii*2.0*pi/60)
        glVertex3f(x, y, 0.0)
    glEnd()    
    glEndList()

    # piotr 080405
    drawing_globals.filledCircleList = filledCircleList = glGenLists(1)
    glNewList(filledCircleList, GL_COMPILE)
    glBegin(GL_POLYGON)
    for ii in range(60):
        x = cos(ii*2.0*pi/60)
        y = sin(ii*2.0*pi/60)
        glVertex3f(x, y, 0.0)
    glEnd()    
    glEndList()

    drawing_globals.lineCubeList = lineCubeList = glGenLists(1)
    glNewList(lineCubeList, GL_COMPILE)
    glBegin(GL_LINES)
    cvIndices = [0,1, 2,3, 4,5, 6,7, 0,3, 1,2, 5,6, 4,7, 0,4, 1,5, 2,6, 3,7]
    for i in cvIndices:
        glVertex3fv(tuple(drawing_globals.cubeVertices[i]))
    glEnd()    
    glEndList()

    # Debug Preferences
    from utilities.debug_prefs import debug_pref, Choice_boolean_True
    from utilities.debug_prefs import Choice_boolean_False
    choices = [Choice_boolean_False, Choice_boolean_True]

    # 20060314 grantham
    initial_choice = choices[drawing_globals.allow_color_sorting_default]
    drawing_globals.allow_color_sorting_pref = debug_pref(
        "Use Color Sorting?", initial_choice,
        prefs_key = drawing_globals.allow_color_sorting_prefs_key)
        #bruce 060323 removed non_debug = True for A7 release, changed default
        #value to False (far above), and changed its prefs_key so developers
        #start with the new default value.
    #russ 080225: Added.
    initial_choice = choices[drawing_globals.use_color_sorted_dls_default]
    drawing_globals.use_color_sorted_dls_pref = debug_pref(
        "Use Color-sorted Display Lists?", initial_choice,
        prefs_key = drawing_globals.use_color_sorted_dls_prefs_key)
    #russ 080225: Added.
    initial_choice = choices[drawing_globals.use_color_sorted_vbos_default]
    drawing_globals.use_color_sorted_vbos_pref = debug_pref(
        "Use Color-sorted Vertex Buffer Objects?", initial_choice,
        prefs_key = drawing_globals.use_color_sorted_vbos_prefs_key)

    #russ 080403: Added drawing variant selection
    variants = [
        "0. OpenGL 1.0 - glBegin/glEnd tri-strips vertex-by-vertex.",
        "1. OpenGL 1.1 - glDrawArrays from CPU RAM.",
        "2. OpenGL 1.1 - glDrawElements indexed arrays from CPU RAM.",
        "3. OpenGL 1.5 - glDrawArrays from graphics RAM VBO.",
        "4. OpenGL 1.5 - glDrawElements, verts in VBO, index in CPU.",
        "5. OpenGL 1.5 - VBO/IBO buffered glDrawElements."]
    drawing_globals.use_drawing_variant = debug_pref(
        "GLPane: drawing method",
        Choice(names = variants, values = range(len(variants)),
               defaultValue = drawing_globals.use_drawing_variant_default),
        prefs_key = drawing_globals.use_drawing_variant_prefs_key)

    # temporarily always print this, while default setting might be in flux,
    # and to avoid confusion if the two necessary prefs are set differently
    # [bruce 080305]
    if (drawing_globals.allow_color_sorting_pref and
        drawing_globals.use_color_sorted_dls_pref):
        print "\nnote: this session WILL use color sorted display lists"
    else:
        print "\nnote: this session will NOT use color sorted display lists"
    if (drawing_globals.allow_color_sorting_pref and
        drawing_globals.use_color_sorted_vbos_pref):
        print "note: this session WILL use", \
              "color sorted Vertex Buffer Objects\n"
    else:
        print "note: this session will NOT use", \
              "color sorted Vertex Buffer Objects\n"

    # 20060313 grantham Added use_c_renderer debug pref, can
    # take out when C renderer used by default.
    if drawing_globals.quux_module_import_succeeded:
        initial_choice = choices[drawing_globals.use_c_renderer_default]
        drawing_globals.use_c_renderer = (
            debug_pref("Use native C renderer?",
                       initial_choice,
                       prefs_key = drawing_globals.use_c_renderer_prefs_key))
            #bruce 060323 removed non_debug = True for A7 release, and changed
            # its prefs_key so developers start over with the default value.

    #initTexture('C:\\Huaicai\\atom\\temp\\newSample.png', 128,128)
    return # from setup_drawer
コード例 #38
0
ファイル: bounding.py プロジェクト: wwu-numerik/pydune
    def __init__(self, mesh):
        self.outline_color = (1, 1, 1)
        vertices = mesh.vertex_list.getVertices()
        minV = Vector3()
        maxV = Vector3()
        vertices.sort(lambda x, y: cmp(y.x, x.x))
        minV.x = vertices[0].x
        maxV.x = vertices[-1].x
        vertices.sort(lambda x, y: cmp(y.y, x.y))
        minV.y = vertices[0].y
        maxV.y = vertices[-1].y
        vertices.sort(lambda x, y: cmp(y.z, x.z))
        minV.z = vertices[0].z
        maxV.z = vertices[-1].z

        self.points = []
        for i in range(8):
            self.points.append(Vector3())
        for i in range(2):
            for j in range(2):
                self.points[int("%d%d%d" % (0, i, j), 2)].x = minV.x
                self.points[int("%d%d%d" % (1, i, j), 2)].x = maxV.x
                self.points[int("%d%d%d" % (i, 0, j), 2)].y = minV.y
                self.points[int("%d%d%d" % (i, 1, j), 2)].y = maxV.y
                self.points[int("%d%d%d" % (i, j, 0), 2)].z = minV.z
                self.points[int("%d%d%d" % (i, j, 1), 2)].z = maxV.z

        self.center = Vector3()
        for p in self.points:
            self.center += p
        self.center /= float(8)
        self.dl = glGenLists(1)
        glNewList(self.dl, GL_COMPILE)
        glLineWidth(5)
        c = self.outline_color
        glColor4f(c[0], c[1], c[2], 0.2)
        glBegin(GL_LINE_STRIP)
        for v in self.points:
            glVertex(v())
        glEnd()
        c = self.points
        glBegin(GL_LINES)

        glVertex(c[0]())
        glVertex(c[2]())
        glVertex(c[6]())
        glVertex(c[4]())

        glVertex(c[1]())
        glVertex(c[3]())
        glVertex(c[7]())
        glVertex(c[5]())

        glVertex(c[0]())
        glVertex(c[1]())
        glVertex(c[3]())
        glVertex(c[2]())

        glVertex(c[2]())
        glVertex(c[3]())
        glVertex(c[7]())
        glVertex(c[6]())

        glVertex(c[7]())
        glVertex(c[6]())
        glVertex(c[4]())
        glVertex(c[5]())

        glVertex(c[0]())
        glVertex(c[1]())
        glVertex(c[5]())
        glVertex(c[4]())

        glEnd()
        glPushMatrix()
        glTranslatef(self.center.x, self.center.y, self.center.z)
        q = gluNewQuadric()
        gluSphere(q, GLdouble(0.25), GLint(10), GLint(10))
        glPopMatrix()
        glEndList()
コード例 #39
0
ファイル: drawers.py プロジェクト: ematvey/NanoEngineer-1
def drawaxes(scale, point, color = black, coloraxes = False, dashEnabled = False):
    """
    Draw axes.

    @note: used for both origin axes and point of view axes.

    @see: drawOriginAsSmallAxis (related code)
    """
    n = scale
    glPushMatrix()
    glTranslate(point[0], point[1], point[2])
    glDisable(GL_LIGHTING)
    
    if dashEnabled:
        #ninad060921 Note that we will only support dotted origin axis 
        #(hidden lines) but not POV axis. (as it could be annoying)
        glLineStipple(5, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)
        glDisable(GL_DEPTH_TEST)
    
    glColor3fv(color)
    
    if coloraxes: 
        glColor3fv(red)
        
    glBegin(GL_LINES)
    glVertex( n, 0, 0)
    glVertex(-n, 0, 0)
    
    if coloraxes: 
        glColor3fv(darkgreen)
        
    glVertex(0,  n, 0)
    glVertex(0, -n, 0)
    
    if coloraxes: 
        glColor3fv(blue)
        
    glVertex(0, 0,  n)
    glVertex(0, 0, -n)
    
    glEnd()

    if dashEnabled:
        glDisable(GL_LINE_STIPPLE)
        glEnable(GL_DEPTH_TEST)

    glEnable(GL_LIGHTING)
    glPopMatrix()
    return
コード例 #40
0
ファイル: vis_backends.py プロジェクト: molmod/zeobuilder
 def draw_line(self, *points):
     glBegin(GL_LINES)
     for point in points:
         glVertex(point)
     glEnd()
コード例 #41
0
ファイル: drawers.py プロジェクト: ematvey/NanoEngineer-1
def drawOriginAsSmallAxis(scale, origin, dashEnabled = False):
    """
    Draws a small wireframe version of the origin. It is rendered as a 
    3D point at (0, 0, 0) with 3 small axes extending from it in the positive
    X, Y, Z directions.

    @see: drawaxes (related code)
    """
    #Perhaps we should split this method into smaller methods? ninad060920
    #Notes:
    #1. drawing arrowheads implemented on 060918
    #2. ninad060921 Show the origin axes as dotted if behind the mode. 
    #3. ninad060922 The arrow heads are drawn as wireframe cones if behind the
    #   object the arrowhead size is slightly smaller (otherwise some portion of
    #   the the wireframe arrow shows up!
    #4 .Making origin non-zoomable is acheived by replacing hardcoded 'n' with
    #   glpane's scale - ninad060922

    #ninad060922 in future , the following could be user preferences. 
    if (dashEnabled):
        dashShrinkage = 0.9
    else:
        dashShrinkage=1
    x1, y1, z1 = scale * 0.01, scale * 0.01, scale * 0.01
    xEnd, yEnd, zEnd = scale * 0.04, scale * 0.09, scale * 0.025
    arrowBase = scale * 0.0075 * dashShrinkage
    arrowHeight = scale * 0.035 * dashShrinkage
    lineWidth = 1.0

    glPushMatrix()

    glTranslate(origin[0], origin[1], origin[2])
    glDisable(GL_LIGHTING)
    glLineWidth(lineWidth)

    gleNumSides = gleGetNumSides()
    #Code to show hidden lines of the origin if some model obscures it
    #  ninad060921
    if dashEnabled:
        glLineStipple(2, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)
        glDisable(GL_DEPTH_TEST)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        gleSetNumSides(5)   
    else:   
        gleSetNumSides(10)

    glBegin(GL_LINES)

    color = env.prefs[originAxisColor_prefs_key]
    
    glColor3fv(color)

    #start draw a point at origin . 
    #ninad060922 is thinking about using GL_POINTS here

    glVertex(-x1, 0.0, 0.0)
    glVertex( x1, 0.0, 0.0)
    glVertex(0.0, -y1, 0.0)
    glVertex(0.0,  y1, 0.0)
    glVertex(-x1,  y1,  z1)
    glVertex( x1, -y1, -z1)    
    glVertex(x1,   y1,  z1)
    glVertex(-x1, -y1, -z1)    
    glVertex(x1,   y1, -z1)
    glVertex(-x1, -y1,  z1)    
    glVertex(-x1,  y1, -z1)
    glVertex(x1,  -y1,  z1)   
    #end draw a point at origin 

    #start draw small origin axes

    glColor3fv(color)
    glVertex(xEnd, 0.0, 0.0)
    glVertex( 0.0, 0.0, 0.0)

    glColor3fv(color)
    glVertex(0.0, yEnd, 0.0)
    glVertex(0.0,  0.0, 0.0)

    glColor3fv(color)
    glVertex(0.0, 0.0, zEnd)
    glVertex(0.0, 0.0,  0.0)
    glEnd() #end draw lines
    glLineWidth(1.0)

    # End push matrix for drawing various lines in the origin and axes.
    glPopMatrix()
    
    #start draw solid arrow heads  for  X , Y and Z axes
    glPushMatrix() 
    glDisable(GL_CULL_FACE)
    glColor3fv(color)
    glTranslatef(xEnd, 0.0, 0.0)
    glRotatef(90, 0.0, 1.0, 0.0)

    glePolyCone([[0, 0, -1],
                 [0, 0, 0],
                 [0, 0, arrowHeight],
                 [0, 0, arrowHeight+1]],
                None,
                [arrowBase, arrowBase, 0, 0])

    glPopMatrix()

    glPushMatrix()
    glColor3fv(color)
    glTranslatef(0.0, yEnd, 0.0)
    glRotatef(-90, 1.0, 0.0, 0.0)

    glePolyCone([[0, 0, -1],
                 [0, 0, 0],
                 [0, 0, arrowHeight],
                 [0, 0, arrowHeight+1]],
                None,
                [arrowBase, arrowBase, 0, 0])

    glPopMatrix()

    glPushMatrix()
    glColor3fv(color)
    glTranslatef(0.0,0.0,zEnd)

    glePolyCone([[0, 0, -1],
                 [0, 0, 0],
                 [0, 0, arrowHeight],
                 [0, 0, arrowHeight+1]],
                None,
                [arrowBase, arrowBase, 0, 0])

    #Disable line stipple and Enable Depth test
    if dashEnabled:
        glLineStipple(1, 0xAAAA)
        glDisable(GL_LINE_STIPPLE)
        glEnable(GL_DEPTH_TEST)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    gleSetNumSides(gleNumSides)
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPopMatrix() 
    #end draw solid arrow heads  for  X , Y and Z axes
    return
 def dibujar(inicio, fin):
     glBegin(GL_LINES)
     glVertex(inicio)
     glVertex(fin)
     glEnd()
 def dibujar_ejes(self):
     if self.programa.ajustes.ver_ejes.isChecked():
         glLineWidth(3)
         glBegin(GL_LINES)
         # Eje X, color rojo
         glColor(1, 0, 0)
         glVertex(0, 0, 0)
         glVertex(10, 0, 0)
         # Eje Y, color verde
         glColor(0, 1, 0)
         glVertex(0, 0, 0)
         glVertex(0, 10, 0)
         # Eje Z, color azul
         glColor(0, 0, 1)
         glVertex(0, 0, 0)
         glVertex(0, 0, 10)
         glEnd()
コード例 #44
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()
コード例 #45
0
ファイル: setup_draw.py プロジェクト: vcsrc/nanoengineer
def setup_drawer():
    """
    Set up the usual constant display lists in the current OpenGL context.

    WARNING: THIS IS ONLY CORRECT IF ONLY ONE GL CONTEXT CONTAINS DISPLAY LISTS
    -- or more precisely, only the GL context this has last been called in (or
    one which shares its display lists) will work properly with the routines in
    drawer.py, since the allocated display list names are stored in globals set
    by this function, but in general those names might differ if this was called
    in different GL contexts.
    """
    spherelistbase = glGenLists(_NUM_SPHERE_SIZES)
    sphereList = []
    for i in range(_NUM_SPHERE_SIZES):
        sphereList += [spherelistbase+i]
        glNewList(sphereList[i], GL_COMPILE)
        glBegin(GL_TRIANGLE_STRIP) # GL_LINE_LOOP to see edges
        stripVerts = getSphereTriStrips(i)
        for vertNorm in stripVerts:
            glNormal3fv(vertNorm)
            glVertex3fv(vertNorm)
            continue
        glEnd()
        glEndList()
        continue
    drawing_globals.sphereList = sphereList

    # Sphere triangle-strip vertices for each level of detail.
    # (Cache and re-use the work of making them.)
    # Can use in converter-wrappered calls like glVertexPointerfv,
    # but the python arrays are re-copied to C each time.
    sphereArrays = []
    for i in range(_NUM_SPHERE_SIZES):
        sphereArrays += [getSphereTriStrips(i)]
        continue
    drawing_globals.sphereArrays = sphereArrays

    # Sphere glDrawArrays triangle-strip vertices for C calls.
    # (Cache and re-use the work of converting a C version.)
    # Used in thinly-wrappered calls like glVertexPointer.
    sphereCArrays = []
    for i in range(_NUM_SPHERE_SIZES):
        CArray = numpy.array(sphereArrays[i], dtype = numpy.float32)
        sphereCArrays += [CArray]
        continue
    drawing_globals.sphereCArrays = sphereCArrays

    # Sphere indexed vertices.
    # (Cache and re-use the work of making the indexes.)
    # Can use in converter-wrappered calls like glDrawElementsui,
    # but the python arrays are re-copied to C each time.
    sphereElements = []             # Pairs of lists (index, verts) .
    for i in range(_NUM_SPHERE_SIZES):
        sphereElements += [indexVerts(sphereArrays[i], .0001)]
        continue
    drawing_globals.sphereElements = sphereElements

    # Sphere glDrawElements index and vertex arrays for C calls.
    sphereCIndexTypes = []          # numpy index unsigned types.
    sphereGLIndexTypes = []         # GL index types for drawElements.
    sphereCElements = []            # Pairs of numpy arrays (Cindex, Cverts) .
    for i in range(_NUM_SPHERE_SIZES):
        (index, verts) = sphereElements[i]
        if len(index) < 256:
            Ctype = numpy.uint8
            GLtype = GL_UNSIGNED_BYTE
        else:
            Ctype = numpy.uint16
            GLtype = GL_UNSIGNED_SHORT
            pass
        sphereCIndexTypes += [Ctype]
        sphereGLIndexTypes += [GLtype]
        sphereCIndex = numpy.array(index, dtype = Ctype)
        sphereCVerts = numpy.array(verts, dtype = numpy.float32)
        sphereCElements += [(sphereCIndex, sphereCVerts)]
        continue
    drawing_globals.sphereCIndexTypes = sphereCIndexTypes
    drawing_globals.sphereGLIndexTypes = sphereGLIndexTypes
    drawing_globals.sphereCElements = sphereCElements

    if glGetString(GL_EXTENSIONS).find("GL_ARB_vertex_buffer_object") >= 0:

        # A GLBufferObject version for glDrawArrays.
        sphereArrayVBOs = []
        for i in range(_NUM_SPHERE_SIZES):
            vbo = GLBufferObject(GL_ARRAY_BUFFER_ARB,
                                 sphereCArrays[i], GL_STATIC_DRAW)
            sphereArrayVBOs += [vbo]
            continue
        drawing_globals.sphereArrayVBOs = sphereArrayVBOs

        # A GLBufferObject version for glDrawElements indexed verts.
        sphereElementVBOs = []              # Pairs of (IBO, VBO)
        for i in range(_NUM_SPHERE_SIZES):
            ibo = GLBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB,
                                 sphereCElements[i][0], GL_STATIC_DRAW)
            vbo = GLBufferObject(GL_ARRAY_BUFFER_ARB,
                                 sphereCElements[i][1], GL_STATIC_DRAW)
            sphereElementVBOs += [(ibo, vbo)]
            continue
        drawing_globals.sphereElementVBOs = sphereElementVBOs

        ibo.unbind()
        vbo.unbind()
        pass

    #bruce 060415
    drawing_globals.wiresphere1list = wiresphere1list = glGenLists(1)
    glNewList(wiresphere1list, GL_COMPILE)
    didlines = {} # don't draw each triangle edge more than once

    def shoulddoline(v1,v2):
        # make sure not list (unhashable) or Numeric array (bug in __eq__)
        v1 = tuple(v1)
        v2 = tuple(v2)
        if (v1,v2) not in didlines:
            didlines[(v1,v2)] = didlines[(v2,v1)] = None
            return True
        return False
    def doline(v1,v2):
        if shoulddoline(v1,v2):
            glVertex3fv(v1)
            glVertex3fv(v2)
        return
    glBegin(GL_LINES)
    ocdec = getSphereTriangles(1)
    for tri in ocdec:
        #e Could probably optim this more, e.g. using a vertex array or VBO or
        #  maybe GL_LINE_STRIP.
        doline(tri[0], tri[1])
        doline(tri[1], tri[2])
        doline(tri[2], tri[0])
    glEnd()
    glEndList()

    drawing_globals.CylList = CylList = glGenLists(1)
    glNewList(CylList, GL_COMPILE)
    glBegin(GL_TRIANGLE_STRIP)
    for (vtop, ntop, vbot, nbot) in drawing_globals.cylinderEdges:
        glNormal3fv(nbot)
        glVertex3fv(vbot)
        glNormal3fv(ntop)
        glVertex3fv(vtop)
    glEnd()
    glEndList()

    drawing_globals.CapList = CapList = glGenLists(1)
    glNewList(CapList, GL_COMPILE)
    glNormal3fv(drawing_globals.cap0n)
    glBegin(GL_POLYGON)
    for p in drawing_globals.drum0:
        glVertex3fv(p)
    glEnd()
    glNormal3fv(drawing_globals.cap1n)
    glBegin(GL_POLYGON)
    #bruce 060609 fix "ragged edge" bug in this endcap: drum1 -> drum2
    for p in drawing_globals.drum2:
        glVertex3fv(p)
    glEnd()
    glEndList()

    drawing_globals.diamondGridList = diamondGridList = glGenLists(1)
    glNewList(diamondGridList, GL_COMPILE)
    glBegin(GL_LINES)
    for p in drawing_globals.digrid:
        glVertex(p[0])
        glVertex(p[1])
    glEnd()
    glEndList()

    drawing_globals.lonsGridList = lonsGridList = glGenLists(1)
    glNewList(lonsGridList, GL_COMPILE)
    glBegin(GL_LINES)
    for p in drawing_globals.lonsEdges:
        glVertex(p[0])
        glVertex(p[1])
    glEnd()
    glEndList()

    drawing_globals.CubeList = CubeList = glGenLists(1)
    glNewList(CubeList, GL_COMPILE)
    glBegin(GL_QUAD_STRIP)
    # note: CubeList has only 4 faces of the cube; only suitable for use in
    # wireframes; see also solidCubeList [bruce 051215 comment reporting
    # grantham 20051213 observation]
    glVertex((-1,-1,-1))
    glVertex(( 1,-1,-1))
    glVertex((-1, 1,-1))
    glVertex(( 1, 1,-1))
    glVertex((-1, 1, 1))
    glVertex(( 1, 1, 1))
    glVertex((-1,-1, 1))
    glVertex(( 1,-1, 1))
    glVertex((-1,-1,-1))
    glVertex(( 1,-1,-1))
    glEnd()
    glEndList()

    drawing_globals.solidCubeList = solidCubeList = glGenLists(1)
    glNewList(solidCubeList, GL_COMPILE)
    glBegin(GL_QUADS)
    for i in xrange(len(drawing_globals.cubeIndices)):
        avenormals = V(0,0,0) #bruce 060302 fixed normals for flat shading
        for j in xrange(4) :
            nTuple = tuple(
                drawing_globals.cubeNormals[drawing_globals.cubeIndices[i][j]])
            avenormals += A(nTuple)
        avenormals = norm(avenormals)
        for j in xrange(4) :
            vTuple = tuple(
                drawing_globals.cubeVertices[drawing_globals.cubeIndices[i][j]])
            #bruce 060302 made size compatible with glut.glutSolidCube(1.0)
            vTuple = A(vTuple) * 0.5
            glNormal3fv(avenormals)
            glVertex3fv(vTuple)
    glEnd()
    glEndList()

    drawing_globals.rotSignList = rotSignList = glGenLists(1)
    glNewList(rotSignList, GL_COMPILE)
    glBegin(GL_LINE_STRIP)
    for ii in xrange(len(drawing_globals.rotS0n)):
        glVertex3fv(tuple(drawing_globals.rotS0n[ii]))
    glEnd()
    glBegin(GL_LINE_STRIP)
    for ii in xrange(len(drawing_globals.rotS1n)):
        glVertex3fv(tuple(drawing_globals.rotS1n[ii]))
    glEnd()
    glBegin(GL_TRIANGLES)
    for v in drawing_globals.arrow0Vertices + drawing_globals.arrow1Vertices:
        glVertex3f(v[0], v[1], v[2])
    glEnd()
    glEndList()

    drawing_globals.linearArrowList = linearArrowList = glGenLists(1)
    glNewList(linearArrowList, GL_COMPILE)
    glBegin(GL_TRIANGLES)
    for v in drawing_globals.linearArrowVertices:
        glVertex3f(v[0], v[1], v[2])
    glEnd()
    glEndList()

    drawing_globals.linearLineList = linearLineList = glGenLists(1)
    glNewList(linearLineList, GL_COMPILE)
    glEnable(GL_LINE_SMOOTH)
    glBegin(GL_LINES)
    glVertex3f(0.0, 0.0, -drawing_globals.halfHeight)
    glVertex3f(0.0, 0.0, drawing_globals.halfHeight)
    glEnd()
    glDisable(GL_LINE_SMOOTH)
    glEndList()

    drawing_globals.circleList = circleList = glGenLists(1)
    glNewList(circleList, GL_COMPILE)
    glBegin(GL_LINE_LOOP)
    for ii in range(60):
        x = cos(ii*2.0*pi/60)
        y = sin(ii*2.0*pi/60)
        glVertex3f(x, y, 0.0)
    glEnd()
    glEndList()

    # piotr 080405
    drawing_globals.filledCircleList = filledCircleList = glGenLists(1)
    glNewList(filledCircleList, GL_COMPILE)
    glBegin(GL_POLYGON)
    for ii in range(60):
        x = cos(ii*2.0*pi/60)
        y = sin(ii*2.0*pi/60)
        glVertex3f(x, y, 0.0)
    glEnd()
    glEndList()

    drawing_globals.lineCubeList = lineCubeList = glGenLists(1)
    glNewList(lineCubeList, GL_COMPILE)
    glBegin(GL_LINES)
    cvIndices = [0,1, 2,3, 4,5, 6,7, 0,3, 1,2, 5,6, 4,7, 0,4, 1,5, 2,6, 3,7]
    for i in cvIndices:
        glVertex3fv(tuple(drawing_globals.cubeVertices[i]))
    glEnd()
    glEndList()

    #initTexture('C:\\Huaicai\\atom\\temp\\newSample.png', 128,128)
    return # from setup_drawer
    def dibujar_rectas(self, cuadrante: str):
        def dibujar(inicio, fin):
            glBegin(GL_LINES)
            glVertex(inicio)
            glVertex(fin)
            glEnd()

        for i in range(self.programa.lista_rectas.count()):
            recta = self.programa.lista_rectas.itemWidget(
                self.programa.lista_rectas.item(i))
            if recta.render.isChecked():
                glColor(recta.color)
                glLineWidth(recta.grosor)
                if recta.infinita.isChecked():
                    if "I" in recta.partes and cuadrante == "I":
                        glBegin(GL_LINES)
                        glVertex(recta.partes["I"][0])
                        glVertex(recta.partes["I"][1])
                        glEnd()
                    if "II" in recta.partes and cuadrante == "II":
                        glBegin(GL_LINES)
                        glVertex(recta.partes["II"][0])
                        glVertex(recta.partes["II"][1])
                        glEnd()
                    elif "III" in recta.partes and cuadrante == "III":
                        glBegin(GL_LINES)
                        glVertex(recta.partes["III"][0])
                        glVertex(recta.partes["III"][1])
                        glEnd()
                    elif "IV" in recta.partes and cuadrante == "IV":
                        glBegin(GL_LINES)
                        glVertex(recta.partes["IV"][0])
                        glVertex(recta.partes["IV"][1])
                        glEnd()
                    self.traza_v_recta(recta)
                    self.traza_h_recta(recta)
                else:
                    if recta.traza_v == "Contenida en PV" and recta.traza_h == "Contenida en PH":
                        if cuadrante == "I":
                            dibujar(recta.punto_1.coordinates,
                                    recta.punto_2.coordinates)
                    if recta.traza_v == "Contenida en PV":
                        if recta.traza_h_entre_puntos:
                            if cuadrante == recta.cuadrante_punto_1:
                                dibujar(recta.punto_1.coordinates,
                                        recta.traza_h)
                            if cuadrante == recta.cuadrante_punto_2:
                                dibujar(recta.punto_2.coordinates,
                                        recta.traza_h)
                            self.traza_h_recta(recta)
                        else:
                            if cuadrante == recta.cuadrante_punto_1:
                                dibujar(recta.punto_1.coordinates,
                                        recta.punto_2.coordinates)

                    elif recta.traza_h == "Contenida en PH":
                        if recta.traza_v_entre_puntos:
                            if cuadrante == recta.cuadrante_punto_1:
                                dibujar(recta.punto_1.coordinates,
                                        recta.traza_v)
                            if cuadrante == recta.cuadrante_punto_2:
                                dibujar(recta.punto_2.coordinates,
                                        recta.traza_v)
                            self.traza_v_recta(recta)
                        else:
                            if cuadrante == recta.cuadrante_punto_1:
                                dibujar(recta.punto_1.coordinates,
                                        recta.punto_2.coordinates)

                    elif recta.cuadrante_punto_1 == recta.cuadrante_punto_2 == cuadrante == "I":
                        dibujar(recta.punto_1.coordinates,
                                recta.punto_2.coordinates)
                    elif recta.cuadrante_punto_1 == recta.cuadrante_punto_2 == cuadrante == "II":
                        dibujar(recta.punto_1.coordinates,
                                recta.punto_2.coordinates)
                    elif recta.cuadrante_punto_1 == recta.cuadrante_punto_2 == cuadrante == "III":
                        dibujar(recta.punto_1.coordinates,
                                recta.punto_2.coordinates)
                    elif recta.cuadrante_punto_1 == recta.cuadrante_punto_2 == cuadrante == "IV":
                        dibujar(recta.punto_1.coordinates,
                                recta.punto_2.coordinates)
                    else:
                        if recta.traza_v_entre_puntos and recta.traza_h_entre_puntos:
                            if recta.segmento_entre_trazas == cuadrante:
                                dibujar(recta.traza_v, recta.traza_h)
                            elif recta.traza_v_entre_puntos == recta.traza_h_entre_puntos == "LT":
                                if recta.cuadrante_punto_1 == cuadrante:
                                    dibujar(recta.punto_1.coordinates,
                                            recta.traza_h)
                                if recta.cuadrante_punto_2 == cuadrante:
                                    dibujar(recta.punto_2.coordinates,
                                            recta.traza_h)
                                self.traza_h_recta(recta)
                        if recta.cuadrante_punto_1 == cuadrante:
                            if recta.traza_h_entre_puntos == "PH+" and (
                                    cuadrante == "I" or cuadrante == "IV"):
                                dibujar(recta.punto_1.coordinates,
                                        recta.traza_h)
                                self.traza_h_recta(recta)
                            if recta.traza_h_entre_puntos == "PH-" and (
                                    cuadrante == "II" or cuadrante == "III"):
                                dibujar(recta.punto_1.coordinates,
                                        recta.traza_h)
                                self.traza_h_recta(recta)

                            if recta.traza_v_entre_puntos == "PV+" and (
                                    cuadrante == "I" or cuadrante == "II"):
                                dibujar(recta.punto_1.coordinates,
                                        recta.traza_v)
                                self.traza_v_recta(recta)
                            if recta.traza_v_entre_puntos == "PV-" and (
                                    cuadrante == "III" or cuadrante == "IV"):
                                dibujar(recta.punto_1.coordinates,
                                        recta.traza_v)
                                self.traza_v_recta(recta)
                        if recta.cuadrante_punto_2 == cuadrante:
                            if recta.traza_h_entre_puntos == "PH+" and (
                                    cuadrante == "I" or cuadrante == "IV"):
                                dibujar(recta.punto_2.coordinates,
                                        recta.traza_h)
                                self.traza_h_recta(recta)
                            if recta.traza_h_entre_puntos == "PH-" and (
                                    cuadrante == "II" or cuadrante == "III"):
                                dibujar(recta.punto_2.coordinates,
                                        recta.traza_h)
                                self.traza_h_recta(recta)

                            if recta.traza_v_entre_puntos == "PV+" and (
                                    cuadrante == "I" or cuadrante == "II"):
                                dibujar(recta.punto_2.coordinates,
                                        recta.traza_v)
                                self.traza_v_recta(recta)
                            if recta.traza_v_entre_puntos == "PV-" and (
                                    cuadrante == "III" or cuadrante == "IV"):
                                dibujar(recta.punto_2.coordinates,
                                        recta.traza_v)
                                self.traza_v_recta(recta)
コード例 #47
0
ファイル: bounding.py プロジェクト: stjordanis/pydune
    def __init__(self, mesh):
        self.outline_color = (1, 1, 1)
        vertices = mesh.vertex_list.getVertices()
        minV = Vector3()
        maxV = Vector3()
        vertices.sort(lambda x, y: cmp(y.x, x.x))
        minV.x = vertices[0].x
        maxV.x = vertices[-1].x
        vertices.sort(lambda x, y: cmp(y.y, x.y))
        minV.y = vertices[0].y
        maxV.y = vertices[-1].y
        vertices.sort(lambda x, y: cmp(y.z, x.z))
        minV.z = vertices[0].z
        maxV.z = vertices[-1].z

        self.points = []
        for i in range(8):
            self.points.append(Vector3())
        for i in range(2):
            for j in range(2):
                self.points[int('%d%d%d' % (0, i, j), 2)].x = minV.x
                self.points[int('%d%d%d' % (1, i, j), 2)].x = maxV.x
                self.points[int('%d%d%d' % (i, 0, j), 2)].y = minV.y
                self.points[int('%d%d%d' % (i, 1, j), 2)].y = maxV.y
                self.points[int('%d%d%d' % (i, j, 0), 2)].z = minV.z
                self.points[int('%d%d%d' % (i, j, 1), 2)].z = maxV.z

        self.center = Vector3()
        for p in self.points:
            self.center += p
        self.center /= float(8)
        self.dl = glGenLists(1)
        glNewList(self.dl, GL_COMPILE)
        glLineWidth(5)
        c = self.outline_color
        glColor4f(c[0], c[1], c[2], 0.2)
        glBegin(GL_LINE_STRIP)
        for v in self.points:
            glVertex(v())
        glEnd()
        c = self.points
        glBegin(GL_LINES)

        glVertex(c[0]())
        glVertex(c[2]())
        glVertex(c[6]())
        glVertex(c[4]())

        glVertex(c[1]())
        glVertex(c[3]())
        glVertex(c[7]())
        glVertex(c[5]())

        glVertex(c[0]())
        glVertex(c[1]())
        glVertex(c[3]())
        glVertex(c[2]())

        glVertex(c[2]())
        glVertex(c[3]())
        glVertex(c[7]())
        glVertex(c[6]())

        glVertex(c[7]())
        glVertex(c[6]())
        glVertex(c[4]())
        glVertex(c[5]())

        glVertex(c[0]())
        glVertex(c[1]())
        glVertex(c[5]())
        glVertex(c[4]())

        glEnd()
        glPushMatrix()
        glTranslatef(self.center.x, self.center.y, self.center.z)
        q = gluNewQuadric()
        gluSphere(q, GLdouble(0.25), GLint(10), GLint(10))
        glPopMatrix()
        glEndList()
コード例 #48
0
ファイル: drawers.py プロジェクト: vcsrc/nanoengineer
def drawOriginAsSmallAxis(scale, origin, dashEnabled=False):
    """
    Draws a small wireframe version of the origin. It is rendered as a
    3D point at (0, 0, 0) with 3 small axes extending from it in the positive
    X, Y, Z directions.

    @see: drawaxes (related code)
    """
    #Perhaps we should split this method into smaller methods? ninad060920
    #Notes:
    #1. drawing arrowheads implemented on 060918
    #2. ninad060921 Show the origin axes as dotted if behind the mode.
    #3. ninad060922 The arrow heads are drawn as wireframe cones if behind the
    #   object the arrowhead size is slightly smaller (otherwise some portion of
    #   the the wireframe arrow shows up!
    #4 .Making origin non-zoomable is acheived by replacing hardcoded 'n' with
    #   glpane's scale - ninad060922

    #ninad060922 in future , the following could be user preferences.
    if (dashEnabled):
        dashShrinkage = 0.9
    else:
        dashShrinkage = 1
    x1, y1, z1 = scale * 0.01, scale * 0.01, scale * 0.01
    xEnd, yEnd, zEnd = scale * 0.04, scale * 0.09, scale * 0.025
    arrowBase = scale * 0.0075 * dashShrinkage
    arrowHeight = scale * 0.035 * dashShrinkage
    lineWidth = 1.0

    glPushMatrix()

    glTranslate(origin[0], origin[1], origin[2])
    glDisable(GL_LIGHTING)
    glLineWidth(lineWidth)

    gleNumSides = gleGetNumSides()
    #Code to show hidden lines of the origin if some model obscures it
    #  ninad060921
    if dashEnabled:
        glLineStipple(2, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)
        glDisable(GL_DEPTH_TEST)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        gleSetNumSides(5)
    else:
        gleSetNumSides(10)

    glBegin(GL_LINES)

    color = env.prefs[originAxisColor_prefs_key]

    glColor3fv(color)

    #start draw a point at origin .
    #ninad060922 is thinking about using GL_POINTS here

    glVertex(-x1, 0.0, 0.0)
    glVertex(x1, 0.0, 0.0)
    glVertex(0.0, -y1, 0.0)
    glVertex(0.0, y1, 0.0)
    glVertex(-x1, y1, z1)
    glVertex(x1, -y1, -z1)
    glVertex(x1, y1, z1)
    glVertex(-x1, -y1, -z1)
    glVertex(x1, y1, -z1)
    glVertex(-x1, -y1, z1)
    glVertex(-x1, y1, -z1)
    glVertex(x1, -y1, z1)
    #end draw a point at origin

    #start draw small origin axes

    glColor3fv(color)
    glVertex(xEnd, 0.0, 0.0)
    glVertex(0.0, 0.0, 0.0)

    glColor3fv(color)
    glVertex(0.0, yEnd, 0.0)
    glVertex(0.0, 0.0, 0.0)

    glColor3fv(color)
    glVertex(0.0, 0.0, zEnd)
    glVertex(0.0, 0.0, 0.0)
    glEnd()  #end draw lines
    glLineWidth(1.0)

    # End push matrix for drawing various lines in the origin and axes.
    glPopMatrix()

    #start draw solid arrow heads  for  X , Y and Z axes
    glPushMatrix()
    glDisable(GL_CULL_FACE)
    glColor3fv(color)
    glTranslatef(xEnd, 0.0, 0.0)
    glRotatef(90, 0.0, 1.0, 0.0)

    glePolyCone(
        [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]],
        None, [arrowBase, arrowBase, 0, 0])

    glPopMatrix()

    glPushMatrix()
    glColor3fv(color)
    glTranslatef(0.0, yEnd, 0.0)
    glRotatef(-90, 1.0, 0.0, 0.0)

    glePolyCone(
        [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]],
        None, [arrowBase, arrowBase, 0, 0])

    glPopMatrix()

    glPushMatrix()
    glColor3fv(color)
    glTranslatef(0.0, 0.0, zEnd)

    glePolyCone(
        [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]],
        None, [arrowBase, arrowBase, 0, 0])

    #Disable line stipple and Enable Depth test
    if dashEnabled:
        glLineStipple(1, 0xAAAA)
        glDisable(GL_LINE_STIPPLE)
        glEnable(GL_DEPTH_TEST)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    gleSetNumSides(gleNumSides)
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPopMatrix()
    #end draw solid arrow heads  for  X , Y and Z axes
    return