Ejemplo n.º 1
0
 def draw_lane_lines(self, lane):
     gl.glColor3f(1., 1., 1.)
     W = 1000
     graphics.draw(4, gl.GL_LINES, ('v2f',
         np.hstack([lane.p-lane.m*W-0.5*lane.w*lane.n, lane.p+lane.m*W-0.5*lane.w*lane.n,
                    lane.p-lane.m*W+0.5*lane.w*lane.n, lane.p+lane.m*W+0.5*lane.w*lane.n])
     ))
Ejemplo n.º 2
0
	def draw(self, frame):
		# The gneneral plan here is:
		#  1. Get the dots in the range of 0-255.
		#  2. Create a texture with the dots data.
		#  3. Draw the texture, scaled up with nearest-neighbor.
		#  4. Draw a mask over the dots to give them a slightly more realistic look.
		
		gl.glEnable(gl.GL_BLEND)
		gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
		gl.glLoadIdentity()
		
		# Draw the dots in this color:
		gl.glColor3f(1.0, 0.5, 0.25)

		gl.glScalef(1, -1, 1)
		gl.glTranslatef(0, -DMD_SIZE[1]*DMD_SCALE, 0)

		data = frame.get_data_mult()
		image = pyglet.image.ImageData(DMD_SIZE[0], DMD_SIZE[1], 'L', data, pitch=DMD_SIZE[0])

		gl.glTexParameteri(image.get_texture().target, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
		image.blit(0, 0, width=DMD_SIZE[0]*DMD_SCALE, height=DMD_SIZE[1]*DMD_SCALE)

		del image

		gl.glScalef(DMD_SCALE/float(MASK_SIZE), DMD_SCALE/float(MASK_SIZE), 1.0)
		gl.glColor4f(1.0, 1.0, 1.0, 1.0)
		self.mask_texture.blit_tiled(x=0, y=0, z=0, width=DMD_SIZE[0]*MASK_SIZE, height=DMD_SIZE[1]*MASK_SIZE)
Ejemplo n.º 3
0
 def render_boid(self):
     glBegin(GL_TRIANGLES)
     glColor3f(*self.color)
     glVertex2f(-(self.size), 0.0)
     glVertex2f(self.size, 0.0)
     glVertex2f(0.0, self.size * 3.0)
     glEnd()
Ejemplo n.º 4
0
 def draw(self, colour=(0., 0., 1.)):
   s = self.size # just a shorthand
   gl.glColor3f(*colour)
   gl.glBegin(gl.GL_LINE_LOOP)
   for vertex in self.verticies:
     gl.glVertex2f(*vertex)
   gl.glEnd()
Ejemplo n.º 5
0
 def flush_labels(self):
     gl.glClear(gl.GL_DEPTH_BUFFER_BIT)
     gl.glPushMatrix()
     gl.glTranslatef(-self.game.camera_x * defs.WINDOW_SCALE[0],
                     -self.game.camera_y * defs.WINDOW_SCALE[1], 0)
     for label, x, y, scale in self.labels:
         if scale:
             gl.glPushMatrix()
             label.anchor_x = 'center'
             label.anchor_y = 'center'
             gl.glTranslatef(x * defs.WINDOW_SCALE[0],
                             y * defs.WINDOW_SCALE[1], 0)
             gl.glScalef(*scale)
             label.x = label.y = 0
             label.draw()
             gl.glPopMatrix()
         else:
             label.x = x * defs.WINDOW_SCALE[0]
             label.y = y * defs.WINDOW_SCALE[1]
             label.draw()
     self.labels = []
     gl.glColor3f(1, 1, 1)
     gl.glEnable(gl.GL_DEPTH_TEST)
     gl.glPopMatrix()
     # self.fps_label.draw()
     self.game.score.draw()
Ejemplo n.º 6
0
 def create_window(self, _iScr=0, _title="", _dx=0, _dy=0, _left=0, _top=0,
                   _scale=1.0, _isScrOvl=False, _iScrGUI=0, _offset=(0,0)):
   """ If the renderer was initialized, create a window instance and store
       it in the internal window list. For parameters, see Window class.
   """
   if self.isReady:
     self.winList.append(Window(self, _iScr, _title, _dx, _dy, _left, _top,
                                _scale, _isScrOvl, _iScrGUI, _offset))    
     '''
     if len(self.winList) == 1:
     # Is the first window, set some general OpenGL properties
     #
     '''
     GL.glClearColor(0., 0., 0., 0.)
     GL.glColor3f(1., 1., 1.)
     GL.glDisable(GL.GL_DEPTH_TEST)
     GL.glEnable(GL.GL_BLEND)
     GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
     '''
     GL.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
     GL.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
 
     GL.glShadeModel(GL_FLAT) # GL_FLAT or GL_SMOOTH
     GL.glEnable(GL_POINT_SMOOTH)
     '''
     return self.winList[-1]
   else:  
     return None
Ejemplo n.º 7
0
 def draw_lane_surface(self, lane):
     gl.glColor3f(0.4, 0.4, 0.4)
     W = 1000
     graphics.draw(4, gl.GL_QUAD_STRIP, ('v2f',
         np.hstack([lane.p-lane.m*W-0.5*lane.w*lane.n, lane.p-lane.m*W+0.5*lane.w*lane.n,
                    lane.q+lane.m*W-0.5*lane.w*lane.n, lane.q+lane.m*W+0.5*lane.w*lane.n])
     ))
Ejemplo n.º 8
0
 def f():
     for u in range(1, len(self.u_set)):
         pgl.glBegin(pgl.GL_QUAD_STRIP)
         for v in range(len(self.v_set)):
             pa = self.verts[u - 1][v]
             pb = self.verts[u][v]
             if pa is None or pb is None:
                 pgl.glEnd()
                 pgl.glBegin(pgl.GL_QUAD_STRIP)
                 continue
             if use_cverts:
                 ca = self.cverts[u - 1][v]
                 cb = self.cverts[u][v]
                 if ca is None:
                     ca = (0, 0, 0)
                 if cb is None:
                     cb = (0, 0, 0)
             else:
                 if use_solid_color:
                     ca = cb = self.default_solid_color
                 else:
                     ca = cb = self.default_wireframe_color
             pgl.glColor3f(*ca)
             pgl.glVertex3f(*pa)
             pgl.glColor3f(*cb)
             pgl.glVertex3f(*pb)
         pgl.glEnd()
Ejemplo n.º 9
0
 def draw(self):
     if draw_debug:
         glColor3f(1,1,1)
         self.vertex_list.draw(GL_LINE_LOOP)
         glColor3f(1,1,0)
         for j,r in self.forces:
             pyglet.graphics.draw(2, GL_LINES, ("v2f", (r[0], r[1], r[0] + j[0]/10, r[1] + j[1]/10)))
Ejemplo n.º 10
0
Archivo: trees.py Proyecto: Knio/miru
    def _draw(self):
        corner = c = self.octree.corner
        w = self.octree.width

        gl.glPushAttrib( gl.GL_ENABLE_BIT )
        gl.glEnable( gl.GL_COLOR_MATERIAL )

        if self.octree._child_nodes is None:
            if self.list_id:
                gl.glCallList(self.list_id)
            else:
                self.list_id = gl.glGenLists(1)
                gl.glNewList(self.list_id, gl.GL_COMPILE)

                gl.glColor3f(*self.color)
                gl.glBegin(gl.GL_LINE_LOOP)
                gl.glVertex3f(*c)
                gl.glVertex3f(*(c + (0,w,0)))
                gl.glVertex3f(*(c + (0,w,w)))
                gl.glVertex3f(*(c + (0,0,w)))
                gl.glEnd()

                c = corner + (w,0,0)

                gl.glBegin(gl.GL_LINE_LOOP)
                gl.glVertex3f(*c)
                gl.glVertex3f(*(c + (0,w,0)))
                gl.glVertex3f(*(c + (0,w,w)))
                gl.glVertex3f(*(c + (0,0,w)))
                gl.glEnd()

                gl.glBegin(gl.GL_LINES)
                gl.glVertex3f(*c)
                gl.glVertex3f(*(c - (w,0,0)))
                gl.glVertex3f(*(c + (0,w,0)))
                gl.glVertex3f(*(corner + (0,w,0)))
                gl.glVertex3f(*(c + (0,w,w)))
                gl.glVertex3f(*(corner + (0,w,w)))
                gl.glVertex3f(*(c + (0,0,w)))
                gl.glVertex3f(*(corner + (0,0,w)))
                gl.glEnd()

                gl.glEndList()

        # This could be optimized of course
        if self.octree._child_nodes is not None:
            r = self.color[0] + 0.14
            if r < 1.0:
                r = r % 1.0
            else:
                r = 1.0
            b = max((self.color[2] - 0.14), 0)
            for node in self.octree._child_nodes.values():
                if not self._cache.has_key(id(node)):
                    self._cache[id(node)] = OctreeDebug(node, color=(r,0,b))
                debugNode = self._cache[id(node)]
                debugNode._draw()
        gl.glColor3f(1,1,1)

        gl.glPopAttrib()
Ejemplo n.º 11
0
 def draw_line(self, v, color):
     o = self._p._origin
     pgl.glBegin(pgl.GL_LINES)
     pgl.glColor3f(*color)
     pgl.glVertex3f(v[0][0] + o[0], v[0][1] + o[1], v[0][2] + o[2])
     pgl.glVertex3f(v[1][0] + o[0], v[1][1] + o[1], v[1][2] + o[2])
     pgl.glEnd()
Ejemplo n.º 12
0
def draw_block(block):
    transformed = [world_to_screen(block.GetWorldPoint(p)) for p in POINTS]
    gl.glColor3f(1.0, 0.1, 0)
    gl.glBegin(gl.GL_LINE_LOOP)
    for p in transformed:
        gl.glVertex2f(*p)
    gl.glEnd()
Ejemplo n.º 13
0
    def draw(self):
        self.loadStartPosition()
        gl.glRotatef(90.0, 0.0, 0.0, 1.0)
        gl.glBegin(gl.GL_QUADS)
        gl.glColor3f(1.0, 1.0, 0.0)
        tenth = math.pi * 2.0 / 10.0
        for z in [-0.1, 0.1]:
            for i in xrange(5):
                a = float(i) * tenth * 2.0
                gl.glVertex3f(0.0, 0.0, z)
                gl.glVertex3f(0.4 * math.cos(a - tenth), 0.4 * math.sin(a - tenth), z)
                gl.glVertex3f(math.cos(a), math.sin(a), z)
                gl.glVertex3f(0.4 * math.cos(a + tenth), 0.4 * math.sin(a + tenth), z)
        for i in xrange(5):
            a = float(i) * tenth * 2.0
            gl.glVertex3f(0.4 * math.cos(a - tenth), 0.4 * math.sin(a - tenth), 0.1)
            gl.glVertex3f(math.cos(a), math.sin(a), 0.1)
            gl.glVertex3f(math.cos(a), math.sin(a), -0.1)
            gl.glVertex3f(0.4 * math.cos(a - tenth), 0.4 * math.sin(a - tenth), -0.1)
            gl.glVertex3f(0.4 * math.cos(a + tenth), 0.4 * math.sin(a + tenth), 0.1)
            gl.glVertex3f(math.cos(a), math.sin(a), 0.1)
            gl.glVertex3f(math.cos(a), math.sin(a), -0.1)
            gl.glVertex3f(0.4 * math.cos(a + tenth), 0.4 * math.sin(a + tenth), -0.1)
        gl.glEnd()

        self.loadStartPosition()
        gl.glTranslatef(0.0, 0.0, 0.1)
        gl.glScalef(0.01, 0.01, 0.0)
        self.label.draw()

        gl.glLoadIdentity()
Ejemplo n.º 14
0
 def draw(self):
     gl.glClear(gl.GL_DEPTH_BUFFER_BIT)
     if self.game.game_over:
         if self.game.game_lost:
             gl.glBegin(gl.GL_QUADS)
             gl.glColor3f(1, 1, 1)
             gl.glVertex3f(0, 0, -0.9)
             gl.glVertex3f(0, defs.WINDOW_HEIGHT, -0.9)
             gl.glVertex3f(defs.WINDOW_WIDTH, defs.WINDOW_HEIGHT, -0.9)
             gl.glVertex3f(defs.WINDOW_WIDTH, 0, -0.9)
             gl.glEnd()
             self.you_died.draw()
             self.you_died2.draw()
             if not self.died:
                 for name in self.VALUES:
                     getattr(self, name + '_label').color = (0, 0, 0, 255)
             self.died = True
         else:
             gl.glBegin(gl.GL_QUADS)
             gl.glColor3f(0, 0, 0)
             gl.glVertex3f(0, 0, -0.9)
             gl.glVertex3f(0, defs.WINDOW_HEIGHT, -0.9)
             gl.glVertex3f(defs.WINDOW_WIDTH, defs.WINDOW_HEIGHT, -0.9)
             gl.glVertex3f(defs.WINDOW_WIDTH, 0, -0.9)
             gl.glEnd()
             self.you_win.draw()
     for name in self.VALUES:
         getattr(self, name + '_label').draw()
Ejemplo n.º 15
0
def setup():
    # One-time GL setup
    glClearColor(1, 1, 1, 1)
    glColor3f(1, 0, 0)
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_CULL_FACE)

    # Uncomment this line for a wireframe view
    #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

    # Simple light setup.  On Windows GL_LIGHT0 is enabled by default,
    # but this is not the case on Linux or Mac, so remember to always
    # include it.
    glEnable(GL_LIGHTING)
    glEnable(GL_LIGHT0)
    glEnable(GL_LIGHT1)

    # Define a simple function to create ctypes arrays of floats:
    def vec(*args):
        return (GLfloat * len(args))(*args)

    glLightfv(GL_LIGHT0, GL_POSITION, vec(.5, .5, 1, 0))
    glLightfv(GL_LIGHT0, GL_SPECULAR, vec(.5, .5, 1, 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, 50)
Ejemplo n.º 16
0
 def setup(self):
   # One-time GL setup
   gl.glClearColor(1, 1, 1, 0)
   gl.glColor3f(1, 0, 0)
   gl.glEnable(gl.GL_DEPTH_TEST)
   gl.glEnable(gl.GL_CULL_FACE)
   gl.glDisable(gl.GL_LIGHTING)
Ejemplo n.º 17
0
 def draw(self):
     gl.glColor3f(0, 0, 0)
     gl.glRectd(self._aabb.x, self._aabb.y, self._aabb.x+self._aabb.width,
             self._aabb.y+self._aabb.height)
     gl.glColor3f(*self.color)
     gl.glRectd(self._aabb.x+2, self._aabb.y+2,
             self._aabb.x+self._aabb.width-2, self._aabb.y+self._aabb.height-2)
Ejemplo n.º 18
0
	def draw(self):
		for x,y in self.grid:
			opengl.glPushMatrix()
			opengl.glTranslatef(x*self.grid_size, y*self.grid_size, 0)
			opengl.glColor3f(self.color[0], self.color[1], self.color[2])
			self.vlist.draw(pyglet.gl.GL_LINE_LOOP)
			opengl.glPopMatrix()
		if self.secondary is not None: self.secondary.draw()
Ejemplo n.º 19
0
 def draw(self):
   r = self.size.x
   gl.glColor3f(1.0, .7, 0.0)
   with shiftView(self.body.position):
     gl.glBegin(gl.GL_LINE_LOOP)
     for angle in xrange(0, 360, 360/12):
       gl.glVertex2f(*self.size.rotated_degrees(angle))
     gl.glEnd()
Ejemplo n.º 20
0
 def drawGl(self):
     glColor3f(0,0.5,0)
     offset = 0
     x1, x2 = 0, self.width
     for i in range(8):
         y = self.altitude - offset
         pyglet.graphics.draw(2, GL_LINES, ('v2i', (x1, y, x2, y)))
         offset += i*2
Ejemplo n.º 21
0
 def draw(self):
     if not self.should_draw: return
     glColor3f(1, 1, 1)
     self.texture.blit(0, 100)
     glColor4f(1, 1, 1, 0.65)
     glRectf(0, 0, self.width, 100)
     self.lbls.draw()
     self.draw_subcontrols()
Ejemplo n.º 22
0
 def nakresli_tvar(self):
     """Nakreslí obdélník"""
     gl.glColor3f(1, 0.5, 0)
     gl.glBegin(gl.GL_TRIANGLE_FAN)
     gl.glVertex2f(-VELIKOST_TORPEDA, -VELIKOST_TORPEDA/2)
     gl.glVertex2f(-VELIKOST_TORPEDA, VELIKOST_TORPEDA/2)
     gl.glVertex2f(VELIKOST_TORPEDA, VELIKOST_TORPEDA/2)
     gl.glVertex2f(VELIKOST_TORPEDA, -VELIKOST_TORPEDA/2)
     gl.glEnd()
Ejemplo n.º 23
0
    def draw(self):
        gl.glColor3f(1, 1, 1)
        gl.glBegin(gl.GL_LINES)
        gl.glVertex2f(0, 50)
        gl.glVertex2f(self.window.width, 50)
        gl.glEnd()

        for label in self.labels:
            label.draw()
Ejemplo n.º 24
0
 def render(self):
     self.w.batches["mm_buttons"].draw()
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     gl.glColor3f(0.3, 0.3, 0.3, 1)
     for e in self.entries:
         graphics.draw(
             4, gl.GL_QUADS, ('v2i', e.rectangle)
         )
         e.label.draw()
Ejemplo n.º 25
0
def draw_rects(done, colors):
    gl.glBegin(gl.GL_QUADS)
    for rect in done:
        gl.glColor3f(*colors[rect.rel])
        gl.glVertex2f(rect.x, rect.y)
        gl.glVertex2f(rect.x+rect.width, rect.y)
        gl.glVertex2f(rect.x+rect.width, rect.y+rect.height)
        gl.glVertex2f(rect.x, rect.y+rect.height)
    gl.glEnd()
Ejemplo n.º 26
0
def draw_line(a, b, color):
    gl.glPushMatrix()
    gl.glColor3f(color[0], color[1], color[2])
    gl.glLineWidth(2)
    gl.glBegin(gl.GL_LINES)
    gl.glVertex2f(a[0], a[1])
    gl.glVertex2f(b[0], b[1])
    gl.glEnd()
    gl.glPopMatrix()
Ejemplo n.º 27
0
                def draw_arrow(p1, p2):
                    """
                    Draw a single vector.
                    """
                    glColor3f(0.4, 0.4, 0.9)
                    glVertex3f(*p1)

                    glColor3f(0.9, 0.4, 0.4)
                    glVertex3f(*p2)
Ejemplo n.º 28
0
 def drawBackground(self):
     glColor3f(self.backColour[0],self.backColour[1],self.backColour[2])
     glTranslatef(self.focusX, self.focusY, 0)
     glBegin(GL_QUADS)
     glVertex3i(0, 0, 0)
     glVertex3f(0, float(self.height), 0)
     glVertex3f(float(self.width), float(self.height), 0)
     glVertex3f(float(self.width), 0, 0)
     glEnd()
     glTranslatef(-self.focusX, -self.focusY, 0)
Ejemplo n.º 29
0
	def renderCatalog(cat, far):
		gl.glDisable(gl.GL_LIGHTING)
		for s in cat:
			c = s.getRgb()
			gl.glPointSize(s.getSize())
			gl.glBegin(gl.GL_POINTS)
			gl.glColor3f(c[0], c[1], c[2])
			gl.glVertex3f(far * cos(s.ra_rad) * cos(s.dec_rad), far * sin(s.ra_rad) * cos(s.dec_rad), far * sin(s.dec_rad))
			gl.glEnd()
		gl.glEnable(gl.GL_LIGHTING)
Ejemplo n.º 30
0
 def draw(self, colour=(0., 0., 1.)):
   s = self.size # shorthand
   gl.glColor3f(*colour)
   with shiftView(self.pos):
     gl.glBegin(gl.GL_LINE_LOOP)
     gl.glVertex2f(-s.x, +s.y)
     gl.glVertex2f(+s.x, +s.y)
     gl.glVertex2f(+s.x, -s.y)
     gl.glVertex2f(-s.x, -s.y)
     gl.glEnd()
Ejemplo n.º 31
0
def bezier_draw(cps, n=20, red=False):
    pts = [bezier_point(cps, i / (n - 1)) for i in range(0, n)]
    gl.glBegin(gl.GL_LINE_STRIP)

    if red:
        gl.glColor3f(1, 0, 0)
    else:
        gl.glColor3f(0, 0, 1)

    for i, p in enumerate(pts):
        gl.glVertex3f(*p)

    gl.glEnd()
    gl.glColor3f(1, 1, 1)
Ejemplo n.º 32
0
def drawStuff():

    gl.glBegin(gl.GL_TRIANGLES)
    gl.glColor3f(1.0, 0.0, 1)
    gl.glVertex3f(0.0, 0.5, 1)
    gl.glColor3f(0.0, 1.0, 0.0)
    gl.glVertex3f(-0.5, -0.5, 1)
    gl.glColor3f(0.0, 0.0, 1.0)
    gl.glVertex3f(0.5, -0.5, -1)
    gl.glEnd()

    a_blob.draw()

    myWin.flip()
Ejemplo n.º 33
0
def bezier_draw_points_curve(cps, n=10, red=False):
    from pyglet import gl
    pts = [bezier_point(cps, i / (n - 1)) for i in range(0, n)]
    gl.glPointSize(5)
    gl.glBegin(gl.GL_POINTS)

    if red:
        gl.glColor3f(0, 0, 1)
    else:
        gl.glColor3f(1, 0, 0)

    for i, p in enumerate(pts):
        gl.glVertex3f(p[0], 0.01, p[2])

    gl.glEnd()
    gl.glColor3f(1, 1, 1)
Ejemplo n.º 34
0
 def render1(self):
     points = [[0.08910714285714288, -0.009017857142857133],
               [0.13910714285714287, -0.04026785714285712],
               [0.12285714285714289, 0.07098214285714288],
               [0.08535714285714285, 0.03348214285714288],
               [0.10535714285714287, 0.07848214285714286],
               [0.04910714285714285, 0.13348214285714285],
               [-0.03589285714285714, 0.11723214285714287],
               [-0.14964285714285713, 0.08598214285714287],
               [-0.21714285714285714, 0.023482142857142868],
               [-0.18589285714285714, -0.004017857142857129],
               [-0.12714285714285714, -0.11151785714285713],
               [-0.039642857142857146, -0.15651785714285713],
               [0.044107142857142845, -0.15651785714285713],
               [0.12035714285714288, -0.06526785714285713]]
     gl.glColor3f(*self.color)
     gl.glBegin(gl.GL_POLYGON)
     for p0, p1 in points:
         gl.glVertex3f(p0, -p1, 0)
     gl.glEnd()
     points = [[-0.14964285714285713, -0.016517857142857112],
               [-0.11214285714285714, 0.020982142857142866],
               [-0.15839285714285714, 0.06973214285714288],
               [-0.17089285714285712, 0.013482142857142887]]
     gl.glColor3f(0.5, 0.4, 0.3)
     gl.glBegin(gl.GL_POLYGON)
     for p0, p1 in points:
         gl.glVertex3f(p0, -p1, 0)
     gl.glEnd()
     points = []
     for i in range(20):
         ang = 2 * np.pi * i / 20
         points.append((np.cos(ang) * 0.018 - 0.16,
                        np.sin(ang) * 0.018 - 0.01))
     gl.glColor3f(0, 0, 0)
     gl.glBegin(gl.GL_POLYGON)
     for p0, p1 in points:
         gl.glVertex3f(p0, p1, 0)
     gl.glEnd()
Ejemplo n.º 35
0
def drawing():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)  # smaz obsah okna (vybarvi na cerno)
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu

    ### Plots the snake body
    for i in range(0, len(snake_position) - 1):
        draw_rectangle(PIECE * snake_position[i][0],
                       PIECE * snake_position[i][1],
                       PIECE * (snake_position[i][0] + 1),
                       PIECE * (snake_position[i][1] + 1))

    ### Snake head in blue
    gl.glColor3f(0, 0, 1)
    draw_rectangle(PIECE * snake_position[-1][0],
                   PIECE * snake_position[-1][1],
                   PIECE * (snake_position[-1][0] + 1),
                   PIECE * (snake_position[-1][1] + 1))

    ### Food
    draw_rectangle(PIECE * food_position[0], PIECE * food_position[1],
                   PIECE * (food_position[0] + 1),
                   PIECE * (food_position[1] + 1))
    ### Score
    draw_text(str(N - 20), PIECE * SCORE_POSITION[0],
              PIECE * SCORE_POSITION[1], 'left', PIECE * FONT_SIZE)
    ### Walls
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu
    draw_rectangle(0, 0, PIECE * WALL_THICKNESS, PIECE * HEIGHT)
    draw_rectangle(0, 0, PIECE * WIDTH, PIECE * WALL_THICKNESS)
    draw_rectangle(PIECE * WIDTH - PIECE * WALL_THICKNESS, 0, PIECE * WIDTH,
                   PIECE * HEIGHT)
    draw_rectangle(0, PIECE * HEIGHT - PIECE * WALL_THICKNESS, PIECE * WIDTH,
                   PIECE * HEIGHT)

    if QUIT_SIGNAL == 1:
        draw_text('GAME OVER', PIECE * WIDTH // 2 - PIECE * FONT_SIZE * 4,
                  PIECE * HEIGHT // 2 - PIECE * FONT_SIZE // 2, 'left',
                  PIECE * FONT_SIZE)
