예제 #1
0
    def render(self):
        """ renders the item to the screen """

        glPushMatrix()

        glMultMatrixf(numpy.transpose(self.translation_matrix))

        glMultMatrixf(self.scaling_matrix)

        glMultMatrixf(self.rotation_matrix)

        cur_color = color.COLORS[self.color_index]

        glColor3f(cur_color[0], cur_color[1], cur_color[2])

        if self.selected:  # emit light if the node is selected

            glMaterialfv(GL_FRONT, GL_EMISSION, [0.3, 0.3, 0.3])

        self.render_self()

        if self.selected:

            glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0])

        glPopMatrix()
예제 #2
0
파일: context3d.py 프로젝트: h2r/slu_core
    def drawGrid(self):

        grids_per_screen = 10
        eye_dist = self.camera_xyz[2]
        meters_per_grid = round_to_125(eye_dist / grids_per_screen)
        num_lines = 300

        glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_LINE_BIT)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_DEPTH_TEST)

        glPushMatrix()
        glTranslatef(0, 0, 0)
        glColor3f(0.2, 0.2, 0.2)
        glBegin(GL_LINES)

        for i in range(num_lines):
            glVertex2f((-num_lines / 2 + i) * meters_per_grid,
                       -num_lines / 2 * meters_per_grid)
            glVertex2f((-num_lines / 2 + i) * meters_per_grid,
                       num_lines / 2 * meters_per_grid)

            glVertex2f(-num_lines / 2 * meters_per_grid,
                       (-num_lines / 2 + i) * meters_per_grid)
            glVertex2f(num_lines / 2 * meters_per_grid,
                       (-num_lines / 2 + i) * meters_per_grid)

        glEnd()
        glPopMatrix()
        glPopAttrib()
예제 #3
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))
예제 #4
0
    def _paintGLGrid(self):
        resolutionMillimeters = 1
        griddedAreaSize = 100

        glLineWidth(1.0)

        glBegin(GL_LINES)

        glColor3f(1.0, 1.0, 1.0)

        glVertex3f(griddedAreaSize, 0, 0)
        glVertex3f(-griddedAreaSize, 0, 0)
        glVertex3f(0, griddedAreaSize, 0)
        glVertex3f(0, -griddedAreaSize, 0)

        numOfLines = int(griddedAreaSize / resolutionMillimeters)

        for i in range(numOfLines):
            glVertex3f(resolutionMillimeters * i, -griddedAreaSize, 0)
            glVertex3f(resolutionMillimeters * i, griddedAreaSize, 0)
            glVertex3f(griddedAreaSize, resolutionMillimeters * i, 0)
            glVertex3f(-griddedAreaSize, resolutionMillimeters * i, 0)

            glVertex3f(resolutionMillimeters * (-i), -griddedAreaSize, 0)
            glVertex3f(resolutionMillimeters * (-i), griddedAreaSize, 0)
            glVertex3f(griddedAreaSize, resolutionMillimeters * (-i), 0)
            glVertex3f(-griddedAreaSize, resolutionMillimeters * (-i), 0)

        glEnd()
예제 #5
0
 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()
예제 #6
0
    def draw_geometric2d(shape):
        """
        Draw a 2D shape, of type GeometricPrimitive
        """
        if shape.type == "POINTS":
            glBegin(GL_POINTS)
        elif shape.type == "LINES":
            glBegin(GL_LINES)
        elif shape.type == "LINE_STRIP":
            glBegin(GL_LINE_STRIP)
        elif shape.type == "LINE_LOOP":
            glBegin(GL_LINE_LOOP)
        elif shape.type == "POLYGON":
            glBegin(GL_POLYGON)
        elif shape.type == "TRIANGLES":
            glBegin(GL_TRIANGLES)
        elif shape.type == "TRIANGLE_STRIP":
            glBegin(GL_TRIANGLE_STRIP)
        elif shape.type == "TRIANGLE_FAN":
            glBegin(GL_TRIANGLE_FAN)
        elif shape.type == "QUADS":
            glBegin(GL_QUADS)
        elif shape.type == "QUAD_STRIP":
            glBegin(GL_QUAD_STRIP)
        else:
            logger.error("Invalid type for geometric primitive!")
            raise NameError

        # set color
        glColor3f(shape.color[0], shape.color[1], shape.color[2])

        # create vertices
        for vertex in shape.vertices:
            glVertex2f(vertex[0], vertex[1])
        glEnd()
