コード例 #1
0
ファイル: object3D.py プロジェクト: softtrainee/arlab
    def _text_(self, text, offs, stroke=False, color=None):
        '''
        '''

        if stroke:
            font = GLUT_STROKE_ROMAN

            glutStrokeWidth(font, 50)
            for c in text:
                glutStrokeCharacter(font, ord(c))
        else:
            glDisable(GL_LIGHTING)
            co = color if (color and (isinstance(color, tuple) or isinstance(color, list))) else (0, 1, 0)

            glColor3f(*co)
            font = GLUT_BITMAP_HELVETICA_18
            glRasterPos2f(*offs)
            for c in text:
                glutBitmapCharacter(font, ord(c))
            glEnable(GL_LIGHTING)
コード例 #2
0
ファイル: measure.py プロジェクト: yuhangwang/zeobuilder
    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()
コード例 #3
0
ファイル: measure.py プロジェクト: molmod/zeobuilder
    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()
コード例 #4
0
ファイル: interfacegl.py プロジェクト: ulethHCI/GLuskap
    def drawHUD(self, camera, vertices, pos=None, status=''):
        from OpenGL.GLUT import glutStrokeCharacter, GLUT_STROKE_MONO_ROMAN

        view = glGetInteger(GL_VIEWPORT)
        if (view[1] != 0) or (view[3] != 0):
            # print "view = [", view[0], ",", view[1], ",", view[2], ",", view[3]
            # Switch to an orthogonal projection for drawing the HUD
            glDisable(GL_LIGHTING)
            glDisable(GL_DEPTH_TEST)
            glMatrixMode(GL_PROJECTION)
            glPushMatrix()
            glLoadIdentity()
            vheight = view[3] - view[1]
            vwidth = view[2]
            right = 100.0
            top = float(vheight) / float(vwidth) * right
            glOrtho(0.0, right, 0.0, top, 0.0, 1.0)
            glMatrixMode(GL_MODELVIEW)
            glPushMatrix()
            glLoadIdentity()
            gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
            #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            glEnable(GL_BLEND)
            glEnable(GL_LINE_SMOOTH)
            glEnable(GL_POLYGON_SMOOTH)

            #
            # Begin draw
            #
            from math import sin, cos, pi, atan2, acos, sqrt
            from utilities import diff3D, dist3D

            def circle():
                for x in range(25):
                    theta = x * 2 * pi / 24
                    glVertex3f(cos(theta), sin(theta), 0.0)

            def halfcircle(start, end):
                for x in range(start, end):
                    theta = x * 2 * pi / 24
                    glVertex3f(cos(theta), sin(theta), 0.0)

            # Move into position to draw
            glLineWidth(1.0)
            glColor4f(1.0, 1.0, 1.0, 0.35)
            glPushMatrix()
            glTranslatef(89.0, 8.0, 0.001)
            glPushMatrix()

            glPushAttrib(GL_CURRENT_BIT)
            # Draw a circle to represent the XZ plane (bearing)
            glScalef(4.0, 4.0, 1.0)
            glBegin(GL_TRIANGLE_FAN)
            glVertex3f(0.0, 0.0, 0.0)
            circle()
            glEnd()

            # Draw the orientation of the camera
            glPushMatrix()
            glScalef(1.01, 1.01, 1.0)
            glColor4f(0.9, 0.9, 0.4, 0.9)
            glRotatef(180.0 * atan2(-1.0 * camera.vpn[Z_AXIS], camera.vpn[X_AXIS]) / pi, 0.0, 0.0, 1.0)
            glBegin(GL_TRIANGLE_FAN)
            glVertex3f(0.0, 0.0, 0.0)
            halfcircle(-2, 3)
            glEnd()
            glPopMatrix()

            # Draw the origin marker
            glPushMatrix()
            dOrigin = diff3D((0.0, 0.0, 0.0), camera.pos)

            glRotatef(270 - 180.0 * atan2(camera.pos[Z_AXIS], camera.pos[X_AXIS]) / pi - 90.0, 0.0, 0.0, 1.0)
            glColor4f(0.9, 0.2, 0.2, 0.95)
            glBegin(GL_TRIANGLES)
            glVertex3f(0.9, 0.0, 0.0)
            glVertex3f(1.1, -0.1, 0.0)
            glVertex3f(1.1, 0.1, 0.0)
            glEnd()
            glPopMatrix()

            # If there are vertices selected, draw vertex markers
            for v in vertices:
                glPushMatrix()
                dVertex = diff3D(v.pos, camera.pos)

                glRotatef(270 - 180.0 * atan2(dVertex[Z_AXIS], dVertex[X_AXIS]) / pi - 90.0, 0.0, 0.0, 1.0)
                glColor4f(0.2, 0.7, 0.9, 0.95)
                glBegin(GL_TRIANGLES)
                glVertex3f(0.9, 0.0, 0.0)
                glVertex3f(1.1, -0.1, 0.0)
                glVertex3f(1.1, 0.1, 0.0)
                glEnd()
                glPopMatrix()

            # Draw the X and Z axes on it
            glBegin(GL_LINE_STRIP)
            glColor3f(1.0, 0.5, 0.5)
            glVertex3f(-1.0, 0.0, 0.0)
            glVertex3f(-0.01, 0.0, 0.0)
            glColor3f(1.0, 0.0, 0.0)
            glVertex3f(0.0, 0.0, 0.0)
            glColor3f(0.5, 0.0, 0.0)
            glVertex3f(0.01, 0.0, 0.0)
            glVertex3f(1.0, 0.0, 0.0)
            glEnd()
            glBegin(GL_LINE_STRIP)
            glColor3f(0.5, 0.5, 1.0)
            glVertex3f(0.0, 1.0, 0.0)
            glVertex3f(0.0, 0.01, 0.0)
            glColor3f(0.0, 0.0, 1.0)
            glVertex3f(0.0, 0.0, 0.0)
            glColor3f(0.0, 0.0, 0.5)
            glVertex3f(0.0, -0.01, 0.0)
            glVertex3f(0.0, -1.0, 0.0)
            glEnd()
            glPopAttrib()
            # Done drawing XZ plane

            # Draw a half-circle to represent elevation
            glPushAttrib(GL_CURRENT_BIT)
            glTranslatef(2.2, 0.0, 0.0)
            glBegin(GL_TRIANGLE_FAN)
            halfcircle(6, 19)
            glEnd()

            # Draw the orientation of the camera
            glPushMatrix()
            glScalef(1.01, 1.01, 1.0)
            glColor4f(0.9, 0.9, 0.4, 0.9)
            glRotatef(90.0 + 180.0 * acos(utilities.dot_product(camera.vpn, (0.0, 1.0, 0.0))) / pi, 0.0, 0.0, 1.0)
            glBegin(GL_TRIANGLE_FAN)
            glVertex3f(0.0, 0.0, 0.0)
            halfcircle(-2, 3)
            glEnd()
            glPopMatrix()

            # Draw the zero-elevation line
            glBegin(GL_LINES)
            glColor4f(0.0, 0.0, 0.0, 1.0)
            glVertex3f(-1.0, 0.0, 0.0)
            glVertex3f(0.0, 0.0, 0.0)
            glEnd()

            # Draw the origin marker
            glPushMatrix()
            dOrigin = diff3D(camera.pos, (0.0, 0.0, 0.0))
            dist = dist3D(c=dOrigin)

            glRotatef(90.0 + 180.0 * acos(utilities.dot_product(dOrigin, (0.0, 1.0, 0.0)) / dist) / pi, 0.0, 0.0, 1.0)
            glColor4f(0.9, 0.2, 0.2, 0.95)
            glBegin(GL_TRIANGLES)
            glVertex3f(0.9, 0.0, 0.0)
            glVertex3f(1.1, -0.1, 0.0)
            glVertex3f(1.1, 0.1, 0.0)
            glEnd()
            glPopMatrix()

            # If there are vertices selected, draw vertex markers
            for v in vertices:
                glPushMatrix()
                dVertex = diff3D(v.pos, camera.pos)
                dist = dist3D(c=dVertex)

                glRotatef(270.0 - 180.0 * acos(utilities.dot_product(dVertex, (0.0, 1.0, 0.0)) / dist) / pi, 0.0, 0.0,
                          1.0)
                glColor4f(0.2, 0.7, 0.9, 0.95)
                glBegin(GL_TRIANGLES)
                glVertex3f(0.9, 0.0, 0.0)
                glVertex3f(1.1, -0.1, 0.0)
                glVertex3f(1.1, 0.1, 0.0)
                glEnd()
                glPopMatrix()

            # Clean up
            glPopMatrix()
            glPopAttrib()


            # Coordinates - if _pos_ is specified, draw that,
            # otherwise use the current position of the camera.
            if pos == None:
                pos = camera.pos

            glPushAttrib(GL_CURRENT_BIT)
            glPushMatrix()
            glTranslatef(-8.0, -7.0, 0.0)
            glScalef(0.009, 0.016, 1.0)
            # Draw the background box
            glBegin(GL_QUADS)
            glVertex3f(0.0, -40.0, 0.0)
            glVertex3f(2300.0, -40.0, 0.0)
            glVertex3f(2300.0, 140.0, 0.0)
            glVertex3f(0.0, 140.0, 0.0)
            glEnd()
            # Draw the text
            xS = ('%.1f' % pos[0]).rjust(6) + ' '
            yS = ('%.1f' % pos[1]).rjust(6) + ' '
            zS = ('%.1f' % pos[2]).rjust(6) + ' '
            glLineWidth(1.7)
            glColor4f(0.56, 0.0, 0.0, 0.9)
            for c in xS:
                glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, ord(c))
            glColor4f(0.0, 0.56, 0.0, 0.9)
            for c in yS:
                glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, ord(c))
            glColor4f(0.0, 0.0, 0.56, 0.9)
            for c in zS:
                glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, ord(c))
            glPopAttrib()
            glPopMatrix()

            glPopMatrix()

            #
            # end draw
            #


            #
            # now draw HUD status line
            #
            if status:
                glColor4f(1.0, 1.0, 1.0, 0.25)
                glPushMatrix()
                glTranslatef(0.0, 1.0, 0.001)
                glPushMatrix()

                glScalef(0.009, 0.016, 1.0)
                glBegin(GL_QUADS)
                glVertex3f(0.0, -40.0, 0.0)
                glVertex3f(5000.0, -40.0, 0.0)
                glVertex3f(5000.0, 140.0, 0.0)
                glVertex3f(0.0, 140.0, 0.0)
                glEnd()

                glLineWidth(1.4)
                glColor4f(0.56, 0.0, 0.0, 0.9)
                # Add some space before the first character
                glTranslatef(200.0, 0.0, 0.0)
                for c in status:
                    glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(c))

                glPopMatrix()
                glPopMatrix()


            #
            # end HUD statusline draw
            #

            glPopMatrix()
            glMatrixMode(GL_PROJECTION)
            glPopMatrix()
            glMatrixMode(GL_MODELVIEW)
            glEnable(GL_LIGHTING)
            glEnable(GL_DEPTH_TEST)