Ejemplo n.º 36
0
    def draw(self):
        gl.glLineWidth(1)

        ecsm = game_scene.ecsm

        phys_comp_list = ecsm.comps[phys.PhysicsEcsComponent.name()]
        grav_comp_list = ecsm.comps[phys.GravityEcsComponent.name()]
        coll_comp_list = ecsm.comps[collision.CollisionEcsComponent.name()]
        planet_comp_list = ecsm.comps[planet.PlanetEcsComponent.name()]
        ship_comp_list = ecsm.comps[ship.ShipEcsComponent.name()]
        base_comp_list = ecsm.comps[base.BaseEcsComponent.name()]

        entities = ecsm.entities

        player_entity_id = ecsm.get_system(
            player.PlayerEscSystem.name()).player_entity_id
        player_physc = ecsm.get_entity_comp(player_entity_id,
                                            phys.PhysicsEcsComponent.name())

        # if player_physc:
        #	tx = (-player_physc.pos.x * ZOOM) + const.WIDTH // 2
        #	ty = (-player_physc.pos.y * ZOOM) + const.HEIGHT // 2
        # else:
        tx = const.WIDTH // 2
        ty = const.HEIGHT // 2

        gl.glColor3f(0, 0, 0.2)
        for i in range(0, const.WIDTH, 50):
            gl.glBegin(gl.GL_LINES)
            gl.glVertex2f(i, 0.0)
            gl.glVertex2f(i, const.HEIGHT)
            gl.glEnd()

        for i in range(0, const.HEIGHT, 50):
            gl.glBegin(gl.GL_LINES)
            gl.glVertex2f(0.0, i)
            gl.glVertex2f(const.WIDTH, i)
            gl.glEnd()

        gl.glPushMatrix()
        gl.glLoadIdentity()

        gl.glTranslatef(tx, ty, 0.0)

        # planet orbots
        for idx, eid in enumerate(entities):
            planetc = planet_comp_list[idx]
            physc = phys_comp_list[idx]

            if planetc and physc.static:
                # rpc = rend_plan_comp_list[idx]
                # render.draw_circle(physc.pos.x * ZOOM, physc.pos.y * ZOOM, collc.radius * ZOOM)

                distance = physc.pos.length
                if distance:
                    render.draw_circle(0,
                                       0,
                                       distance * ZOOM,
                                       mode=gl.GL_LINES,
                                       color=(.5, .5, .5, 1))

        for idx, eid in enumerate(entities):
            shipc = ship_comp_list[idx]
            basec = base_comp_list[idx]
            planetc = planet_comp_list[idx]
            physc = phys_comp_list[idx]
            collc = coll_comp_list[idx]

            if basec and basec.crew_load > 0:
                render.draw_circle(physc.pos.x * ZOOM,
                                   physc.pos.y * ZOOM,
                                   TOKEN_SIZE * ZOOM,
                                   color=(1, 1, 0, 1))

            # show planet
            elif planetc:
                # rpc = rend_plan_comp_list[idx]
                render.draw_circle(physc.pos.x * ZOOM,
                                   physc.pos.y * ZOOM,
                                   collc.radius * ZOOM,
                                   color=(.8, .8, .8, 1))

                # gc = grav_comp_list[idx]
                # if gc and gc.gravity_radius:
            #	render.draw_circle(physc.pos.x * ZOOM, physc.pos.y * ZOOM, gc.gravity_radius * ZOOM, None, gl.GL_LINE_LOOP, color=(.3, .3, .3, 1))

        # labels
        for idx, eid in enumerate(entities):
            planetc = planet_comp_list[idx]
            physc = phys_comp_list[idx]
            collc = coll_comp_list[idx]

            if planetc:
                if planetc.pname:
                    label = pyglet.text.Label(
                        planetc.pname,
                        font_name=font.FONT_MONO.name,
                        font_size=12,
                        x=physc.pos.x * ZOOM,
                        y=(physc.pos.y + (collc.radius + 500)) * ZOOM,
                        # + collc.radius + 5
                        anchor_x='center',
                        anchor_y='center',
                        color=(255, 255, 255, 120))
                    label.draw()

        # show player position
        if player_physc:
            render.draw_circle(player_physc.pos.x * ZOOM,
                               player_physc.pos.y * ZOOM,
                               TOKEN_SIZE * ZOOM,
                               color=(1, 0, 0, 1))

        gl.glPopMatrix()
