Beispiel #1
0
 def _line(self, r1, r2):
     glColor(1, 1, 1)
     glLineWidth(1)
     glBegin(GL_LINES)
     glVertex3f(r1[0], r1[1], 0.0)
     glVertex3f(r2[0], r2[1], 0.0)
     glEnd()
 def paint(self):
     glColor3f(0.0, 0.0, 0.6)
     glLineWidth(1.0);
     glBegin(GL_LINES)
     glVertex3f(*self.obj_a.position)
     glVertex3f(*self.obj_b.position)
     glEnd()
Beispiel #3
0
    def draw(self, time, line_width=None):
        if self.hidden:
            return
        if time <= self.ts:
            return
        time = time * 1e-9

        pos_start = self.pos
        path = self.speed * (time - self.ts * 1e-9) * self.dir
        # max_end = self.pos + (self.speed * self.te * self.dir)
        # if not int(self.te) == 0 and time > self.te:
        #    pos_end = max_end
        # else:
        #    pos_end = self.pos + path
        pos_end = self.pos + path

        glPushMatrix()
        if line_width:
            glLineWidth(line_width)
        else:
            glLineWidth(self.line_width)
        glColor3f(*self.color)
        glBegin(GL_LINES)
        glVertex3f(*pos_start)
        glVertex3f(*pos_end)
        glEnd()
        glPopMatrix()
Beispiel #4
0
def make_cube():

    glNewList(G_OBJ_CUBE, GL_COMPILE)

    vertices = [((-0.5, -0.5, -0.5), (-0.5, -0.5, 0.5), (-0.5, 0.5, 0.5),
                 (-0.5, 0.5, -0.5)),
                ((-0.5, -0.5, -0.5), (-0.5, 0.5, -0.5), (0.5, 0.5, -0.5),
                 (0.5, -0.5, -0.5)),
                ((0.5, -0.5, -0.5), (0.5, 0.5, -0.5), (0.5, 0.5, 0.5),
                 (0.5, -0.5, 0.5)),
                ((-0.5, -0.5, 0.5), (0.5, -0.5, 0.5), (0.5, 0.5, 0.5),
                 (-0.5, 0.5, 0.5)),
                ((-0.5, -0.5, 0.5), (-0.5, -0.5, -0.5), (0.5, -0.5, -0.5),
                 (0.5, -0.5, 0.5)),
                ((-0.5, 0.5, -0.5), (-0.5, 0.5, 0.5), (0.5, 0.5, 0.5),
                 (0.5, 0.5, -0.5))]

    normals = [(-1.0, 0.0, 0.0), (0.0, 0.0, -1.0), (1.0, 0.0, 0.0),
               (0.0, 0.0, 1.0), (0.0, -1.0, 0.0), (0.0, 1.0, 0.0)]

    glBegin(GL_QUADS)

    for i in range(6):

        glNormal3f(normals[i][0], normals[i][1], normals[i][2])

        for j in range(4):

            glVertex3f(vertices[i][j][0], vertices[i][j][1], vertices[i][j][2])

    glEnd()

    glEndList()
Beispiel #5
0
 def _line(self, r1, r2):
     glColor(1, 1, 1)
     glLineWidth(1)
     glBegin(GL_LINES)
     glVertex3f(r1[0], r1[1], 0.0)
     glVertex3f(r2[0], r2[1], 0.0)
     glEnd()
Beispiel #6
0
    def _make_list( self ):
        """generate opengl display list to draw triangles in mesh
        """
        # get available list name
        self.list_name = glGenLists( 1 )

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

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

        # for each triangle give normal and 3 vertices
        for triangle in self.triangles:
            glNormal3f( *triangle[0] )
            for i in range( 1, 4 ):
                glVertex3f( *triangle[i] )
        
        glEnd()
        glEndList()
Beispiel #7
0
    def initialize(self):
        glutPositionWindow(0, 600)
        GLRealtimeProgram.initialize(self)

        colors = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 0), (0, 1, 1), (1, 0, 1)]

        for (i, cloud) in enumerate(self.clouds):
            point_list = glGenLists(i + 1)
            self.point_lists.append(point_list)

            # compile the point cloud
            glNewList(point_list, GL_COMPILE)
            glDisable(GL_LIGHTING)
            glBegin(GL_POINTS)
            for point in cloud:
                if len(point) == 2:
                    xyz = point[0]
                    rgb = point[1]
                else:
                    xyz = point[:3]
                    if len(point) == 4:
                        rgb = point[3]
                    elif len(point) > 4:
                        rgb = point[3:6]
                    else:
                        rgb = None

                if rgb is not None:
                    glColor3f(*map(lambda x: x / 255.0, rgb))
                else:
                    glColor3f(*colors[i % len(colors)])
                glVertex3f(*xyz[:3])
            glEnd()
            glEndList()
            logging.debug("compiled {} points for cloud {}".format(len(cloud), i))
Beispiel #8
0
def draw_vertex_terrain(vertex):
    """ Draws point with terrain height color """
    z = vertex[2]
    if (z < 0 and z <= (MIN_HEIGHT / 2)):
        color = TERRAIN_COLOR_LOW
    elif (z > 0 and z >= (MAX_HEIGHT / 2)):
        color = TERRAIN_COLOR_HIGH
    else:
        color = TERRAIN_COLOR_MID

    color = hex_to_float(color)
    if (z < 0):
        minium_intensity = MIN_HEIGHT / (MIN_HEIGHT *
                                         DRAW_COLOR_INTENSITY_WEIGHT)
        intensity = (z / (MIN_HEIGHT * DRAW_COLOR_INTENSITY_WEIGHT))
        # intensity = 1 - (z / (MIN_HEIGHT * DRAW_COLOR_INTENSITY_WEIGHT))
    else:
        minium_intensity = MAX_HEIGHT / (MAX_HEIGHT *
                                         DRAW_COLOR_INTENSITY_WEIGHT)
        intensity = (z / (MAX_HEIGHT * DRAW_COLOR_INTENSITY_WEIGHT))
        # intensity = 1 - (z / (MAX_HEIGHT * DRAW_COLOR_INTENSITY_WEIGHT))
    intensity += minium_intensity
    color[0] = color[0] * intensity
    color[1] = color[1] * intensity
    color[2] = color[2] * intensity

    glColor3fv(color)
    glVertex3f(vertex[0], vertex[1], z * DRAW_HEIGHT_WEIGHT)
Beispiel #9
0
 def draw(self, i):
     glPointSize(7.0)
     glBegin(GL_POINTS)
     glColor3f(self.particles[i].r, self.particles[i].g,
               self.particles[i].b)
     glVertex3f(self.particles[i].x, self.particles[i].y,
                self.particles[i].z)
     glEnd()
Beispiel #10
0
 def drawPath(self, path, color):
     glPushMatrix()
     glColor3f(*color_map[color])
     glBegin(GL_LINE_STRIP)
     for (x, y, z, theta) in path.points_ptsztheta:
         glVertex3f(x, y, z)
     glEnd()
     glPopMatrix()