예제 #7
0
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)
예제 #8
0
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)
예제 #9
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()
예제 #10
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()
예제 #11
0
파일: picwall.py 프로젝트: drewp/picwall
    def draw(self):
        t1 = time.time()
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        glLoadIdentity ()
        horizonY = 1 * 2.2 - .6 + .5
        GLU.gluLookAt(self.eyeX.x, horizonY, 8.0,
                      self.lookX.x, horizonY, 0.0,
                      0.0, 1.0, 0.0)

        glEnable(GL.GL_TEXTURE_2D)

        if 0:
            with pushMatrix():
                glColor3f(1,0,0)
                glTranslatef(*self.ball)
                glScalef(.2, .2, 1)
                imageCard("sample.jpg")

        with pushMatrix():
            with mode(disable=[GL.GL_LIGHTING]):
                for card in self.cards:
                    card.draw(self.eyeX.x, horizonY, self.cardList)

        glFlush()
        pygame.display.flip()
예제 #12
0
    def InitGL(self):
        glClearColor(0.0, 0.0, 0.0, 1)
        glColor3f(1, 0, 0)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_LIGHT1)

        glLightfv(GL_LIGHT0, GL_POSITION, vec(.5, .5, 1, 0))
        glLightfv(GL_LIGHT0, GL_SPECULAR, vec(.5, .5, 0.5, 1))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(1, 1, 1, 1))
        glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 0, .5, 0))
        glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.5, .5, .5, 1))
        glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1, 1, 1, 1))

        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
                     vec(0.5, 0, 0.3, 1))
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1))
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80)
        glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0.1, 0.1, 0.1, 0.9))

        glLightfv(GL_LIGHT0, GL_POSITION, vec(0.0, 200.0, 100.0, 1))
        glLightfv(GL_LIGHT1, GL_POSITION, vec(0.0, -200.0, 100.0, 1))
예제 #13
0
  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))
예제 #14
0
    def render(self, viewBox):
        if not self.intersectsBox(viewBox):
            return
        if self.shouldRefresh:
            self.refresh()
            self.shouldRefresh = False
        
        glColor3f(1, 1, 1)

        img = self.textureData
        pic_ny, pic_nx = img.shape
        tex_nx,tex_ny = getTexSize(pic_nx,pic_ny)
        picTexRatio_x = float(pic_nx) / tex_nx
        picTexRatio_y = float(pic_ny) / tex_ny

        (x,y) = self.pos[:2]

        glBindTexture(GL_TEXTURE_2D, self.texture)
        glBegin(GL_QUADS)
        glTexCoord2f(0, picTexRatio_y)
        glVertex2f(x, y)
        glTexCoord2f(picTexRatio_x, picTexRatio_y)
        glVertex2f(x + self.size[0], y)
        glTexCoord2f(picTexRatio_x, 0)
        glVertex2f(x + self.size[0], y + self.size[1])
        glTexCoord2f(0, 0)
        glVertex2f(x, y + self.size[1])
        glEnd()
예제 #15
0
    def render (self, mode=None):
        """Render Appearance, return (lit, textured, alpha, textureToken)

        Renders the appearance node, returning 3 status flags
        and a token which can be used to disable any enabled
        textures.
        
        Should only be called during visible rendering runs
        """
        if self.material:
            lit = 1
            alpha = self.material.render (mode=mode)
        else:
            lit = 0
            alpha = 1
            glColor3f( 1,1,1)
        textureToken = None
        if self.texture:
            textured = 1
            if self.texture.render( lit=lit, mode=mode ):
                if alpha==1.0:
                    alpha = .5
            if self.textureTransform:
                # only need this if we are textured
                textureToken = self.textureTransform.render (mode=mode)
        else:
            textured = 0
        return lit, textured, alpha, textureToken