Ejemplo n.º 37
0
 def level_draw(self, camera):
     gl.glLoadIdentity()
     gl.glBegin(gl.GL_TRIANGLES)
     gl.glColor3f(1.0, 1.0, 1.0)
     secs = 0
     necs = 0
     for sector in self.sectors:
         if camera.inCamera(sector.x, sector.y, sector.w, sector.h):
             secs += 1
             for node in sector.nodes:
                 necs += 1
                 if node.e4:
                     node2 = node.e4.end
                     if node2.e6:
                         node3 = node2.e6.end
                         gl.glColor3f(*TriNode.color[node.mat])
                         gl.glVertex2f(node.vx - camera.x,
                                       node.vy - camera.y)
                         gl.glColor3f(*TriNode.color[node2.mat])
                         gl.glVertex2f(node2.vx - camera.x,
                                       node2.vy - camera.y)
                         gl.glColor3f(*TriNode.color[node3.mat])
                         gl.glVertex2f(node3.vx - camera.x,
                                       node3.vy - camera.y)
                 if node.e5:
                     node2 = node.e5.end
                     if node2.e3:
                         node3 = node2.e3.start
                         gl.glColor3f(*TriNode.color[node.mat])
                         gl.glVertex2f(node.vx - camera.x,
                                       node.vy - camera.y)
                         gl.glColor3f(*TriNode.color[node2.mat])
                         gl.glVertex2f(node2.vx - camera.x,
                                       node2.vy - camera.y)
                         gl.glColor3f(*TriNode.color[node3.mat])
                         gl.glVertex2f(node3.vx - camera.x,
                                       node3.vy - camera.y)
     gl.glEnd()
     #print(secs, necs)
     gl.glBegin(gl.GL_LINES)
     gl.glColor3f(1.0, 1.0, 1.0)
     for sector in self.sectors:
         if camera.inCamera(sector.x, sector.y, sector.w, sector.h):
             for node in sector.nodes:
                 for edge in node.leftEdgeList():
                     gl.glVertex2f(edge.start.vx - camera.x,
                                   edge.start.vy - camera.y)
                     gl.glVertex2f(edge.end.vx - camera.x,
                                   edge.end.vy - camera.y)
     gl.glEnd()
     if self.selected:
         s = self.selected
         sz = 4
         gl.glBegin(gl.GL_QUADS)
         gl.glColor3f(1.0, 0.0, 0.0)
         gl.glVertex2d(s.vx - sz - camera.x, s.vy - sz - camera.y)
         gl.glVertex2d(s.vx - sz - camera.x, s.vy + sz - camera.y)
         gl.glVertex2d(s.vx + sz - camera.x, s.vy + sz - camera.y)
         gl.glVertex2d(s.vx + sz - camera.x, s.vy - sz - camera.y)
         gl.glEnd()