Beispiel #11
0
    def render_me(self):

        glColor3f(0.75, 0.3, 0.66)
        #glColor3f(1, 1, 1)

        # surface bounds
        x_lower_bound = -10
        x_upper_bound = 10
        y_lower_bound = -10
        y_upper_bound = 10

        step = 0.5

        x_current = x_lower_bound + step
        y_current = y_lower_bound + step

        # draw part of surface
        glBegin(GL_LINES)

        while x_current <= x_upper_bound + 0.0001:

            while y_current < y_upper_bound + 0.0001:
                normal = self.calculate_vertex_normal([
                    x_current,
                    self.surface_function(x_current, y_current), y_current
                ])
                glNormal3f(normal[0], normal[1], normal[2])
                glVertex3f(x_current,
                           self.surface_function(x_current, y_current),
                           y_current)

                y_current += step

            y_current = y_lower_bound + step
            x_current += step

        x_current = x_lower_bound + step
        y_current = y_lower_bound + step

        # draw part of surface
        while y_current <= y_upper_bound + 0.01:

            while x_current <= x_upper_bound + 0.01:
                normal = self.calculate_vertex_normal([
                    x_current,
                    self.surface_function(x_current, y_current), y_current
                ])
                glNormal3f(normal[0], normal[1], normal[2])
                glVertex3f(x_current,
                           self.surface_function(x_current, y_current),
                           y_current)

                x_current += step

            x_current = x_lower_bound + step
            y_current += step

        glEnd()
Beispiel #12
0
 def draw_doms(self, size=3):
     glPushMatrix()
     glPointSize(size)
     glColor3f(1.0, 1.0, 1.0)
     glBegin(GL_POINTS)
     for position in self.dom_positions:
         glVertex3f(position[0], position[1], position[2])
     glEnd()
     glPopMatrix()
    def _draw(self):
        glLineWidth(4.0)

        glBegin(GL_LINES)

        glColor3f(119, 25, 25)
        for path in list(self._path_queue):
            glVertex3f(path[0] * self._resolution_meter -4,path[1] * self._resolution_meter,5)
            glVertex3f(path[0]* self._resolution_meter+4,path[1] * self._resolution_meter,5)

        glEnd()
Beispiel #14
0
 def draw_lines(self, line_width=1):
     glEnable(GL_DEPTH_TEST)
     glShadeModel(GL_FLAT)
     for position in self.line_positions:
         glPushMatrix()
         glTranslated(position[0], position[1], 0)
         glLineWidth(line_width)
         glBegin(GL_LINES)
         glVertex3f(0.0, 0.0, self.z_min)
         glVertex3f(0.0, 0.0, self.z_max)
         glEnd()
         glPopMatrix()
Beispiel #15
0
    def draw_Dierkes_lines(self, result):

        glPushMatrix()
        glMatrixMode(GL_MODELVIEW)
        glColor4f(1.0, 0.0, 0.0, 0.1)
        glLineWidth(1.0)
        for line in result["debug_info"]["Dierkes_lines"][::4]:
            glBegin(GL_LINES)
            glVertex3f(line[0], line[1], line[2])
            glVertex3f(line[3], line[4], line[5])
            glEnd()
        glPopMatrix()
Beispiel #16
0
 def draw(self, line_width=2):
     glEnable(GL_DEPTH_TEST)
     glShadeModel(GL_FLAT)
     glPushMatrix()
     glTranslated(self.x, self.y, self.z)
     glLineWidth(line_width)
     glColor3f(1.0, 1.0, 1.0)
     glBegin(GL_LINES)
     glVertex3f(0.0, 0.0, 0.0)
     glVertex3f(0.0, 0.0, self.length)
     glEnd()
     glPopMatrix()
Beispiel #17
0
    def render(self):
        from OpenGL.GL import GL_POINTS, glBegin, glEnd, glVertex3f

        glBegin(GL_POINTS)
        try:
            for point in self.point_list:
                glVertex3f(point.x, point.y, point.z)
        except Exception as ex:
            error = str(ex)
            error = None
        finally:
            glEnd()
    def render_normals(self, length=1.0):
        from OpenGL.GL import GL_LINES, glBegin, glEnd, glVertex3f

        glBegin(GL_LINES)
        try:
            for triangle in self.yield_triangles():
                plane = triangle.calc_plane()
                center = triangle.calc_center()
                tip = center + plane.unit_normal * length
                glVertex3f(center.x, center.y, center.z)
                glVertex3f(tip.x, tip.y, tip.z)
        finally:
            glEnd()
Beispiel #19
0
def make_man():
    glNewList(G_OBJ_MAN, GL_COMPILE)
    obj=OBJ('./OBJ/smpl_np.obj')
    vertices=obj.vertices
    face=obj.faces
    for i in range(len(face)):
        glColor3f(216 / 255, 186 / 255, 160 / 255)
        glBegin(GL_TRIANGLES)
        glNormal3f(face[i][1][0],face[i][1][1],face[i][1][2])
        for j in range(3):
            glVertex3f(vertices[face[i][0][j]-1][0],vertices[face[i][0][j]-1][1],vertices[face[i][0][j]-1][2])
        glEnd()
    glEndList()
    def drawTexture(self, texture, dx, dy, dw, dh, x, y, w, h, r):
        '''
		texture is an int
		textureRect is a list of size 4, determines which square to take from the texture
		drawRect is a list of size 4, is used to determine the drawing size
		'''

        glBindTexture(self.texext, texture)

        glPushMatrix()
        glTranslatef(dx + dw / 2, dy + dh / 2, 0)
        glRotatef(r, 0, 0, 1.0)
        glTranslatef(-1 * (dx + dw / 2), -1 * (dy + dh / 2), 0)

        glBegin(GL_QUADS)
        #Top-left vertex (corner)
        glTexCoord2f(x, y + h)  #image/texture
        glVertex3f(dx, dy, 0)  #screen coordinates

        #Bottom-left vertex (corner)
        glTexCoord2f(x + w, y + h)
        glVertex3f((dx + dw), dy, 0)

        #Bottom-right vertex (corner)
        glTexCoord2f(x + w, y)
        glVertex3f((dx + dw), (dy + dh), 0)

        #Top-right vertex (corner)
        glTexCoord2f(x, y)
        glVertex3f(dx, (dy + dh), 0)
        glEnd()

        glPopMatrix()
Beispiel #21
0
def draw_lines_3d(lines, color, draw_origin, draw_angles, line_width=2):
    gl.glLoadIdentity()  # reset position
    gl.glTranslatef(*draw_origin)
    #origin of plotting
    gl.glRotatef(draw_angles[1], 1, 0, 0)
    gl.glRotatef(draw_angles[0], 0, 1, 0)

    gl.glColor3f(*color)
    gl.glLineWidth(line_width)
    glBegin(GL_LINES)
    for line in lines:
        for point in line:
            glVertex3f(*point)
    glEnd()