예제 #16
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()
예제 #17
0
def draw_text_2d(text, x, y, line_height=17, color=None):
    """Draw a text at a given 2D position.

    A very basic 2D drawing function for drawing (multi-line) text."
    """
    width = glutGet(GLUT_WINDOW_WIDTH)
    height = glutGet(GLUT_WINDOW_HEIGHT)

    glMatrixMode(GL_PROJECTION)
    glPushMatrix()  #matrix = glGetDouble( GL_PROJECTION_MATRIX )
    glLoadIdentity()
    glOrtho(0.0, width, 0.0, height, -1.0, 1.0)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glLoadIdentity()
    if color:
        glColor3f(*color)
    glRasterPos2i(x, y)
    lines = 0
    for character in text:
        if character == '\n':
            lines += 1
            glRasterPos(x, y - (lines * line_height))
        else:
            glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ord(character))
    glPopMatrix()
    glMatrixMode(GL_PROJECTION)
    glPopMatrix()  #glLoadMatrixd(matrix)
    glMatrixMode(GL_MODELVIEW)
예제 #18
0
    def draw_light_source(self):

        glColor3f(1.0, 1.0, 1.0)

        # 15 is radius of the sphere that light source around
        self.light_source_position = [
            15 * sin(self.theta_light_angle * pi / 180) *
            sin(self.phi_light_angle * pi / 180),
            15 * cos(self.theta_light_angle * pi / 180),
            15 * sin(self.theta_light_angle * pi / 180) *
            cos(self.phi_light_angle * pi / 180)
        ]

        glTranslate(self.light_source_position[0],
                    self.light_source_position[1],
                    self.light_source_position[2])
        # set light source position
        glLightfv(GL_LIGHT0, GL_POSITION, [*self.light_source_position, 1])
        # set light color
        glLightfv(GL_LIGHT0, GL_DIFFUSE, self.light_color)
        # set light intensity
        glLightfv(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.7)
        glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0001)

        # turning the rays of light so that the back of the ball is shaded
        gl_q = gluNewQuadric()
        gluQuadricOrientation(gl_q, GLU_INSIDE)

        # draw visual envelope (ball)
        gluSphere(gl_q, 1, 20, 20)

        glLoadIdentity()
예제 #19
0
    def _paintGLGrid(self):
        resolutionMillimeters = 1
        griddedAreaSize = 100

        glLineWidth(1.0)

        glBegin(GL_LINES)

        glColor3f(1.0, 1.0, 1.0)

        glVertex3f(griddedAreaSize, 0, 0)
        glVertex3f(-griddedAreaSize, 0, 0)
        glVertex3f(0, griddedAreaSize, 0)
        glVertex3f(0, -griddedAreaSize, 0)

        numOfLines = int(griddedAreaSize / resolutionMillimeters)

        for i in range(numOfLines):
            glVertex3f(resolutionMillimeters * i, -griddedAreaSize, 0)
            glVertex3f(resolutionMillimeters * i, griddedAreaSize, 0)
            glVertex3f(griddedAreaSize, resolutionMillimeters * i, 0)
            glVertex3f(-griddedAreaSize, resolutionMillimeters * i, 0)

            glVertex3f(resolutionMillimeters * (-i), -griddedAreaSize, 0)
            glVertex3f(resolutionMillimeters * (-i), griddedAreaSize, 0)
            glVertex3f(griddedAreaSize, resolutionMillimeters * (-i), 0)
            glVertex3f(-griddedAreaSize, resolutionMillimeters * (-i), 0)

        glEnd()
예제 #20
0
    def draw_colour_legend(self):
        menubar_height = self.logo.size[1] + 4
        width = glutGet(GLUT_WINDOW_WIDTH)
        height = glutGet(GLUT_WINDOW_HEIGHT)
        # Colour legend
        left_x = width - 20
        right_x = width - 10
        min_y = menubar_height + 5
        max_y = height - 20
        time_step_size = math.ceil(self.max_hit_time / 20 / 50) * 50
        hit_times = list(range(int(self.min_hit_time), int(self.max_hit_time), int(time_step_size)))
        if len(hit_times) > 1:
            segment_height = int((max_y - min_y) / len(hit_times))
            glMatrixMode(GL_MODELVIEW)
            glLoadIdentity()
            glDisable(GL_LIGHTING)
            glBegin(GL_QUADS)
            for hit_time in hit_times:
                segment_nr = hit_times.index(hit_time)
                glColor3f(*self.spectrum(hit_time))
                glVertex2f(left_x, max_y - segment_height * segment_nr)
                glVertex2f(right_x, max_y - segment_height * segment_nr)
                glColor3f(*self.spectrum(hit_time + time_step_size))
                glVertex2f(left_x, max_y - segment_height * (segment_nr + 1))
                glVertex2f(right_x, max_y - segment_height * (segment_nr + 1))
            glEnd()

            # Colour legend labels
            self.colourist.now_text()
            for hit_time in hit_times:
                segment_nr = hit_times.index(hit_time)
                draw_text_2d("{0:>5}ns".format(hit_time), width - 80, (height - max_y) + segment_height * segment_nr)
