Beispiel #1
0
 def polar(self):
     """
     camera.polar() -> (theta, phi)
     Returns the heading (theta) and elevation (phi) of the camera.
     """
     theta = atan2(-1.0 * self.vpn[Z_AXIS], self.vpn[X_AXIS]) * 180 / pi
     distXZ = sqrt(self.vpn[X_AXIS] * self.vpn[X_AXIS] + self.vpn[Z_AXIS] * self.vpn[Z_AXIS])
     phi = 90.0 - acos(dot_product(self.vpn, (0.0, 1.0, 0.0))) * 180 / pi
     return (theta, phi)
Beispiel #2
0
def ease_triad(triad):
    #bs = [keymap[triad[i]]['base'] * wb[i] / 10 for i in range(len(triad))]
    # ps = [penalties[c] for c in triad]
    ss = path(triad)
    #print(triad + ' ---------------------------')
    #print('stroke path: ' + str(ss))
    # commented out, compound(ps, wp), dot_product(bs, wb)
    components = dot_product(ss, ws)
    #print('penalty: %.2f' % components)
    return 0
Beispiel #3
0
    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)