Beispiel #22
0
def drawFullWindow(vtColors):
    """
    Draw gradient background color.

    <vtColors> is a 4 element list specifying colors for the
       left-down, right-down, right-up, left-up window corners.

    To draw the full window, the modelview and projection should be set in
    identity.
    """
    from utilities.constants import GL_FAR_Z
    glDisable(GL_LIGHTING)

    glBegin(GL_QUADS)
    glColor3fv(vtColors[0])
    glVertex3f(-1, -1, GL_FAR_Z)
    glColor3fv(vtColors[1])
    glVertex3f(1, -1, GL_FAR_Z)
    glColor3fv(vtColors[2])
    glVertex3f(1, 1, GL_FAR_Z)
    glColor3fv(vtColors[3])
    glVertex3f(-1, 1, GL_FAR_Z)
    glEnd()

    glEnable(GL_LIGHTING)
    return
Beispiel #23
0
    def _draw_zero_plane_xy(self, color, texture_id=None, scale=1.0):
        glPushMatrix()
        # glColor3f(*rgb_to_f(*color))
        apply_texture = texture_id is not None
        if apply_texture:
            glColor3f(1, 1, 1)
            glBindTexture(GL_TEXTURE_2D, self._textures[texture_id])
            glTexCoord2f(1.0 * scale, 0.0 * scale)
        else:
            glColor3f(*rgb_to_f(*color))
        glBegin(GL_POLYGON)
        size = self._size / 2

        glVertex3f(size, size, 0)
        if apply_texture:
            glTexCoord2f(1.0 * scale, 1.0 * scale)
        glVertex3f(size, -size, 0)
        if apply_texture:
            glTexCoord2f(0.0 * scale, 1.0 * scale)
        glVertex3f(-size, -size, 0)
        if apply_texture:
            glTexCoord2f(0.0 * scale, 0.0 * scale)
        glVertex3f(-size, size, 0)
        # if texture is not None:
        #     glBindTexture(GL_TEXTURE_2D, )
        glEnd()
        glPopMatrix()
Beispiel #24
0
def drawShadowMaps(lights, layerLoc):
    """
    draws shadow maps for debugging.
    note that a special shader is required to display the depth-component-only textures
    """
    
    i = 0
    for light in lights:
        if light.shadowMapArray==None: continue
        shadowMapArray = light.shadowMapArray
        shadowMaps = shadowMapArray.shadowMaps
        
        glBindTexture( GL_TEXTURE_2D_ARRAY, shadowMapArray.texture.glID )
        glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE )
        
        for j in range(len(shadowMaps)):
            glViewport(130*i, 0, 128, 128)
            
            glUniform1f(layerLoc, float(j))
            
            glBegin(GL_QUADS)
            glVertex3f(-1.0, -1.0, 0.0)
            glVertex3f( 1.0, -1.0, 0.0)
            glVertex3f( 1.0,  1.0, 0.0)
            glVertex3f(-1.0,  1.0, 0.0)
            glEnd()
            
            i += 1
        
        if shadowMapArray.textureType=="sampler2DArrayShadow":
            glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE )
        else:
            glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE )
Beispiel #25
0
def drawFullWindow(vtColors):
    """
    Draw gradient background color.

    <vtColors> is a 4 element list specifying colors for the  
       left-down, right-down, right-up, left-up window corners.

    To draw the full window, the modelview and projection should be set in
    identity.
    """
    from utilities.constants import GL_FAR_Z
    glDisable(GL_LIGHTING)

    glBegin(GL_QUADS)
    glColor3fv(vtColors[0])
    glVertex3f(-1, -1, GL_FAR_Z)
    glColor3fv(vtColors[1])            
    glVertex3f(1, -1, GL_FAR_Z)
    glColor3fv(vtColors[2])
    glVertex3f(1, 1, GL_FAR_Z)
    glColor3fv(vtColors[3])
    glVertex3f(-1, 1, GL_FAR_Z)
    glEnd()

    glEnable(GL_LIGHTING)
    return
Beispiel #26
0
 def drawActivePlace(self):
     if self.placeMode:
         if len(self.place_footprint) <= 2:
             glPushMatrix()
             glColor3f(*color_map["yellow"])
             glBegin(GL_LINES)
             for (x, y, z) in self.place_footprint:
                 glVertex3f(x, y, z)
                 glVertex3f(x, y, z + self.placeHeight)
             glEnd()
             glPopMatrix()
         else:
             place = self.makePlace()
             self.drawPrism(place.prism, color="yellow")
 def render_border(self):
     from OpenGL.GL import glColor3f, glLineWidth, glBegin, glEnd, glVertex3f, GL_LINE_LOOP
     for border_loop in self.border_loop_list:
         scale = 1.001
         glColor3f(0.0, 0.0, 0.0)
         glLineWidth(4.0)
         glBegin(GL_LINE_LOOP)
         try:
             for i in border_loop:
                 point = self.vertex_list[i].clone()
                 point *= scale      # This idea won't work in all cases.
                 glVertex3f(point.x, point.y, point.z)
         finally:
             glEnd()
Beispiel #28
0
    def draw(self, time, line_width=None):
        if self.hidden:
            return
        time = time * 1e-9
        if time <= self.time:
            return

        pos_start = self.pos + (self.speed * (-self.time) * self.dir)
        path = self.speed * (time - self.time) * self.dir
        if self.length:
            max_path = self.length * self.dir
            if np.linalg.norm(max_path) <= np.linalg.norm(path):
                path = max_path
        pos_end = self.pos + path

        glPushMatrix()
        if line_width:
            glLineWidth(line_width)
        else:
            glLineWidth(self.line_width)
        glColor3f(*self.color)
        glBegin(GL_LINES)
        glVertex3f(*pos_start)
        glVertex3f(*pos_end)
        glEnd()
        glPopMatrix()

        if self.cherenkov_cone_enabled and self.colourist.cherenkov_cone_enabled:

            height = np.linalg.norm(pos_end - pos_start)
            position = pos_end - self.dir * height

            glEnable(GL_LIGHTING)
            glEnable(GL_DEPTH_TEST)
            glShadeModel(GL_FLAT)
            glColor4f(0.0, 0.0, 0.8, 0.3)

            glPushMatrix()
            glTranslated(*position)
            glPushMatrix()

            v = np.array(self.dir)
            glMultMatrixf(transform(v))

            glutSolidCone(0.6691 * height, height, 128, 64)
            glPopMatrix()
            glPopMatrix()

            glDisable(GL_LIGHTING)
Beispiel #29
0
    def _render_points(cls, point_list: List[Vector3], size: float, color: List[float]):
        """Draws a collection of points in the OpenGL 3D worldspace.

        This function must be invoked inside the OpenGL render loop.

        :param point_list: the points to render in the view context
        :param size: the size in pixels of each point
        :param color: the color to render the points
        """
        glPointSize(size)
        cls._set_color(color)
        glBegin(GL_POINTS)
        for point in point_list:
            glVertex3f(point.x, point.y, point.z)
        glEnd()