예제 #21
0
    def draw(self):
        t1 = time.time()
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        horizonY = 1 * 2.2 - .6 + .5
        GLU.gluLookAt(self.eyeX.x, horizonY, 8.0, self.lookX.x, horizonY, 0.0,
                      0.0, 1.0, 0.0)

        glEnable(GL.GL_TEXTURE_2D)

        if 0:
            with pushMatrix():
                glColor3f(1, 0, 0)
                glTranslatef(*self.ball)
                glScalef(.2, .2, 1)
                imageCard("sample.jpg")

        with pushMatrix():
            with mode(disable=[GL.GL_LIGHTING]):
                for card in self.cards:
                    card.draw(self.eyeX.x, horizonY, self.cardList)

        glFlush()
        pygame.display.flip()
예제 #22
0
def make_plane():
    glNewList(G_OBJ_PLANE, GL_COMPILE)
    glBegin(GL_LINES)
    glColor3f(0, 0, 0)
    for i in xrange(41):
        glVertex3f(-10.0 + 0.5 * i, 0, -10)
        glVertex3f(-10.0 + 0.5 * i, 0, 10)
        glVertex3f(-10.0, 0, -10 + 0.5 * i)
        glVertex3f(10.0, 0, -10 + 0.5 * i)

    # Axes
    glEnd()
    glLineWidth(5)

    glBegin(GL_LINES)
    glColor3f(0.5, 0.7, 0.5)
    glVertex3f(0.0, 0.0, 0.0)
    glVertex3f(5, 0.0, 0.0)
    glEnd()

    glBegin(GL_LINES)
    glColor3f(0.5, 0.7, 0.5)
    glVertex3f(0.0, 0.0, 0.0)
    glVertex3f(0.0, 5, 0.0)
    glEnd()

    glBegin(GL_LINES)
    glColor3f(0.5, 0.7, 0.5)
    glVertex3f(0.0, 0.0, 0.0)
    glVertex3f(0.0, 0.0, 5)
    glEnd()

    # Draw the Y.
    glBegin(GL_LINES)
    glColor3f(0.0, 0.0, 0.0)
    glVertex3f(0.0, 5.0, 0.0)
    glVertex3f(0.0, 5.5, 0.0)
    glVertex3f(0.0, 5.5, 0.0)
    glVertex3f(-0.5, 6.0, 0.0)
    glVertex3f(0.0, 5.5, 0.0)
    glVertex3f(0.5, 6.0, 0.0)

    # Draw the Z.
    glVertex3f(-0.5, 0.0, 5.0)
    glVertex3f(0.5, 0.0, 5.0)
    glVertex3f(0.5, 0.0, 5.0)
    glVertex3f(-0.5, 0.0, 6.0)
    glVertex3f(-0.5, 0.0, 6.0)
    glVertex3f(0.5, 0.0, 6.0)

    # Draw the X.
    glVertex3f(5.0, 0.0, 0.5)
    glVertex3f(6.0, 0.0, -0.5)
    glVertex3f(5.0, 0.0, -0.5)
    glVertex3f(6.0, 0.0, 0.5)

    glEnd()
    glLineWidth(1)
    glEndList()