Ejemplo n.º 38
0
    def on_draw():
        window.clear()

        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_LINE_SMOOTH)

        width, height = window.get_size()
        gl.glViewport(0, 0, width, height)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.gluPerspective(60, width / float(height), 0.01, 20)

        gl.glMatrixMode(gl.GL_TEXTURE)
        gl.glLoadIdentity()
        # texcoords are [0..1] and relative to top-left pixel corner, add 0.5 to center
        gl.glTranslatef(0.5 / image_data.width, 0.5 / image_data.height, 0)
        image_texture = image_data.get_texture()
        # texture size may be increased by pyglet to a power of 2
        tw, th = image_texture.owner.width, image_texture.owner.height
        gl.glScalef(image_data.width / float(tw),
                    image_data.height / float(th), 1)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        gl.gluLookAt(0, 0, 0, 0, 0, 1, 0, -1, 0)

        gl.glTranslatef(0, 0, state.distance)
        gl.glRotated(state.pitch, 1, 0, 0)
        gl.glRotated(state.yaw, 0, 1, 0)

        if any(state.mouse_btns):
            axes(0.1, 4)

        gl.glTranslatef(0, 0, -state.distance)
        gl.glTranslatef(*state.translation)

        gl.glColor3f(0.5, 0.5, 0.5)
        gl.glPushMatrix()
        gl.glTranslatef(0, 0.5, 0.5)
        grid()
        gl.glPopMatrix()

        psz = max(window.get_size()) / float(max(w, h)) if state.scale else 1
        gl.glPointSize(psz)
        distance = (0, 0, 1) if state.attenuation else (1, 0, 0)
        gl.glPointParameterfv(gl.GL_POINT_DISTANCE_ATTENUATION,
                              (gl.GLfloat * 3)(*distance))

        if state.lighting:
            ldir = [0.5, 0.5, 0.5]  # world-space lighting
            ldir = np.dot(state.rotation, (0, 0, 1))  # MeshLab style lighting
            ldir = list(ldir) + [0]  # w=0, directional light
            gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, (gl.GLfloat * 4)(*ldir))
            gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE,
                         (gl.GLfloat * 3)(1.0, 1.0, 1.0))
            gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT,
                         (gl.GLfloat * 3)(0.75, 0.75, 0.75))
            gl.glEnable(gl.GL_LIGHT0)
            gl.glEnable(gl.GL_NORMALIZE)
            gl.glEnable(gl.GL_LIGHTING)

        gl.glColor3f(1, 1, 1)
        texture = image_data.get_texture()
        gl.glEnable(texture.target)
        gl.glBindTexture(texture.target, texture.id)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_NEAREST)

        # comment this to get round points with MSAA on
        gl.glEnable(gl.GL_POINT_SPRITE)

        if not state.scale and not state.attenuation:
            gl.glDisable(gl.GL_MULTISAMPLE)  # for true 1px points with MSAA on
        vertex_list.draw(gl.GL_POINTS)
        gl.glDisable(texture.target)
        if not state.scale and not state.attenuation:
            gl.glEnable(gl.GL_MULTISAMPLE)

        gl.glDisable(gl.GL_LIGHTING)

        gl.glColor3f(0.25, 0.25, 0.25)
        frustum(depth_intrinsics)
        axes()

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.glOrtho(0, width, 0, height, -1, 1)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        gl.glMatrixMode(gl.GL_TEXTURE)
        gl.glLoadIdentity()
        gl.glDisable(gl.GL_DEPTH_TEST)

        fps_display.draw()