Beispiel #30
0
def draw_points_3d(points, color, draw_origin, draw_angles, line_width=2):
    gl.glLoadIdentity()  # reset position
    gl.glTranslatef(*draw_origin)
    #origin of plotting
    gl.glRotatef(draw_angles[1], 1, 0, 0)
    gl.glRotatef(draw_angles[0], 0, 1, 0)

    glColor3f(*color)
    #draw each point as a line with (almost) identical start and end points
    glLineWidth(line_width)
    for point in points:
        glBegin(GL_LINES)
        glVertex3f(*point)
        glVertex3f(*(point + vec.Vec([0.01, 0, 0])))
        glEnd()
Beispiel #31
0
 def _rectangle(self, r1, r2):
     glColor(1, 1, 1)
     glLineWidth(1)
     glBegin(GL_LINE_LOOP)
     glVertex3f(r1[0], r1[1], 0.0)
     glVertex3f(r2[0], r1[1], 0.0)
     glVertex3f(r2[0], r2[1], 0.0)
     glVertex3f(r1[0], r2[1], 0.0)
     glEnd()
Beispiel #32
0
 def _draw_yz_edge(self, color):
     glBegin(GL_POLYGON)
     glColor3f(*rgb_to_f(*color))
     size = self._size / 2
     glVertex3f(size, size, 0.)
     glVertex3f(size, -size, 0.)
     glVertex3f(-size, -size, 0.)
     glVertex3f(-size, size, 0.)
     glEnd()
Beispiel #33
0
 def _rectangle(self, r1, r2):
     glColor(1, 1, 1)
     glLineWidth(1)
     glBegin(GL_LINE_LOOP)
     glVertex3f(r1[0], r1[1], 0.0)
     glVertex3f(r2[0], r1[1], 0.0)
     glVertex3f(r2[0], r2[1], 0.0)
     glVertex3f(r1[0], r2[1], 0.0)
     glEnd()
Beispiel #34
0
def make_cube():
    glNewList(G_OBJ_CUBE, GL_COMPILE)
    vertices = [((-0.5, -0.5, -0.5), (-0.5, -0.5, 0.5), (-0.5, 0.5, 0.5), (-0.5, 0.5, -0.5)),
                ((-0.5, -0.5, -0.5), (-0.5, 0.5, -0.5), (0.5, 0.5, -0.5), (0.5, -0.5, -0.5)),
                ((0.5, -0.5, -0.5), (0.5, 0.5, -0.5), (0.5, 0.5, 0.5), (0.5, -0.5, 0.5)),
                ((-0.5, -0.5, 0.5), (0.5, -0.5, 0.5), (0.5, 0.5, 0.5), (-0.5, 0.5, 0.5)),
                ((-0.5, -0.5, 0.5), (-0.5, -0.5, -0.5), (0.5, -0.5, -0.5), (0.5, -0.5, 0.5)),
                ((-0.5, 0.5, -0.5), (-0.5, 0.5, 0.5), (0.5, 0.5, 0.5), (0.5, 0.5, -0.5))]
    normals = [(-1.0, 0.0, 0.0), (0.0, 0.0, -1.0), (1.0, 0.0, 0.0), (0.0, 0.0, 1.0), (0.0, -1.0, 0.0), (0.0, 1.0, 0.0)]

    glBegin(GL_QUADS)
    for i in xrange(6):
        glNormal3f(normals[i][0], normals[i][1], normals[i][2])
        for j in xrange(4):
            glVertex3f(vertices[i][j][0], vertices[i][j][1], vertices[i][j][2])
    glEnd()
    glEndList()
    def _render_circle(cls, center: Vector3, radius: float, sections: int,
                       color: List[float]):
        """Draws a circle out of dashed lines around a center point in the x-y plane.

        This function must be invoked inside the OpenGL render loop.

        :param center: the center point of the rendered circle
        :param radius: the size of the rendered circle
        :param sections: the number of vertices used in the dashed line circle
        :param color: the color to render the points
        """
        cls._set_color(color)
        glBegin(GL_LINES)
        for i in range(sections):
            theta = pi * 2.0 * float(i) / float(sections - 1)
            glVertex3f(center.x + cos(theta) * radius,
                       center.y + sin(theta) * radius, center.z)
        glEnd()
Beispiel #36
0
 def _draw_zero_plane_xy(self, color):
     glPushMatrix()
     glColor3f(*rgb_to_f(*color))
     glBegin(GL_POLYGON)
     size = self._size / 2
     glVertex3f(size, size, 0)
     glVertex3f(size, -size, 0)
     glVertex3f(-size, -size, 0)
     glVertex3f(-size, size, 0)
     glEnd()
     glPopMatrix()
Beispiel #37
0
def draw_path(a_path):
    """ draws a path with opengl lines.
    """

    glBegin(GL_LINES)
    try:
        last = 0

        for x, y, z in a_path.points:
            if last:

                glVertex3f(lx, ly, lz)
                glVertex3f(x, y, z)
                lx, ly, lz = x, y, z
            else:
                last = 1
                lx, ly, lz = x, y, z
    finally:
        glEnd()
Beispiel #38
0
def make_mesh():
    glNewList(G_OBJ_MESH,GL_COMPILE)
    vertices=[[1.0,0.0,1.0],[0.0,0.0,-1.0],[-1.0,0.0,1.0],[0.0,1.0,0.0]]
    face=[[1,4,3],[1,2,4],[2,3,4],[1,3,2]]
    for i in range(len(face)):
        glColor3f(216/255,186/255,160/255)
        point0=np.array(vertices[face[i][0]-1])
        point1 = np.array(vertices[face[i][1]-1])
        point2 =np.array(vertices[face[i][2]-1])
        A=point1-point0
        B=point0-point2
        C = np.cross(B, A)
        N = C/np.linalg.norm(C)
        glBegin(GL_TRIANGLES)
        glNormal3f(N[0],N[1],N[2])
        for j in range(3):
            glVertex3f(vertices[face[i][j]-1][0],vertices[face[i][j]-1][1],vertices[face[i][j]-1][2])
        glEnd()
    glEndList()
Beispiel #39
0
    def draw(self, time, line_width=None):
        if self.hidden:
            return
        time = time * 1e-9

        pos_start = self.start_pos + (constants.c * (-self.time) * self.dir)
        if time >= self.time:
            pos_end = self.pos
        else:
            path = constants.c * (time - self.time) * self.dir
            pos_end = self.pos + path

        glPushMatrix()
        glLineWidth(self.line_width)
        glColor3f(*self.color)
        glBegin(GL_LINES)
        glVertex3f(*pos_start)
        glVertex3f(*pos_end)
        glEnd()
        glPopMatrix()
Beispiel #40
0
def draw_path(a_path):
    """ draws a path with opengl lines.
    """


    glBegin(GL_LINES)
    try:
	last = 0

	for x,y,z in a_path.points:
	    if last:
		
		glVertex3f(lx,ly,lz)
		glVertex3f(x,y,z)
		lx, ly, lz = x,y,z
	    else:
		last = 1
		lx, ly, lz = x,y,z
    finally:
	glEnd()