예제 #23
0
def make_plane():
    glNewList(G_OBJ_PLANE, GL_COMPILE)
    glBegin(GL_LINES)
    glColor3f(0, 0, 0)
    for i in range(41):
        glVertex3f(-10.0 + 0.5 * i, 0, -10)
        glVertex3f(-10.0 + 0.5 * i, 0, 10)
        glVertex3f(-10.0, 0, -10 + 0.5 * i)
        glVertex3f(10.0, 0, -10 + 0.5 * i)

    # Axes
    glEnd()
    glLineWidth(5)

    glBegin(GL_LINES)
    glColor3f(0.5, 0.7, 0.5)
    glVertex3f(0.0, 0.0, 0.0)
    glVertex3f(5, 0.0, 0.0)
    glEnd()

    glBegin(GL_LINES)
    glColor3f(0.5, 0.7, 0.5)
    glVertex3f(0.0, 0.0, 0.0)
    glVertex3f(0.0, 5, 0.0)
    glEnd()

    glBegin(GL_LINES)
    glColor3f(0.5, 0.7, 0.5)
    glVertex3f(0.0, 0.0, 0.0)
    glVertex3f(0.0, 0.0, 5)
    glEnd()

    # Draw the Y.
    glBegin(GL_LINES)
    glColor3f(0.0, 0.0, 0.0)
    glVertex3f(0.0, 5.0, 0.0)
    glVertex3f(0.0, 5.5, 0.0)
    glVertex3f(0.0, 5.5, 0.0)
    glVertex3f(-0.5, 6.0, 0.0)
    glVertex3f(0.0, 5.5, 0.0)
    glVertex3f(0.5, 6.0, 0.0)

    # Draw the Z.
    glVertex3f(-0.5, 0.0, 5.0)
    glVertex3f(0.5, 0.0, 5.0)
    glVertex3f(0.5, 0.0, 5.0)
    glVertex3f(-0.5, 0.0, 6.0)
    glVertex3f(-0.5, 0.0, 6.0)
    glVertex3f(0.5, 0.0, 6.0)

    # Draw the X.
    glVertex3f(5.0, 0.0, 0.5)
    glVertex3f(6.0, 0.0, -0.5)
    glVertex3f(5.0, 0.0, -0.5)
    glVertex3f(6.0, 0.0, 0.5)

    glEnd()
    glLineWidth(1)
    glEndList()
예제 #24
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()
예제 #25
0
파일: context3d.py 프로젝트: h2r/slu_core
 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()
예제 #26
0
def draw_rectangle(width, height, color, line_width=2):
    glColor3f(*color)
    glLineWidth(line_width)
    glBegin(GL_LINE_LOOP)
    for coords in [[1, 1], [1, -1], [-1, -1], [-1, 1]]:
        glVertex2f(*shift_scale_point(
            vec.Vec([width / 2, height / 2]) * vec.Vec(coords)))
    glEnd()
예제 #27
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()
예제 #28
0
def draw_rect(x, y, width, height):
    glColor3f(0.71, 0.83, 1)
    glBegin(GL_QUADS)
    glVertex2f(x, y)
    glVertex2f(x + width, y)
    glVertex2f(x + width, y + height)
    glVertex2f(x, y + height)
    glEnd()
    glColor3f(1, 1, 1)
예제 #29
0
def draw_lines_2d(lines, color, line_width=2):

    glColor3f(*color)
    glLineWidth(line_width)
    glBegin(GL_LINES)
    for line in lines:
        for point in line:
            glVertex2f(*shift_scale_point(point))
    glEnd()
예제 #30
0
def draw_points_2d(points, color, line_width=2):
    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)
        glVertex2f(*shift_scale_point(point))
        glVertex2f(*(shift_scale_point(point) + vec.Vec([1, 0])))
        glEnd()
예제 #31
0
 def paintSphere(self, diameter):
     r = diameter / 70.
     glColor3f(0., 0., 0.)
     glPushMatrix()
     glTranslatef(0., r - 1., 0.)  # move down
     glRotatef(90., 1., 0., 0.)
     slices = max(int(round(r * 32)), 9)
     glutWireSphere(r, slices, slices)
     glPopMatrix()
예제 #32
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()
예제 #33
0
def draw_rect(x, y, width, height):
    glColor3f(0.71, 0.83, 1)
    glBegin(GL_QUADS)
    glVertex2f(x, y)
    glVertex2f(x + width, y)
    glVertex2f(x + width, y + height)
    glVertex2f(x, y + height)
    glEnd()
    glColor3f(1, 1, 1)
예제 #34
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()
예제 #35
0
 def DrawHint(self):
     """Prints a caption for the plot"""
     p = self.printer
     p.ResetRaster()
     for sensorInfo in self.sensors:
         glColor3f(*sensorInfo["color"])
         # to make the color effective for text,
         # we have to call glRasterPos by printing a linebreak:
         p.Print("\n")
         p.Print("  %s" % (sensorInfo["name"]))
예제 #36
0
파일: graph.py 프로젝트: reims/wesen
 def DrawHint(self):
     """Prints a caption for the plot"""
     p = self.printer
     p.ResetRaster()
     for sensorInfo in self.sensors:
         glColor3f(*sensorInfo["color"])
         # to make the color effective for text,
         # we have to call glRasterPos by printing a linebreak:
         p.Print("\n")
         p.Print("  %s" % (sensorInfo["name"]))