コード例 #5
0
ファイル: interfacegl.py プロジェクト: ulethHCI/GLuskap
    def drawVertexLabels(self, parent, vxlist, labelFunc, labelStrokeWidth, labelColor, shadowColor):
        """
        drawVertexLabels(vxlist, labelFunc, labelStrokeWidth, labelColor, shadowColor) -> void
        Draws labels for vertices in vxlist on an ortho projection layer.

        labelStrokeWidth: A float controlling the strokewidth for the label text.
        labelColor: A 3-tuple float color: the label text
        shadowColor: A 3-tuple float color: the label shadow
        labelFunc: A function that takes a vertex object and returns some value to use as the label for the vertex.
        """
        # model = glGetFloat(GL_MODELVIEW_MATRIX)
        model = glGetDouble(GL_MODELVIEW_MATRIX)
        proj = glGetDouble(GL_PROJECTION_MATRIX)
        view = glGetInteger(GL_VIEWPORT)
        coords = range(len(vxlist))
        ctx = parent

        for vnum in range(len(vxlist)):
            v = vxlist[vnum]
            # Multiply points if snapping to grid
            if ctx.showGrid:
                vpos = utilities.mult3D(v.pos, ctx.spacing)
            else:
                vpos = v.pos
            #print "not projected:", vpos
            coords[vnum] = gluProject(vpos[0], vpos[1], vpos[2], model, proj, view)

        # Switch to an orthogonal projection for drawing the labels
        glDisable(GL_LIGHTING)
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glOrtho(view[0], view[2], view[1], view[3], 0.0, 1.0)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glLineWidth(labelStrokeWidth)
        glDisable(GL_LINE_SMOOTH)
        gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

        # Unproject the screen coordinates into the new ortho projection
        model = glGetDouble(GL_MODELVIEW_MATRIX)
        proj = glGetDouble(GL_PROJECTION_MATRIX)
        view = glGetInteger(GL_VIEWPORT)

        for vnum in range(len(vxlist)):
            v = vxlist[vnum]
            label = str(labelFunc(v))
            if len(label) < 1 or v.hidden:
                continue

            x, y, z = coords[vnum]
            #print "BEFORE:", label, "at:", x, y, z
            trX, trY, trZ = gluUnProject(x, y, z, model, proj, view)
            #print "After:", label, "at:", trX, trY, trZ
            # Because we flatten the Z coordinate in the ortho project,
            # we have to manually discard Things Behind Us
            if trZ < 0.0:
                continue

            glPushMatrix()

            glTranslatef(trX, trY, 0.5)

            x = min(12.0 * trZ, 0.20)
            glScalef(x, x, x)
            offset = len(label) % 2 * -50.0 + -50.0 * (len(label) - 1)
            glTranslatef(offset, 0.0, 0.0)
            glTranslatef(0.0, 0.0, 0.0)

            # Draw the shadow
            glColor4f(shadowColor[0], shadowColor[1], shadowColor[2], 1.0)
            glPushMatrix()
            glTranslatef(7.5, -7.5, -0.5)
            for c in label:
                glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(c))
            glPopMatrix()

            # Draw the label
            glColor4f(labelColor[0], labelColor[1], labelColor[2], 1.0)
            glPushMatrix()
            for c in label:
                glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(c))
            glPopMatrix()

            glPopMatrix()

        glPopMatrix()
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glEnable(GL_LIGHTING)
コード例 #6
0
ファイル: interfacegl.py プロジェクト: ulethHCI/GLuskap
    def draw_localaxes(self, parent, vertex, axes=(X_AXIS, Y_AXIS, Z_AXIS), labels=('Q', 'A', 'W', 'S', 'E', 'D')):
        """Draw local axes around the specified vertex"""
        from math import log

        ctx = parent
        glPushMatrix()

        # Multiply points if snapping to grid
        if ctx.showGrid:
            glTranslatef(vertex.pos[0] * ctx.spacing, vertex.pos[1] * ctx.spacing, vertex.pos[2] * ctx.spacing)
        else:
            glTranslatef(vertex.pos[0], vertex.pos[1], vertex.pos[2])

        if vertex.radius > 0:
            scale = max(log(40 * vertex.radius, 10), 0)
        else:
            scale = 1
        scale = (vertex.radius + scale) * 1.5
        glScalef(scale, scale, scale)
        glDisable(GL_LIGHTING)
        glLineWidth(2.0)

        if X_AXIS in axes:
            # X axis
            glBegin(GL_LINE_STRIP)
            glColor3f(1.0, 0.5, 0.5)
            glVertex3f(-1.0, 0.0, 0.0)
            glVertex3f(-0.01, 0.0, 0.0)
            glColor3f(1.0, 0.0, 0.0)

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

        if Y_AXIS in axes:
            # Y axis
            glBegin(GL_LINE_STRIP)
            glColor3f(0.5, 1.0, 0.5)
            glVertex3f(0.0, -1.0, 0.0)
            glVertex3f(0.0, -0.01, 0.0)
            glColor3f(0.0, 1.0, 0.0)
            glVertex3f(0.0, 0.0, 0.0)

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

        if Z_AXIS in axes:
            # Z axis
            glBegin(GL_LINE_STRIP)
            glColor3f(0.5, 0.5, 1.0)
            glVertex3f(0.0, 0.0, -1.0)
            glVertex3f(0.0, 0.0, -0.01)
            glColor3f(0.0, 0.0, 1.0)
            glVertex3f(0.0, 0.0, 0.0)

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

        # Get the coordinates of the endpoints of each of the axes.
        model = glGetDouble(GL_MODELVIEW_MATRIX)
        proj = glGetDouble(GL_PROJECTION_MATRIX)
        view = glGetInteger(GL_VIEWPORT)
        coords = {}
        coords['-X'] = gluProject(-1.5, 0.0, 0.0, model, proj, view)
        coords['+X'] = gluProject(1.5, 0.0, 0.0, model, proj, view)
        coords['-Y'] = gluProject(0.0, -1.5, 0.0, model, proj, view)
        coords['+Y'] = gluProject(0.0, 1.5, 0.0, model, proj, view)
        coords['-Z'] = gluProject(0.0, 0.0, -1.5, model, proj, view)
        coords['+Z'] = gluProject(0.0, 0.0, 1.5, model, proj, view)
        glPopMatrix()

        # Switch to an orthogonal projection for drawing the labels
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glOrtho(view[0], view[0]+view[2], view[1], view[3], 0.0, 10.0)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glDisable(GL_LINE_SMOOTH)
        glLineWidth(1.0)
        gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

        # Unproject the screen coordinates into the new ortho projection
        model = glGetDouble(GL_MODELVIEW_MATRIX)
        proj = glGetDouble(GL_PROJECTION_MATRIX)
        view = glGetInteger(GL_VIEWPORT)

        info = {}
        if X_AXIS in axes:
            info.update({
            '+X': {'color': (0.5, 0.0, 0.0), 'label': labels[0]},
            '-X': {'color': (1.0, 0.5, 0.5), 'label': labels[1]},
            })
        if Y_AXIS in axes:
            info.update({
            '+Y': {'color': (0.0, 0.5, 0.0), 'label': labels[2]},
            '-Y': {'color': (0.5, 1.0, 0.5), 'label': labels[3]},
            })
        if Z_AXIS in axes:
            info.update({
            '+Z': {'color': (0.0, 0.0, 0.5), 'label': labels[4]},
            '-Z': {'color': (0.5, 0.5, 1.0), 'label': labels[5]},
            })
        for point in info.keys():
            if not coords[point]:
                continue

            glPushMatrix()

            x, y, z = coords[point]
            trX, trY, trZ = gluUnProject(x, y, z, model, proj, view)
            glTranslatef(trX, trY, trZ)

            c = info[point]['color']
            glColor4f(c[0], c[1], c[2], 1.0)

            # Set up for drawing the label and box
            glScalef(0.09, 0.09, 0.09)
            offset = len(info[point]['label']) % 2 * -50.0 + -50.0 * (len(info[point]['label']) - 1)
            glTranslatef(offset, -100.0, 0.0)

            # Draw a box around the text
            top = 160.0
            bottom = -60.0
            left = -50.0
            right = 100.0 * (len(info[point]['label']) + 1) - 10.0
            glColor4f(0.7, 0.7, 0.7, 1.0)
            glBegin(GL_QUADS)
            glVertex3f(left, bottom, -0.01)
            glVertex3f(right, bottom, -0.01)
            glVertex3f(right, top, -0.01)
            glVertex3f(left, top, -0.01)
            glEnd()
            glColor4f(c[0], c[1], c[2], 1.0)
            glBegin(GL_LINE_STRIP)
            glVertex3f(left, top, 0.0)
            glVertex3f(right, top, 0.0)
            glVertex3f(right, bottom, 0.0)
            glVertex3f(left, bottom, 0.0)
            glVertex3f(left, top, 0.0)
            glEnd()

            # Draw the label
            for c in info[point]['label']:
                glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, ord(c))
            glPopMatrix()

        # Restore the standard projection
        glPopMatrix()
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glEnable(GL_LIGHTING)