Ejemplo n.º 39
0
        z = hmd.headPose.translation.z
        # print(x, y, z)

        # use OpenGL rendering commands here...

        # Just draw a triangle 2 meters away. Let's use the ovrMatrix4f type to
        # handle the translation. You can do whatever you like to the position
        # every frame.
        #
        triangle_origin = ovrVector3f(0.0, 0.0, -2.0)
        M = ovrMatrix4f.translation(triangle_origin)

        GL.glPushMatrix()
        GL.glMultMatrixf(M.ctypes)  # multiply the scene by the matrix
        GL.glBegin(GL.GL_TRIANGLES)
        GL.glColor3f(1, 0, 0)
        GL.glVertex3f(-1.0, -1.0, 0.0)
        GL.glColor3f(0, 1, 0)
        GL.glVertex3f(1.0, -1.0, 0.0)
        GL.glColor3f(0, 0, 1)
        GL.glVertex3f(0.0, 1.0, 0.0)
        GL.glEnd()
        GL.glPopMatrix()

    # send the rendered buffer to the HMD
    hmd.flip()

    # check if the application should exit
    if event.getKeys('q') or hmd.shouldQuit:
        stopApp = True
    elif event.getKeys('r') or hmd.shouldRecenter:
Ejemplo n.º 40
0
    def _display_movements(self, has_vbo):
        self.vertex_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, self.vertex_buffer.ptr)

        self.vertex_color_buffer.bind()
        glColorPointer(3, GL_FLOAT, 0, self.vertex_color_buffer.ptr)

        self.vertex_normal_buffer.bind()
        glNormalPointer(GL_FLOAT, 0, self.vertex_normal_buffer.ptr)

        self.index_buffer.bind()

        # Prevent race condition by using the number of currently loaded layers
        max_layers = self.layers_loaded

        start = 1
        layer_selected = self.num_layers_to_draw <= max_layers
        if layer_selected:
            end_prev_layer = self.layer_stops[self.num_layers_to_draw - 1]
        else:
            end_prev_layer = 0
        end = self.layer_stops[min(self.num_layers_to_draw, max_layers)]

        glDisableClientState(GL_COLOR_ARRAY)

        glColor3f(*self.color_printed[:-1])

        # Draw printed stuff until end or end_prev_layer
        cur_end = min(self.printed_until, end)
        if not self.only_current:
            if 1 <= end_prev_layer <= cur_end:
                self._draw_elements(1, end_prev_layer)
            elif cur_end >= 1:
                self._draw_elements(1, cur_end)

        glEnableClientState(GL_COLOR_ARRAY)

        # Draw nonprinted stuff until end_prev_layer
        start = max(cur_end, 1)
        if end_prev_layer >= start:
            if not self.only_current:
                self._draw_elements(start, end_prev_layer)
            cur_end = end_prev_layer

        # Draw current layer
        if layer_selected:
            glDisableClientState(GL_COLOR_ARRAY)

            glColor3f(*self.color_current_printed[:-1])

            if cur_end > end_prev_layer:
                self._draw_elements(end_prev_layer + 1, cur_end)

            glColor3f(*self.color_current[:-1])

            if end > cur_end:
                self._draw_elements(cur_end + 1, end)

            glEnableClientState(GL_COLOR_ARRAY)

        # Draw non printed stuff until end (if not ending at a given layer)
        start = max(self.printed_until, 1)
        if not layer_selected and end >= start:
            self._draw_elements(start, end)

        self.index_buffer.unbind()
        self.vertex_buffer.unbind()
        self.vertex_color_buffer.unbind()
        self.vertex_normal_buffer.unbind()
Ejemplo n.º 41
0
    def render(self, world_state, goals=[], time_step=None, wait=True):
        """"
        Renders the world state. Spawn a window if called for the first time.

        Parameters
        ----------

        world_state:
            state of the world as an instance of `roboball2d.physics.world_state.WorldState`
        
        goals:
            list of tuple (x1, x2, (r,g,b)). For each item, a goal will be 
            drawn on the ground, using the specified color

        time_step: 
             allows to force a frame rate by either;
             - having rendering waiting a suitable amount of time (wait=True)
             or
             - skipping some frames (wait=False)

        wait:
             see time_step above

        """

        if time_step is not None:

            # if wait : sleep the right amount of time such that the correct framerate is met
            # TODO: Does it make sense to wait before actually having rendered? This will result in a slower
            # framerate than desired. Should be right before self.window.flip()
            if wait:

                if self._t_last_frame is None:
                    sleep_time = 0.0
                else:
                    sleep_time = max(
                        0.0, time_step - (time.time() - self._t_last_frame))

                time.sleep(sleep_time)

                self._t_last_frame = time.time()

            # if not wait : skipping frame if required
            else:
                t = time.time()

                if self._t_last_frame is None:
                    self._t_last_frame = t

                if t - self._t_last_frame < time_step:
                    return

                self._t_last_frame = t

        if self.window is None:
            self.window = pyglet.window.Window(
                width=self.rendering_config.window.width,
                height=self.rendering_config.window.height,
                vsync=False,
                resizable=True)
            self.window.set_location(self.rendering_config.location[0],
                                     self.rendering_config.location[1])
            gl.glClearColor(*self.rendering_config.background_color)

            @self.window.event
            def on_resize(width, height):
                gl.glViewport(0, 0, width, height)
                gl.glMatrixMode(gl.GL_PROJECTION)
                gl.glLoadIdentity()
                gl.glOrtho(
                    0., self.rendering_config.visible_area_width,
                    -0.1 * float(height) / width *
                    self.rendering_config.visible_area_width,
                    0.9 * float(height) / width *
                    self.rendering_config.visible_area_width, -1., 1.)
                gl.glMatrixMode(gl.GL_MODELVIEW)
                return pyglet.event.EVENT_HANDLED

        self.window.clear()
        self.window.switch_to()
        self.window.dispatch_events()

        gl.glLoadIdentity()

        # balls
        if self.ball_configs:
            for ball, config in zip(world_state.balls, self.ball_configs):
                draw_ball(ball.position, ball.angle, config.radius, 16,
                          config.color, config.line_color)

        # robots
        for robot in world_state.robots:
            robot.render()

        gl.glBegin(gl.GL_QUADS)
        gl.glColor3f(*self.rendering_config.ground_color)
        gl.glVertex2f(0., 0.)
        gl.glVertex2f(0., -10.)
        gl.glVertex2f(self.rendering_config.visible_area_width, -10.)
        gl.glVertex2f(self.rendering_config.visible_area_width, 0.)
        gl.glEnd()

        # goals (if any)
        for goal in goals:
            x1, x2, color = goal
            draw_box(
                [(x1 + x2) / 2.0, -0.5 * self.rendering_config.visual_height],
                max(x1, x2) - min(x1, x2), self.rendering_config.visual_height,
                0., color)

        for callback in self._callbacks:
            callback(world_state)

        self.window.flip()