Beispiel #41
0
    def draw_tool_chain(self):
        font_scale = 0.00015
        glMatrixMode(GL_MODELVIEW)

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

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

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

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

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

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

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

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

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

        glColor(1, 1, 1)
        glLineWidth(1)
        for index, point in enumerate(self.points[:num]):
            glPushMatrix()
            glTranslate(point[0], point[1], 0.0)
            glScaled(font_scale, font_scale, 1)
            glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, ord(str(index + 1)))
            glPopMatrix()
    def _draw(self):
        if self._cross is None:
            return

        glLineWidth(3.0)
        glBegin(GL_LINES)

        glColor3f(1.0, 0.0, 0.0)
        glVertex3f(self._cross[0] - 20, self._cross[1] - 20, 10)
        glVertex3f(self._cross[0] + 20, self._cross[1] + 20, 10)
        glVertex3f(self._cross[0] - 20, self._cross[1] + 20, 10)
        glVertex3f(self._cross[0] + 20, self._cross[1] - 20, 10)

        glEnd()
  def show_geometry():
    glNewList(1, GL_COMPILE)
    glBegin(GL_TRIANGLES)
    glColor3f(1, 1, 1)

    vnum = dm.np_get_vertices(np_verts)
    tnum = dm.np_get_triangles_vertices(np_tris)
    dm.np_get_triangles_intensity(np_int)
    move_scale(np_verts[:vnum, :])

    coords = np_verts[np_tris[:tnum, :], :]
    mi = coords[:, :, 0].min(axis=0)
    ma = coords[:, :, 0].max(axis=0)

    for f, vv in enumerate(coords):
      v1 = vv[2, :] - vv[0, :]
      v2 = vv[1, :] - vv[0, :]
      n = cross(v2, v1).squeeze()
      n /= norm(n)
      glNormal3f(*n)
      c = np_int[f]
      glColor3f(c, c, c)
      glVertex3f(*vv[0, :].squeeze())
      glVertex3f(*vv[1, :].squeeze())
      glVertex3f(*vv[2, :].squeeze())

    glEnd()
    glEndList()
    return concatenate((mi, ma))
Beispiel #45
0
 def render_slowly(self):
     self.n_tris = 0
     self.n_lines = 0
     for path, stroke, tris, fill, transform in self.paths:
         if tris:
             self.n_tris += len(tris)/3
             if isinstance(fill, str):
                 g = self.gradients[fill]
                 fills = [g.interp(x) for x in tris]
             else:
                 fills = [fill for x in tris]
             #pyglet.graphics.draw(len(tris), GL_TRIANGLES,
             #                     ('v3f', sum((x + [0] for x in tris), [])),
             #                     ('c3B', sum(fills, [])))
             glBegin(GL_TRIANGLES)
             for vtx, clr in zip(tris, fills):
                 vtx = transform(vtx)
                 glColor4ub(*clr)
                 glVertex3f(vtx[0], vtx[1], 0)
             glEnd()
         if path:
             for loop in path:
                 self.n_lines += len(loop) - 1
                 loop_plus = []
                 for i in xrange(len(loop) - 1):
                     loop_plus += [loop[i], loop[i+1]]
                 if isinstance(stroke, str):
                     g = self.gradients[stroke]
                     strokes = [g.interp(x) for x in loop_plus]
                 else:
                     strokes = [stroke for x in loop_plus]
                 #pyglet.graphics.draw(len(loop_plus), GL_LINES,
                 #                     ('v3f', sum((x + [0] for x in loop_plus), [])),
                 #                     ('c3B', sum((stroke for x in loop_plus), [])))
                 glBegin(GL_LINES)
                 for vtx, clr in zip(loop_plus, strokes):
                     vtx = transform(vtx)
                     glColor4ub(*clr)
                     glVertex3f(vtx[0], vtx[1], 0)
                 glEnd()
Beispiel #46
0
	def _drawQuad(self, tex_offset):
		extent = self.extent
		y = self.seaLevel
		max_tex = 50.0+tex_offset
		glBegin(GL_QUADS)
		glTexCoord2f( 0.0+tex_offset, 0.0+tex_offset )
		glVertex3f( 0.0, y, 0.0 )
		glTexCoord2f( max_tex, 0.0+tex_offset )
		glVertex3f( extent, y, 0.0 )
		glTexCoord2f( max_tex, max_tex )
		glVertex3f( extent, y, extent )
		glTexCoord2f( 0.0+tex_offset, max_tex )
		glVertex3f( 0.0, y, extent )
		glEnd()
Beispiel #47
0
 def _drawQuad(self, tex_offset):
     extent = self.extent
     y = self.seaLevel
     max_tex = 50.0 + tex_offset
     glBegin(GL_QUADS)
     glTexCoord2f(0.0 + tex_offset, 0.0 + tex_offset)
     glVertex3f(0.0, y, 0.0)
     glTexCoord2f(max_tex, 0.0 + tex_offset)
     glVertex3f(extent, y, 0.0)
     glTexCoord2f(max_tex, max_tex)
     glVertex3f(extent, y, extent)
     glTexCoord2f(0.0 + tex_offset, max_tex)
     glVertex3f(0.0, y, extent)
     glEnd()
Beispiel #48
0
    def paint(self):
        super(Box, self).paint()

        l = self.length
        wh = self.width / 2.0
        # h = self.height

        p = [
            [0, wh, 0],
            [l, wh, 0],
            [l, -wh, 0],
            [0, -wh, 0],
            [0, wh, 1],
            [l, wh, 1],
            [l, -wh, 1],
            [0, -wh, 1],
        ]

        m = [
            [0, 1, 0, 1, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 1, 0, 0],
            [0, 0, 0, 1, 0, 0, 1, 0],
            [0, 0, 0, 0, 0, 0, 0, 1],
            [0, 0, 0, 0, 0, 1, 0, 1],
            [0, 0, 0, 0, 0, 0, 1, 0],
            [0, 0, 0, 0, 0, 0, 0, 1],
            [0, 0, 0, 0, 0, 0, 0, 0],
        ]

        glLineWidth(2.0)
        glBegin(GL_LINES)  # lgtm [py/call/wrong-arguments]

        glColor4f(1, 0, 0, 1)
        for k in range(8):
            for j in range(k + 1, 8):
                if m[k][j] == 1:
                    glVertex3f(*p[k])
                    glVertex3f(*p[j])

        glEnd()  # lgtm [py/call/wrong-arguments]
Beispiel #49
0
 def render_slowly(self):
     self.n_tris = 0
     self.n_lines = 0
     for path, stroke, tris, fill, transform in self.paths:
         if tris:
             self.n_tris += len(tris) / 3
             if isinstance(fill, str):
                 g = self.gradients[fill]
                 fills = [g.interp(x) for x in tris]
             else:
                 fills = [fill for x in tris]
             #pyglet.graphics.draw(len(tris), GL_TRIANGLES,
             #                     ('v3f', sum((x + [0] for x in tris), [])),
             #                     ('c3B', sum(fills, [])))
             glBegin(GL_TRIANGLES)
             for vtx, clr in zip(tris, fills):
                 vtx = transform(vtx)
                 glColor4ub(*clr)
                 glVertex3f(vtx[0], vtx[1], 0)
             glEnd()
         if path:
             for loop in path:
                 self.n_lines += len(loop) - 1
                 loop_plus = []
                 for i in xrange(len(loop) - 1):
                     loop_plus += [loop[i], loop[i + 1]]
                 if isinstance(stroke, str):
                     g = self.gradients[stroke]
                     strokes = [g.interp(x) for x in loop_plus]
                 else:
                     strokes = [stroke for x in loop_plus]
                 #pyglet.graphics.draw(len(loop_plus), GL_LINES,
                 #                     ('v3f', sum((x + [0] for x in loop_plus), [])),
                 #                     ('c3B', sum((stroke for x in loop_plus), [])))
                 glBegin(GL_LINES)
                 for vtx, clr in zip(loop_plus, strokes):
                     vtx = transform(vtx)
                     glColor4ub(*clr)
                     glVertex3f(vtx[0], vtx[1], 0)
                 glEnd()