예제 #37
0
    def render_me(self):
        glColor3f(1, 1, 1)

        glLoadIdentity()

        glTranslate(self.position[0], self.position[1], self.position[2])

        glutSolidCube(self.side_size)

        glLoadIdentity()
예제 #38
0
def draw_sphere(coords, radius, color_s=BLUE):
    quad: gluNewQuadric = gluNewQuadric()
    gluQuadricDrawStyle(quad, GLU_LINE)
    glColor3f(color_s[0], color_s[1], color_s[2])

    glPushMatrix()
    glTranslatef(coords[0], coords[1], coords[2])

    gluSphere(quad, radius, 12, 12)
    glPopMatrix()
예제 #39
0
def draw_lines(points, closed=False, color_l=WHITE):
    n = len(points)
    iters = n if closed else n - 1
    glBegin(GL_LINES)
    glColor3f(color_l[0], color_l[1], color_l[2])
    for i in range(iters):
        glVertex3fv(points[i])
        glVertex3fv(points[(i + 1) % n])

    glEnd()
예제 #40
0
파일: obj.py 프로젝트: OpenWerkplek/pymt
 def enter(self):
     if not self.compat:
         return
     glLightfv(GL_LIGHT0, GL_AMBIENT, (0, 0, 0, 1))
     glLightfv(GL_LIGHT0, GL_DIFFUSE, (.8, .8, .8, 1))
     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (.9, .9, .9))
     glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)
     glEnable(GL_LIGHTING)
     glEnable(GL_LIGHT0)
     glEnable(GL_DEPTH_TEST)
     glColor3f(1, 1, 1)
예제 #41
0
    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()
예제 #42
0
def _draw_text(font, input_str, x, y, line_height=16, r=1.0, g=1.0, b=1.0):
    """Render text based on window position. The origin is in the bottom-left."""
    glColor3f(r, g, b)
    glWindowPos2f(x, y)
    input_list = input_str.split('\n')
    y = y + (line_height * (len(input_list) - 1))
    for line in input_list:
        glWindowPos2f(x, y)
        y -= line_height
        for ch in line:
            glutBitmapCharacter(font, ctypes.c_int(ord(ch)))
예제 #43
0
 def enter(self):
     if not self.compat:
         return
     glLightfv(GL_LIGHT0, GL_AMBIENT, (0, 0, 0, 1))
     glLightfv(GL_LIGHT0, GL_DIFFUSE, (.8, .8, .8, 1))
     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (.9, .9, .9))
     glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)
     glEnable(GL_LIGHTING)
     glEnable(GL_LIGHT0)
     glEnable(GL_DEPTH_TEST)
     glColor3f(1, 1, 1)
    def render(self, random_colors=False):
        from OpenGL.GL import glMaterialfv, GL_FRONT, GL_SPECULAR, GL_SHININESS, GL_AMBIENT, GL_DIFFUSE, glColor3f

        glMaterialfv(GL_FRONT, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
        glMaterialfv(GL_FRONT, GL_SHININESS, [30.0])
        glMaterialfv(GL_FRONT, GL_AMBIENT, [self.color.x * 0.3, self.color.y * 0.3, self.color.z * 0.3, 1.0])
        glMaterialfv(GL_FRONT, GL_DIFFUSE, [self.color.x, self.color.y, self.color.z, 1.0])
        
        glColor3f(self.color.x, self.color.y, self.color.z)
        
        super().render(random_colors=random_colors)
예제 #45
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()
예제 #46
0
파일: Rockmeter.py 프로젝트: west2554/fofix
  def render(self, visibility, playerNum):
    w, h, = self.stage.engine.view.geometry[2:4]
    v = 1.0

    self.updateLayer(playerNum)
    for effect in self.effects:
      effect.update()
    
    glColor3f(*self.engine.theme.hexToColor(self.color))

    if self.condition:
      self.font.render(self.text, (self.position[0], self.position[1]), align = self.alignment)
예제 #47
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()
예제 #48
0
 def draw_pin(self, x, y):
     glPushMatrix()
     glColor3f(1.0, 1.0, 0.0)
     glTranslatef(x, 0.0, -y) 
     glRotatef(-90, 1.0, 0.0, 0.0)
     obj = gluNewQuadric()
     gluCylinder(obj, 0.05, 0.05, 0.5, 10, 10)
     glPushMatrix()
     gluDisk(obj, 0.0, 0.05, 10, 10)
     glTranslatef(0.0, 0.5, 0.0) 
     glPopMatrix()
     glPopMatrix()
예제 #49
0
파일: graph.py 프로젝트: reims/wesen
 def DrawPlot(self):
     """Plots the curves for all sensors in self.sensors"""
     glPushMatrix()
     # TODO the following is "moving away from frame",
     # and should use the framedata (plastic, etc.)
     # from the GuiObject base class.
     # Probably this stuff should be done in GuiObject!
     glTranslatef(0.005, 0.01, 0.0)
     glScalef(0.99 / self.resolution, 0.7 / self.maxValue, 1.0)
     for sensorInfo, data in zip(self.sensors, self.history):
         glColor3f(*(sensorInfo["color"]))
         data.Draw()
     glPopMatrix()
예제 #50
0
파일: node.py 프로젝트: 343829084/500lines
    def render(self):
        glPushMatrix()
        glMultMatrixf(numpy.transpose(self.translation))
        glMultMatrixf(self.scalemat)
        cur_color = color.COLORS[self.color_index]
        glColor3f(cur_color[0], cur_color[1], cur_color[2])
        if self.selected:  # emit light if the node is selected
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.3, 0.3, 0.3])
        glCallList(self.call_list)
        if self.selected:
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0])

        glPopMatrix()