Ejemplo n.º 42
0
 def draw_notice(
     self, notice
 ):  # Elis: Function added to just have an arrow when car is coming.
     #if notice.condition: # then notice condition is fulfilled, so notify.
     if notice.name == 'maniac':
         if notice.info is not False and notice.info < 5 and notice.info > 0:  # old: notice.info <= 5 and notice.info >= 0:
             #if notice.have_played is False:
             #    notice.beep.play()
             #    notice.have_played = True
             sprite = self.obj_sprites['arrow%d' % np.ceil(notice.info)]
             sprite.x, sprite.y = -0.13, self.center()[1] + 0.85
             sprite.rotation = 0
             sprite.draw()
     elif notice.name == 'exit':
         exit_begins = notice.exit_begins
         W = notice.W
         U = notice.U
         gl.glColor3f(0.4, 0.4, 0.4)
         graphics.draw(4, gl.GL_QUAD_STRIP,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins + W),
                                   (0.13 / 2, exit_begins),
                                   (1, exit_begins + U + W),
                                   (1, exit_begins + U)])))
         gl.glColor3f(1, 1, 1)
         graphics.draw(2, gl.GL_LINES,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins + W),
                                   (1, exit_begins + U + W)])))
         graphics.draw(2, gl.GL_LINES, ('v2f',
                                        np.hstack([(0.13 / 2, exit_begins),
                                                   (1, exit_begins + U)])))
         # dashed lines (neater way to do this?)
         gl.glColor3f(0.4, 0.4, 0.4)
         graphics.draw(
             2,
             gl.GL_LINES,
             (
                 'v2f',
                 np.hstack([(0.13 / 2, exit_begins),
                            (0.13 / 2, exit_begins + W)
                            ])  # overwrite the usual white road lines.
             ))
         gl.glColor3f(1, 1, 1)
         graphics.draw(2, gl.GL_LINES,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins),
                                   (0.13 / 2, exit_begins + 0.05 * W)])))
         graphics.draw(2, gl.GL_LINES,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins + 0.1 * W),
                                   (0.13 / 2, exit_begins + 0.15 * W)])))
         graphics.draw(2, gl.GL_LINES,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins + 0.2 * W),
                                   (0.13 / 2, exit_begins + 0.25 * W)])))
         graphics.draw(2, gl.GL_LINES,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins + 0.3 * W),
                                   (0.13 / 2, exit_begins + 0.35 * W)])))
         graphics.draw(2, gl.GL_LINES,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins + 0.4 * W),
                                   (0.13 / 2, exit_begins + 0.45 * W)])))
         graphics.draw(2, gl.GL_LINES,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins + 0.5 * W),
                                   (0.13 / 2, exit_begins + 0.55 * W)])))
         graphics.draw(2, gl.GL_LINES,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins + 0.6 * W),
                                   (0.13 / 2, exit_begins + 0.65 * W)])))
         graphics.draw(2, gl.GL_LINES,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins + 0.7 * W),
                                   (0.13 / 2, exit_begins + 0.75 * W)])))
         graphics.draw(2, gl.GL_LINES,
                       ('v2f',
                        np.hstack([(0.13 / 2, exit_begins + 0.8 * W),
                                   (0.13 / 2, exit_begins + W)])))
         if notice.info is not False and notice.info < 5 and notice.info > 0:  # Here for exit.
             #if notice.have_played is False:
             #    notice.beep.play()
             #    notice.have_played = True
             sprite = self.obj_sprites['rarrow%d' % np.ceil(notice.info)]
             sprite.x, sprite.y = 0.13 + 0.13 / 4, self.center()[1] + 0.85
             sprite.roation = 0
             sprite.draw()
     elif notice.name == 'quit':
         if notice.info == 1 or notice.info == -1:  # the done.
             topic_program.paused = True
             initcond = notice.current_init_order[0]
             while True:
                 input_text = raw_input(
                     'Write your subject ID and trial number: ')
                 input_text = input_text.split()
                 if (len(input_text) == 2
                         and input_text[0] in notice.subject_list
                         and input_text[1] in notice.trial_list):
                     save = True
                     if input_text[1] == notice.trial_list[-1]:
                         # last trial so take next order for next subject.
                         # rotate list of orders for next subject.
                         notice.init_orders = notice.init_orders[
                             1:] + notice.init_orders[:1]
                         # get the first order for next subject (copies it to
                         # preserve the orginal one in case something goes wrong).
                         notice.current_init_order = copy.copy(
                             notice.init_orders[0])
                     else:
                         # rotate the current order for next trial.
                         notice.current_init_order = (
                             notice.current_init_order[1:] +
                             notice.current_init_order[:1])
                     break
                 elif len(input_text) == 1 and input_text[0] == 'dismiss':
                     # completely ignore this trial and continue.
                     save = False
                     break
                 elif len(input_text) == 1 and input_text[0] == 'skip':
                     # jump to next order without saving.
                     save = False
                     notice.init_orders = notice.init_orders[
                         1:] + notice.init_orders[:1]
                     notice.current_init_order = copy.copy(
                         notice.init_orders[0])
                     break
                 elif len(input_text) == 1 and input_text[0] == 'reset':
                     # reset to same original order (in case something went wrong).
                     save = False
                     notice.current_init_order = copy.copy(
                         notice.init_orders[0])
                     break
                 elif len(input_text) == 1 and input_text[0] == 'RESET':
                     # Reset the total list of orders and make current order the first.
                     save = False
                     notice.init_orders = copy.copy(
                         notice.original_init_order)
                     notice.current_init_order = copy.copy(
                         notice.init_orders[0])
                     break
                 else:
                     print('Wrong input format.')
                     print('Example of correct input formats:')
                     print('kth1 2')
                     print('ucb2 3')
                     print('Try again...')
             # if save:
             #     save_name = notice.scenario+'-initcond'+str(initcond)+'-'+input_text[0]+'-'+input_text[1]
             #     with open('data/'+input_text[0]+'/%s-%d.pickle'%(save_name, int(time.time())), 'w') as f:
             #         pickle.dump((topic_world.history, notice.info), f)
             self.reset()