Beispiel #50
0
    def orthogonalPass(self, debugShadows=False):
        """
        draw stuff in orthogonal projection.
        mainly the scene can be post processed here
        and some gui elements could be drawn.
        """

        ### DRAW THE SCENE ###

        # TODO: post shader magic !
        glUseProgram(0)

        # enable the scene texture
        # Note that texture unit 0 should be active now.
        glEnable(GL_TEXTURE_2D)
        glBindTexture(GL_TEXTURE_2D, self.sceneTexture.glID)
        # make sure texture matrix is set to identity
        glMatrixMode(GL_TEXTURE)
        glLoadIdentity()
        glMatrixMode(GL_MODELVIEW)

        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0)
        glVertex3f(0.0, 0.0, -1.0)
        glTexCoord2f(1.0, 0.0)
        glVertex3f(self.winSize[0], 0.0, -1.0)
        glTexCoord2f(1.0, 1.0)
        glVertex3f(self.winSize[0], self.winSize[1], -1.0)
        glTexCoord2f(0.0, 1.0)
        glVertex3f(0.0, self.winSize[1], -1.0)
        glEnd()

        ### DEBUG DRAWINGS ###

        # debug shadow maps
        if debugShadows:
            # draw the shadow maps
            self.visualizeDepthShader.enable()
            layerLoc = glGetUniformLocation(self.visualizeDepthShader.program, "layer")
            drawShadowMaps(self.lights, layerLoc)

            # reset viewport and reset to ffp
            glViewport(0, 0, self.winSize[0], self.winSize[1])
            glUseProgram(0)

        glBindTexture(GL_TEXTURE_2D, 0)
        glDisable(GL_TEXTURE_2D)

        GLApp.orthogonalPass(self)
Beispiel #51
0
def draw_circle_3d(radius,
                   axes,
                   color,
                   draw_origin,
                   draw_angles,
                   n_points=30,
                   line_width=2):
    gl.glLoadIdentity()  # reset position
    gl.glTranslatef(*draw_origin)
    #origin of plotting
    gl.glRotatef(draw_angles[1], 1, 0, 0)
    gl.glRotatef(draw_angles[0], 0, 1, 0)
    glColor3f(*color)
    glLineWidth(line_width)
    glBegin(GL_LINE_LOOP)
    for i in range(n_points):
        x = math.cos(math.pi * 2 * i / n_points) * radius
        y = math.sin(math.pi * 2 * i / n_points) * radius
        p = vec.zero_vec(3)
        p[axes[0]] = x
        p[axes[1]] = y
        glVertex3f(*p)
    glEnd()
Beispiel #52
0
 def renderizar_cuad(self, x, y, ancho, alto):
     """Renderiza un cuadrado, se ingresan coordenadas para
     textura por defecto.
     x, y = posición (superior izquierda) del cuadrado
     ancho, alto = tamaño del cuadrado"""
     glBegin(GL_QUADS)
     # Arriba-Izquierda
     glTexCoord2f(0.0, 1.0)
     glVertex3f(x, y, 0.0)
     # Abajo-Izquirda
     glTexCoord2f(0.0, 0.0)
     glVertex3f(x, alto, 0.0)
     # Abajo-Derecha
     glTexCoord2f(1.0, 0.0)
     glVertex3f(ancho, alto, 0.0)
     # Arriba-Derecha
     glTexCoord2f(1.0, 1.0)
     glVertex3f(ancho, y, 0.0)
     glEnd()
Beispiel #53
0
    def openglSetup(self):
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glEnable(GL.GL_DEPTH_TEST) 
        glEnable(GL.GL_COLOR_MATERIAL)

        glViewport (0, 0, self.surf.get_width(), self.surf.get_height())
        glMatrixMode (GL.GL_PROJECTION)
        glLoadIdentity ()
        glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
        glMatrixMode (GL.GL_MODELVIEW)

        self.cardList = glGenLists(1)
        glNewList(self.cardList, GL.GL_COMPILE)
        glColor3f(1,1,1)
        with begin(GL.GL_QUADS):
            glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, -1.0,  0.0)
            glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, -1.0,  0.0)
            glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, 1.0,  0.0)
            glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, 1.0,  0.0)
        glEndList()
    def draw(self, resolution_meter, position, orientation,yaw):

        try:
            self._lock.acquire()
            vehicle_position = (
                position[0] * resolution_meter, position[1] * resolution_meter,
                position[2] * resolution_meter)
            glTranslatef(vehicle_position[0],vehicle_position[1],vehicle_position[2])  # Translate Box

            matrix = quaternion_matrix(orientation)  # convert quaternion to translation matrix
            glMultMatrixf(matrix)  # Rotate Box

            glBegin(GL_TRIANGLES)
            glColor3f(0.0078, 0.2588, 0.39607)
            for tri in self.get_triangles():
                glNormal3f(tri.normal.x, tri.normal.z, tri.normal.y)
                glVertex3f((tri.points[0].x - self.vehicle_size_y) * resolution_meter,
                           (tri.points[0].z - self.vehicle_size_x) * resolution_meter,
                           (tri.points[0].y - self.vehicle_size_z) * resolution_meter)
                glVertex3f((tri.points[1].x - self.vehicle_size_y) * resolution_meter,
                           (tri.points[1].z - self.vehicle_size_x) * resolution_meter,
                           (tri.points[1].y - self.vehicle_size_z) * resolution_meter)
                glVertex3f((tri.points[2].x - self.vehicle_size_y) * resolution_meter,
                           (tri.points[2].z - self.vehicle_size_x) * resolution_meter,
                           (tri.points[2].y - self.vehicle_size_z) * resolution_meter)
            glEnd()

            if self._lock_on_sub:
                modelview_matrix = self.gl_view.get_view_matrix()
                modelview_matrix[3] = [vehicle_position[0] * -1 , vehicle_position[1] * -1, modelview_matrix[3][2], modelview_matrix[3][3]]
                self.gl_view.load_view_matrix(modelview_matrix)

            if self._lock_rotate:
                self.gl_view.rotate_absolute((0,0,1),yaw)
        finally:
                self._lock.release()