예제 #51
0
파일: object.py 프로젝트: reims/wesen
 def _drawframe(self):
     """Draw a frame around the GuiObject"""
     framedata = self._getFrameData()
     color, plastic, x, y = framedata["color"], framedata["plastic"], \
         framedata["x"], framedata["y"]
     glColor3f(*(c - plastic for c in color))
     glRectf(0.0, 1.0, 1.0, 1.0 - x)
     # top
     glRectf(0.0, 0.0, y, 1.0)
     # left
     glColor3f(*(c + plastic for c in color))
     glRectf(0.0, 0.0, 1.0, x)
     # bottom
     glRectf(1.0, 0.0, 1.0 - y, 1.0)
예제 #52
0
    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()
예제 #53
0
    def draw_led(self, x, y, color):
        glPushMatrix()
        
        if color < 0:
            glColor3f(*self.color_led_red)
        else:
            glColor3f(*self.color_led_green)

        glTranslatef(x, 0.1, -y) 
        glRotatef(-90, 1.0, 0.0, 0.0)
        obj = gluNewQuadric()
        gluSphere(obj, 0.15, 10, 10)
        
        glPopMatrix()
예제 #54
0
def draw_text_3d(text, x, y, z, color=None):
    """Draw a text at a given 3D position.

    A very basic 3D drawing function for displaying text in a 3D scene.
    The multi-line support is experimental.
    """
    if color:
        glColor3f(*color)
    glRasterPos(x, y, z)
    for character in text:
        if character == '\n':
            glRasterPos(x, y, z - 15)
        else:
            glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ord(character))
예제 #55
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)
예제 #56
0
    def render(self):
        """ renders the item to the screen """
        glPushMatrix()
        glMultMatrixf(numpy.transpose(self.translation_matrix))
        glMultMatrixf(self.scaling_matrix)
        cur_color = color.COLORS[self.color_index]
        glColor3f(cur_color[0], cur_color[1], cur_color[2])
        if self.selected:  # emit light if the node is selected
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.3, 0.3, 0.3])

        self.render_self()

        if self.selected:
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0])
        glPopMatrix()
예제 #57
0
파일: verlet.py 프로젝트: genjix/random
 def draw(self):
     size = self.mass
     if size < 0.2:
         size = 0.2
     glBegin(GL_TRIANGLE_FAN)
     glColor3f(1.0, 0.0, 0.0)
     """glVertex2f(-self.mass, -self.mass)
     glColor3f(0.0, 1.0, 0.0)
     glVertex2f(0.0, self.mass)
     glColor3f(0.0, 0.0, 1.0)
     glVertex2f(self.mass, -self.mass)"""
     glVertex2f(0.0, 0.0)
     glColor3f(0.0, 1.0, 0.0)
     for angle in xrange(0,370,10):
         glVertex2f(math.sin(angle)*size, math.cos(angle)*size)
     glEnd()
예제 #58
0
    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()