Ejemplo n.º 43
0
        def on_draw(self):
            if (not self.e.period is None) and (not self.e.filename is None):
                if True:  #not os.path.isfile(self.e.filename):
                    if self.e.time() > self.e.period:
                        pyglet.app.exit()
            self.clear()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            #                     gluOrtho2D sets up a two-dimensional orthographic viewing region.
            #          Parameters left, right
            #                             Specify the coordinates for the left and right vertical clipping planes.
            #                         bottom, top
            #                             Specify the coordinates for the bottom and top horizontal clipping planes.
            #                         Description
            #         gl.gluOrtho2D(-(self.W-1)/2*self.e.total_width, (self.W+1)/2*self.e.total_width, -self.e.total_width/2, self.e.total_width/2, 0, 0, 1);
            self.W = float(self.width) / self.height
            gl.gluOrtho2D(-self.W / 2 * self.e.total_width,
                          self.W / 2 * self.e.total_width,
                          -self.e.total_width / 2, self.e.total_width / 2, 0,
                          0, 1)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()

            #gl.glLineWidth () #p['line_width'])
            gl.glEnable(gl.GL_BLEND)
            gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
            gl.glColor3f(0., 0., 0.)

            if self.first_frame:
                #                 print(self.e.t0, self.e.t)
                self.e.t0 = time.time()
                self.e.t = self.e.time()
                #                 print(self.e.t0, self.e.t)
                self.first_frame = False

            dt = self.e.time() - self.e.t
            if 1. / self.e.desired_fps - dt > 0.:
                time.sleep(1. / self.e.desired_fps - dt)

            self.e.receive()
            X, Y, Theta = self.e.lames[0, :], self.e.lames[1, :], self.e.lames[
                2, :]
            dX, dY = np.cos(Theta) / 2., np.sin(Theta) / 2.
            #print(Theta)
            # coords = np.vstack((X-dX*self.e.lame_length, Y-dY*self.e.lame_length, X+dX*self.e.lame_length, Y+dY*self.e.lame_length))
            coords = np.vstack((
                X - dX * self.e.lame_length + dY * self.e.lame_width,
                Y - dY * self.e.lame_length - dX * self.e.lame_width,
                X + dX * self.e.lame_length + dY * self.e.lame_width,
                Y + dY * self.e.lame_length - dX * self.e.lame_width,
                X - dX * self.e.lame_length - dY * self.e.lame_width,
                Y - dY * self.e.lame_length + dX * self.e.lame_width,
                X + dX * self.e.lame_length - dY * self.e.lame_width,
                Y + dY * self.e.lame_length + dX * self.e.lame_width,
            ))
            #pyglet.graphics.draw(2*self.e.N_lame, gl.GL_LINES, ('v2f', coords.T.ravel().tolist()))
            if True:
                indices = np.array([
                    0, 1, 2, 1, 2, 3
                ])[:, np.newaxis] + 4 * np.arange(self.e.N_lame)
                pyglet.graphics.draw_indexed(
                    4 * self.e.N_lame, pyglet.gl.GL_TRIANGLES,
                    indices.T.ravel().tolist(),
                    ('v2f', coords.T.ravel().tolist()))
                #pyglet.graphics.draw(4*self.e.N_lame, gl.GL_QUADS, ('v2f', coords.T.ravel().tolist()))

            # carré
            if self.e.DEBUG:
                coords = np.array([[
                    -.5 * self.e.total_width, .5 * self.e.total_width,
                    .5 * self.e.total_width, -.5 * self.e.total_width
                ],
                                   [
                                       -.5 * self.e.total_width,
                                       -.5 * self.e.total_width,
                                       .5 * self.e.total_width,
                                       .5 * self.e.total_width
                                   ]])
                pyglet.graphics.draw(4, gl.GL_LINE_LOOP,
                                     ('v2f', coords.T.ravel().tolist()))
            # centres des lames
            if self.e.DEBUG:
                gl.glLineWidth(1.)
                gl.glColor3f(0., 0., 0.)
                pyglet.graphics.draw(
                    self.e.N_lame, gl.GL_POINTS,
                    ('v2f', self.e.lames[:2, :].T.ravel().tolist()))
                gl.glColor3f(1., 0., 0.)
                pyglet.graphics.draw(2, gl.GL_LINES, ('v2f', [0., 0., 1., 0.]))
                gl.glColor3f(0., 1., 0.)
                pyglet.graphics.draw(2, gl.GL_LINES, ('v2f', [0., 0., 0., 1.]))

            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()

            self.label.draw()
            self.text.draw()
Ejemplo n.º 44
0
 def draw(self):
     super(AngleEditor, self).draw()
     if not self.dragging:
         gl.glColor3f(*SELECTED_COLOUR)
         self.protractor.draw()
         gl.glColor3f(*WHITE)
Ejemplo n.º 45
0
  def _render_img(self, width, height, multi_fbo, final_fbo, img_array, top_down=True):
    """
    Render an image of the environment into a frame buffer
    Produce a numpy RGB array image as output
    """

    if not self.graphics:
      return

    # Switch to the default context
    # This is necessary on Linux nvidia drivers
    # pyglet.gl._shadow_window.switch_to()
    self.shadow_window.switch_to()

    from pyglet import gl
    # Bind the multisampled frame buffer
    gl.glEnable(gl.GL_MULTISAMPLE)
    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, multi_fbo)
    gl.glViewport(0, 0, width, height)

    # Clear the color and depth buffers

    c0, c1, c2 = self.horizon_color
    gl.glClearColor(c0, c1, c2, 1.0)
    gl.glClearDepth(1.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    # Set the projection matrix
    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.gluPerspective(
      self.cam_fov_y,
      width / float(height),
      0.04,
      100.0
    )

    # Set modelview matrix
    # Note: we add a bit of noise to the camera position for data augmentation
    pos = self.cur_pos
    angle = self.cur_angle
    if self.domain_rand:
      pos = pos + self.randomization_settings['camera_noise']

    x, y, z = pos + self.cam_offset
    dx, dy, dz = self.get_dir_vec(angle)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    if self.draw_bbox:
      y += 0.8
      gl.glRotatef(90, 1, 0, 0)
    elif not top_down:
      y += self.cam_height
      gl.glRotatef(self.cam_angle[0], 1, 0, 0)
      gl.glRotatef(self.cam_angle[1], 0, 1, 0)
      gl.glRotatef(self.cam_angle[2], 0, 0, 1)
      gl.glTranslatef(0, 0, self._perturb(gym_duckietown.simulator.CAMERA_FORWARD_DIST))

    if top_down:
      gl.gluLookAt(
        # Eye position
        (self.grid_width * self.road_tile_size) / 2,
        self.top_cam_height,
        (self.grid_height * self.road_tile_size) / 2,
        # Target
        (self.grid_width * self.road_tile_size) / 2,
        0,
        (self.grid_height * self.road_tile_size) / 2,
        # Up vector
        0, 0, -1.0
      )
    else:
      gl.gluLookAt(
        # Eye position
        x,
        y,
        z,
        # Target
        x + dx,
        y + dy,
        z + dz,
        # Up vector
        0, 1.0, 0.0
      )

    # Draw the ground quad
    gl.glDisable(gl.GL_TEXTURE_2D)
    gl.glColor3f(*self.ground_color)
    gl.glPushMatrix()
    gl.glScalef(50, 1, 50)
    self.ground_vlist.draw(gl.GL_QUADS)
    gl.glPopMatrix()

    # Draw the ground/noise triangles
    self.tri_vlist.draw(gl.GL_TRIANGLES)

    # Draw the road quads
    gl.glEnable(gl.GL_TEXTURE_2D)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)

    # For each grid tile
    for j in range(self.grid_height):
      for i in range(self.grid_width):
        # Get the tile type and angle
        tile = self._get_tile(i, j)

        if tile is None:
          continue

        # kind = tile['kind']
        angle = tile['angle']
        color = tile['color']
        texture = tile['texture']

        gl.glColor3f(*color)

        gl.glPushMatrix()
        gl.glTranslatef((i + 0.5) * self.road_tile_size, 0, (j + 0.5) * self.road_tile_size)
        gl.glRotatef(angle * 90, 0, 1, 0)

        # Bind the appropriate texture
        texture.bind()

        self.road_vlist.draw(gl.GL_QUADS)
        gl.glPopMatrix()

        if self.draw_curve and tile['drivable']:
          # Find curve with largest dotproduct with heading
          curves = self._get_tile(i, j)['curves']
          curve_headings = curves[:, -1, :] - curves[:, 0, :]
          curve_headings = curve_headings / np.linalg.norm(curve_headings).reshape(1, -1)
          dirVec = get_dir_vec(angle)
          dot_prods = np.dot(curve_headings, dirVec)

          # Current ("closest") curve drawn in Red
          pts = curves[np.argmax(dot_prods)]
          bezier_draw(pts, n=20, red=True)

          pts = self._get_curve(i, j)
          for idx, pt in enumerate(pts):
            # Don't draw current curve in blue
            if idx == np.argmax(dot_prods):
                continue
            bezier_draw(pt, n=20)

    # For each object
    for idx, obj in enumerate(self.objects):
      obj.render(self.draw_bbox)

    # Draw the agent's own bounding box
    if self.draw_bbox:
      corners = get_agent_corners(pos, angle)
      gl.glColor3f(1, 0, 0)
      gl.glBegin(gl.GL_LINE_LOOP)
      gl.glVertex3f(corners[0, 0], 0.01, corners[0, 1])
      gl.glVertex3f(corners[1, 0], 0.01, corners[1, 1])
      gl.glVertex3f(corners[2, 0], 0.01, corners[2, 1])
      gl.glVertex3f(corners[3, 0], 0.01, corners[3, 1])
      gl.glEnd()

    if top_down:
      gl.glPushMatrix()
      gl.glTranslatef(*self.cur_pos)
      gl.glScalef(1, 1, 1)
      gl.glRotatef(self.cur_angle * 180 / np.pi, 0, 1, 0)
      # glColor3f(*self.color)
      self.mesh.render()
      gl.glPopMatrix()

    # Resolve the multisampled frame buffer into the final frame buffer
    gl.glBindFramebuffer(gl.GL_READ_FRAMEBUFFER, multi_fbo)
    gl.glBindFramebuffer(gl.GL_DRAW_FRAMEBUFFER, final_fbo)
    gl.glBlitFramebuffer(
      0, 0,
      width, height,
      0, 0,
      width, height,
      gl.GL_COLOR_BUFFER_BIT,
      gl.GL_LINEAR
    )

    # Copy the frame buffer contents into a numpy array
    # Note: glReadPixels reads starting from the lower left corner
    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, final_fbo)
    gl.glReadPixels(
      0,
      0,
      width,
      height,
      gl.GL_RGB,
      gl.GL_UNSIGNED_BYTE,
      img_array.ctypes.data_as(POINTER(gl.GLubyte))
    )

    # Unbind the frame buffer
    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)

    # Flip the image because OpenGL maps (0,0) to the lower-left corner
    # Note: this is necessary for gym.wrappers.Monitor to record videos
    # properly, otherwise they are vertically inverted.
    img_array = np.ascontiguousarray(np.flip(img_array, axis=0))

    return img_array

    def render_obs(self):
        """
        Render an observation from the point of view of the agent
        """

        observation = self._render_img(
                self.camera_width,
                self.camera_height,
                self.multi_fbo,
                self.final_fbo,
                self.img_array,
                top_down=True
        )

        # self.undistort - for UndistortWrapper
        if self.distortion and not self.undistort:
            observation = self.camera_model.distort(observation)

        return observation