Beispiel #55
0
    def initializeGL(self):
        glClearColor(0.85, 0.85, 0.85, 1.0)
        glClearDepth(1.0)
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        glShadeModel(GL_SMOOTH)
        glEnable(GL_NORMALIZE)
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)
        glLightfv(GL_LIGHT0, GL_POSITION, (0.0, 0.0, 1.0, 0.0))
        glEnable(GL_LIGHT0)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        self.display_list = glGenLists(1)
        glNewList(self.display_list, GL_COMPILE)
        glScalef(0.5, 0.5, 0.5)

        glEnable(GL_LIGHTING)

        # board
        glColor3f(0.0, 0.0, 0.0)
        self.draw_cuboid(4.0, 4.0, 0.16)

        # USB connector
        glPushMatrix()
        glColor3f(0.5, 0.51, 0.58)
        glTranslatef(0.0, -1.6, 0.28)
        self.draw_cuboid(0.75, 0.9, 0.4)
        glPopMatrix()

        # right button
        glPushMatrix()
        glColor3f(0.5, 0.51, 0.58)
        glTranslatef(1.15, -1.85, 0.16)
        self.draw_cuboid(0.4, 0.3, 0.16)
        glColor3f(0.0, 0.0, 0.0)
        glTranslatef(0.0, -0.155, 0.025)
        self.draw_cuboid(0.18, 0.1, 0.08)
        glPopMatrix()

        # left button
        glPushMatrix()
        glColor3f(0.5, 0.51, 0.58)
        glTranslatef(-1.15, -1.85, 0.16)
        self.draw_cuboid(0.4, 0.3, 0.16)
        glColor3f(0.0, 0.0, 0.0)
        glTranslatef(0.0, -0.155, 0.025)
        self.draw_cuboid(0.18, 0.1, 0.08)
        glPopMatrix()

        # left btb top
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(-1.65, 0.0, 0.38)
        self.draw_cuboid(0.5, 1.4, 0.9)
        glPopMatrix()

        # right btb top
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(1.65, 0.0, 0.38)
        self.draw_cuboid(0.5, 1.4, 0.9)
        glPopMatrix()

        # left btb bottom
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(-1.65, 0.0, -0.33)
        self.draw_cuboid(0.5, 1.4, 0.5)
        glPopMatrix()

        # right btb bottom
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(1.65, 0.0, -0.33)
        self.draw_cuboid(0.5, 1.4, 0.5)
        glPopMatrix()

        # left bricklet port
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(-0.85, 1.8, -0.23)
        self.draw_cuboid(1.2, 0.4, 0.3)
        glPopMatrix()

        # right bricklet port
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(0.85, 1.8, -0.23)
        self.draw_cuboid(1.2, 0.4, 0.3)
        glPopMatrix()

        # left direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-1.05, 1.425, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # top direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-0.675, 1.8, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # right direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-0.3, 1.425, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # bottom direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-0.675, 1.05, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # left y orientation LED
        glPushMatrix()
        glColor3f(0.0, 0.0, 1.0)
        glTranslatef(0.275, 1.7, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # right y orientation LED
        glPushMatrix()
        glColor3f(1.0, 0.0, 0.0)
        glTranslatef(0.425, 1.7, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # top z orientation LED
        glPushMatrix()
        glColor3f(1.0, 0.0, 0.0)
        glTranslatef(0.35, 1.15, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # bottom z orientation LED
        glPushMatrix()
        glColor3f(0.0, 0.0, 1.0)
        glTranslatef(0.35, 1.0, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # top x orientation LED
        glPushMatrix()
        glColor3f(1.0, 0.0, 0.0)
        glTranslatef(1.0, 1.15, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # bottom x orientation LED
        glPushMatrix()
        glColor3f(0.0, 0.0, 1.0)
        glTranslatef(1.0, 1.0, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # top alignment corner
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glBegin(GL_TRIANGLES)
        glNormal3f(0.0, 0.0, 1.0)
        glVertex3f(-2.0, -2.0, 0.09)
        glVertex3f(-1.1, -2.0, 0.09)
        glVertex3f(-2.0, -1.1, 0.09)
        glEnd()
        glPopMatrix()

        # bottom alignment corner
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glBegin(GL_TRIANGLES)
        glNormal3f(0.0, 0.0, -1.0)
        glVertex3f(-2.0, -2.0, -0.09)
        glVertex3f(-2.0, -1.1, -0.09)
        glVertex3f(-1.1, -2.0, -0.09)
        glEnd()
        glPopMatrix()

        glDisable(GL_LIGHTING)

        # axis
        glPushMatrix()
        glTranslatef(-2.3, -2.3, -0.38)
        glLineWidth(3.0)
        glBegin(GL_LINES)
        glColor3f(1,0,0) # x axis is red
        glVertex3f(0,0,0)
        glVertex3f(3,0,0)
        glColor3f(0,0.5,0) # y axis is green
        glVertex3f(0,0,0)
        glVertex3f(0,3,0)
        glColor3f(0,0,1) # z axis is blue
        glVertex3f(0,0,0)
        glVertex3f(0,0,3)
        glEnd()
        glLineWidth(1.0)
        glPopMatrix()

        glEndList()
    def _draw(self):
        glLineWidth(4.0)

        glBegin(GL_LINES)

        glColor3f(0.5, 0.5, 0.5)
        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(50.0, 0.0, 1.0)

        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(0.0, 50.0, 1.0)

        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(0.0, 0.0, 50.0)

        glEnd()
def drawGPGrid(glpane, color, line_type, w, h, uw, uh, up, right):
    """
    Draw grid lines for a Grid Plane.
    
    glpane = the glpane
    color = grid line and unit text color
    line_type is: 0=None, 1=Solid, 2=Dashed or 3=Dotted
    w = width
    h = height
    uw = width spacing between grid lines
    uh = height spacing between grid lines
    """
    
    if line_type == NO_LINE:
        return

    if uw > w: uw = w
    if uh > h: uh = h

    Z_OFF = 0.0 #0.001
    
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    
    hw = w/2.0; hh = h/2.0

    #glEnable(GL_LINE_SMOOTH)
    #glEnable(GL_BLEND)
    #glBlendFunc(GL_SRC_ALPHA, GL_ONE)#_MINUS_SRC_ALPHA)
    
    if line_type > 1:
        glEnable(GL_LINE_STIPPLE)
        if line_type == DASHED_LINE:
            glLineStipple (1, 0x00FF)  #  dashed
        elif line_type == DOTTED_LINE:
            glLineStipple (1, 0x0101)  #  dotted
        else:
            print "drawGPGrid(): line_type '", line_type, \
                  "' is not valid.  Drawing dashed grid line."
            glLineStipple (1, 0x00FF)  #  dashed
    
    glBegin(GL_LINES)

    #Draw horizontal lines
    y1 = 0
    while y1 > -hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 -= uh

    y1 = 0
    while y1 < hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 += uh

    #Draw vertical lines
    x1 = 0
    while x1 < hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 += uw

    x1 = 0
    while x1 > -hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 -= uw

    glEnd()

    if line_type > 1:
        glDisable (GL_LINE_STIPPLE)
    
    # Draw unit labels for gridlines (in nm).
    text_color = color
    
    import sys
    if sys.platform == "darwin":
        # WARNING: Anything smaller than 9 pt on Mac OS X results in 
        # un-rendered text. Not sure why. -- piotr 080616
        font_size = 9
    else:
        font_size = 8
        
    text_offset = 0.5 # Offset from edge of border, in Angstroms.
    
    
    # Draw unit text labels for horizontal lines (nm)
    y1 = 0
    while y1 > -hh:
        y1 -= uh
        drawtext("%g" % (-y1 / 10.0), text_color,
                 V(hw + text_offset, y1, 0.0), font_size, glpane)
    drawtext("%g" % (-y1 / 10.0), text_color,
             V(hw + text_offset, y1, 0.0), font_size, glpane)

    y1 = 0
    while y1 < hh:
        drawtext("%g" % (-y1 / 10.0), text_color,
                 V(hw + text_offset, y1, 0.0), font_size, glpane)
        y1 += uh
    drawtext("%g" % (-y1 / 10.0), text_color,
             V(hw + text_offset, y1, 0.0), font_size, glpane)

    # Draw unit text labels for vertical lines (nm).
    x1 = 0
    while x1 < hw:
        drawtext("%g" % (x1 / 10.0), text_color,
                 V(x1, hh + text_offset, 0.0), font_size, glpane)
        x1 += uw
    drawtext("%g" % (x1 / 10.0), text_color,
             V(x1, hh + text_offset, 0.0), font_size, glpane)

    x1 = 0
    while x1 > -hw:
        drawtext("%g" % (x1 / 10.0), text_color,
                 V(x1, hh + text_offset, 0.0), font_size, glpane)
        x1 -= uw
    drawtext("%g" % (x1 / 10.0), text_color,
             V(x1, hh + text_offset, 0.0), font_size, glpane)
    
    glEnable(GL_LIGHTING)
    return
def drawGPGridForPlane(glpane, color, line_type, w, h, uw, uh, up, right, 
                       displayLabels, originLocation, labelsDisplayStyle):
    """
    Draw grid lines for a Grid from Plane PM.
    
    glpane = the glpane
    color = grid line and unit text color
    line_type is: 0=None, 1=Solid, 2=Dashed, or 3=Dotted
    w = width
    h = height
    uw = width spacing between grid lines
    uh = height spacing between grid lines
    """
    
    if line_type == NO_LINE:
        return

    if uw > w: uw = w
    if uh > h: uh = h

    Z_OFF = 0.0 #0.001
    
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    
    hw = w/2.0; hh = h/2.0

    if line_type > 1:
        glEnable(GL_LINE_STIPPLE)
        if line_type == DASHED_LINE:
            glLineStipple (1, 0x00FF)  #  dashed
        elif line_type == DOTTED_LINE:
            glLineStipple (1, 0x0101)  #  dotted
        else:
            print "drawGPGrid(): line_type '", line_type,"' is not valid. ", \
                  "Drawing dashed grid line."
            glLineStipple (1, 0x00FF)  #  dashed
    
    glBegin(GL_LINES)

    #Draw horizontal lines
    y1 = 0
    while y1 > -hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 -= uh

    y1 = 0
    while y1 < hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 += uh

    #Draw vertical lines
    x1 = 0
    while x1 < hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 += uw

    x1 = 0
    while x1 > -hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 -= uw

    glEnd()

    if line_type > 1:
        glDisable (GL_LINE_STIPPLE)
    
    # Draw unit labels for gridlines (in nm).
    text_color = color
    
    import sys
    if sys.platform == "darwin":
        # WARNING: Anything smaller than 9 pt on Mac OS X results in 
        # un-rendered text. Not sure why. -- piotr 080616
        font_size = 9
    else:
        font_size = 8
        
    text_offset = 0.3 # Offset from edge of border, in Angstroms.
    
    if displayLabels == True:
        if (originLocation == PLANE_ORIGIN_LOWER_LEFT and
            labelsDisplayStyle == LABELS_ALONG_ORIGIN):
            displayLabelsAlongOriginLowerLeft(h, w, hh, hw, uh, uw,
                text_offset, text_color, font_size, glpane)
        elif (originLocation == PLANE_ORIGIN_UPPER_LEFT and
              labelsDisplayStyle == LABELS_ALONG_ORIGIN):
            displayLabelsAlongOriginUpperLeft(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)
        elif (originLocation == PLANE_ORIGIN_UPPER_RIGHT and
              labelsDisplayStyle == LABELS_ALONG_ORIGIN):
            displayLabelsAlongOriginUpperRight(h, w, hh, hw, uh, uw, 
                text_offset, text_color,font_size, glpane)  
        elif (originLocation == PLANE_ORIGIN_LOWER_RIGHT and
              labelsDisplayStyle == LABELS_ALONG_ORIGIN):
            displayLabelsAlongOriginLowerRight(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)  
        elif (originLocation == PLANE_ORIGIN_LOWER_LEFT and
              labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES):
            displayLabelsAlongPlaneEdgesLowerLeft(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)
        elif (originLocation == PLANE_ORIGIN_UPPER_LEFT and
              labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES):
            displayLabelsAlongPlaneEdgesUpperLeft(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)  
        elif (originLocation == PLANE_ORIGIN_UPPER_RIGHT and
              labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES):
            displayLabelsAlongPlaneEdgesUpperRight(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)  
        elif (originLocation == PLANE_ORIGIN_LOWER_RIGHT and
              labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES):
            displayLabelsAlongPlaneEdgesLowerRight(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)  
        
    glEnable(GL_LIGHTING)
    return
Beispiel #59
0
 def draw(self, line_width=1, color=(1.0, 0.0, 0.0)):
     glEnable(GL_DEPTH_TEST)
     glEnable(GL_LINE_SMOOTH)
     glShadeModel(GL_FLAT)
     glPushMatrix()
     glLineWidth(line_width)
     glColor3f(*color)
     glBegin(GL_LINES)
     glVertex3f(-1.0, 0.0, 0.0)
     glVertex3f(1.0, 0.0, 0.0)
     glEnd()
     glPushMatrix()
     glTranslated(1.0, 0.0, 0.0)
     glRotated(90, 0.0, 1.0, 0.0)
     glutSolidCone(0.05, 0.2, 16, 16)
     glPopMatrix()
     glBegin(GL_LINES)
     glVertex3f(0.0, -1.0, 0.0)
     glVertex3f(0.0, 1.0, 0.0)
     glEnd()
     glPushMatrix()
     glTranslated(0.0, 1.0, 0.0)
     glRotated(-90, 1.0, 0.0, 0.0)
     glutSolidCone(0.05, 0.2, 16, 16)
     glPopMatrix()
     glBegin(GL_LINES)
     glVertex3f(0.0, 0.0, -1.0)
     glVertex3f(0.0, 0.0, 1.0)
     glEnd()
     glPushMatrix()
     glTranslated(0.0, 0.0, 1.0)
     glutSolidCone(0.05, 0.2, 16, 16)
     glPopMatrix()
     glPopMatrix()