Ejemplo n.º 46
0
 def draw(self):
     gl.glColor3f(*self.color)
     gl.glCallList(self.square)
     gl.glFlush()
Ejemplo n.º 47
0
Archivo: boid.py Proyecto: Entroc/Boid
 def render_velocity(self):
     glColor3f(0.6, 0.6, 0.6)
     glBegin(GL_LINES)
     glVertex2f(0.0, 0.0)
     glVertex2f(0.0, _BOID_RANGE)
     glEnd()
Ejemplo n.º 48
0
 def on_draw_(self):
     gl.glColor3f(0.25, 0.0, 1.0)
     with self._lock:
         self._vertex_list.draw(pyglet.gl.GL_LINE_STRIP)
Ejemplo n.º 49
0
 def draw_selected(self):
     gl.glColor3f(0, 1, 0)
     self.draw_component()
     gl.glColor3f(1, 1, 1)
Ejemplo n.º 50
0
 def render_velocity(self, b):
     glColor3f(0.6, 0.6, 0.6)
     glBegin(GL_LINES)
     glVertex2f(0.0, 0.0)
     glVertex2f(0.0, b.body.fustrum.radius)
     glEnd()
Ejemplo n.º 51
0
 def draw(self):
     gl.glColor3f(*self.color)
     gl.glBegin(self.primtype)
     for vert in self.verts:
         gl.glVertex2f(*vert)
     gl.glEnd()
Ejemplo n.º 52
0
def on_draw():
    window.clear()

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_LINE_SMOOTH)

    width, height = window.get_size()
    gl.glViewport(0, 0, width, height)

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.gluPerspective(60, width / float(height), 0.01, 20)

    gl.glMatrixMode(gl.GL_TEXTURE)
    gl.glLoadIdentity()
    # texcoords are [0..1] and relative to top-left pixel corner, add 0.5 to center
    gl.glTranslatef(0.5 / image_data.width, 0.5 / image_data.height, 0)
    # texture size may be increased by pyglet to a power of 2
    tw, th = image_data.texture.owner.width, image_data.texture.owner.height
    gl.glScalef(image_data.width / float(tw),
                image_data.height / float(th), 1)

    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    gl.gluLookAt(0, 0, 0, 0, 0, 1, 0, -1, 0)

    gl.glTranslatef(0, 0, state.distance)
    gl.glRotated(state.pitch, 1, 0, 0)
    gl.glRotated(state.yaw, 0, 1, 0)

    """ if any(state.mouse_btns):
        axes(0.1, 4) """

    gl.glTranslatef(0, 0, -state.distance)
    gl.glTranslatef(*state.translation)

    gl.glColor3f(0.5, 0.5, 0.5)
    gl.glPushMatrix()
    gl.glTranslatef(0, 0.5, 0.5)
    #grid()
    gl.glPopMatrix()

    psz = 1
    gl.glPointSize(psz)
    distance = (1, 0, 0)
    gl.glPointParameterfv(gl.GL_POINT_DISTANCE_ATTENUATION,
                          (gl.GLfloat * 3)(*distance))

    gl.glColor3f(1, 1, 1)
    texture = image_data.get_texture()
    gl.glEnable(texture.target)
    gl.glBindTexture(texture.target, texture.id)
    gl.glTexParameteri(
        gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)

    # comment this to get round points with MSAA on
    gl.glEnable(gl.GL_POINT_SPRITE)
    
    gl.glDisable(gl.GL_MULTISAMPLE)  # for true 1px points with MSAA on
    vertex_list.draw(gl.GL_POINTS)
    gl.glDisable(texture.target)
    gl.glEnable(gl.GL_MULTISAMPLE)

    gl.glDisable(gl.GL_LIGHTING)

    gl.glColor3f(0.25, 0.25, 0.25)
    #frustum(depth_intrinsics)
    #axes()

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.glOrtho(0, width, 0, height, -1, 1)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    gl.glMatrixMode(gl.GL_TEXTURE)
    gl.glLoadIdentity()
    gl.glDisable(gl.GL_DEPTH_TEST)
Ejemplo n.º 53
0
 def render(self, position, size, color):
     glColor3f(color[0], color[1], color[2])
     shapes.draw_circle(position, size)
Ejemplo n.º 54
0
 def set_state(self):
     gl.glPushAttrib(gl.GL_LINE_BIT | gl.GL_CURRENT_BIT)
     gl.glLineWidth(2)
     gl.glColor3f(1, 1, 1)
Ejemplo n.º 55
0
def line(x1, y1, x2, y2):
    gl.glBegin(gl.GL_LINES)
    gl.glColor3f(1.0, 1.0, 1.0)
    gl.glVertex2f(x1, y1)
    gl.glVertex2f(x2, y2)
    gl.glEnd()
Ejemplo n.º 56
0
 def render(self):
     gl.glColor3f(*self.color)
     gl.glVertex2f(self.x, self.y)
Ejemplo n.º 57
0
 def draw(self):
     Panel.draw(self)
     pic = self.pic
     glColor3f(1, 1, 1)
     self.pic.blit(self.width - pic.width - 10,
                   self.height - pic.height - 10)
Ejemplo n.º 58
0
 def draw(self):
     glColor3f(1, 1, 1)
     L('thb-tag-gameintro').blit(0, 0)
Ejemplo n.º 59
0
 def draw(self):
     glColor3f(1, 1, 1)
     self.texture.blit(0, 80)
     glColor4f(1, 1, 1, 0.65)
     glRectf(0, 0, self.width, self.ta_height)
     self.draw_subcontrols()
Ejemplo n.º 60
0
 def draw(self):
     gl.glCallList(self.list)
     gl.glColor3f(1.0, 1.0, 1.0)