Esempio n. 1
0
 def rotate(self, ang, rx, ry, rz):
     glPushMatrix()
     glLoadIdentity()
     glRotatef(ang, rx, ry, rz)
     glMultMatrixf(self.matrix)
     self.matrix = get_model_matrix()
     glPopMatrix()
Esempio n. 2
0
    def set_3d(self):
        """ Configure OpenGL to draw in 3d.

        """
        width, height = self.get_size()

        gl.glEnable(gl.GL_DEPTH_TEST)

        gl.glViewport(0, 0, width, height)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.gluPerspective(65.0, width / float(height), 0.1, DIST)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        x, y = self.rotation
        gl.glRotatef(x, 0, 1, 0)
        gl.glRotatef(-y, math.cos(math.radians(x)), 0,
                     math.sin(math.radians(x)))
        x, y, z = self.position
        gl.glTranslatef(-x, -y, -z)

        gl.glEnable(gl.GL_LIGHTING)
        gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                          GLfloat4(0.05, 0.05, 0.05, 1.0))
        gl.glEnable(gl.GL_COLOR_MATERIAL)
        gl.glColorMaterial(gl.GL_FRONT, gl.GL_AMBIENT_AND_DIFFUSE)
        #gl.glLightfv(gl.GL_LIGHT1,gl.GL_SPOT_DIRECTION, GLfloat3(0,0,-1))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_AMBIENT, GLfloat4(0.5, 0.5, 0.5, 1.0))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, GLfloat4(1.0, 1.0, 1.0, 1.0))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION,
                     GLfloat4(0.35, 1.0, 0.65, 0.0))
        #gl.glLightfv(gl.GL_LIGHT0,gl.GL_SPECULAR, GLfloat4(1,1,1,1))
        gl.glDisable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_LIGHT1)
Esempio n. 3
0
    def draw(self, state = [0,0,0]):
        gl.glEnable (gl.GL_LINE_SMOOTH);                                                     
        gl.glHint (gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)     
        gl.glLoadIdentity()
        gl.glLineWidth(1)
        gl.glColor3f(.7,.7,.7)
        draw_rect((-.5,0), (.5,-.01))
        draw_rect((-.01,0),(.01,1))

        gl.glTranslatef(0,self.r_roller,0);

        gl.glPushMatrix();
        
        gl.glTranslatef(state[0]*self.r_roller, 0, 0)
        gl.glColor3f(0,0,0)
        gl.glLineWidth(3)
        
#        gl.glPushMatrix()
        gl.glRotatef(-R2D*state[0],0,0,1)
        draw_mass_center(self.r_roller, (0,0))
#        gl.glPopMatrix()

        gl.glRotatef(-R2D*state[1], 0, 0, 1)

        gl.glTranslatef(0,self.r_roller,0)
        
        gl.glPushMatrix()
        gl.glRotatef(R2D*(state[1]+state[0]),0,0,1)
        gl.glPushAttrib(gl.GL_ENABLE_BIT);
        gl.glColor3f(.7,.2,.2)
        gl.glLineStipple(1, 0xF00F)  # [1]
        gl.glEnable(gl.GL_LINE_STIPPLE)
        draw_line((0,0),(0,1))
        gl.glPopAttrib()
        gl.glPopMatrix()
        
        gl.glTranslatef(-state[1] * self.r_roller,0,0)
        
        gl.glColor3f(0,0,0)        
        draw_rect( (-self.l_board/2,0), (self.l_board/2,.02))
        gl.glColor3f(.5,.5,.5)
        draw_rect((-.01,0), (.01,self.h_body))

        gl.glPushMatrix()
        gl.glTranslatef(0, self.h_body, 0)
        gl.glRotatef(R2D*state[2], 0, 0, 1)
        gl.glColor3f(0,0,0);
        draw_mass_center(.1, (0,0))
        gl.glPopMatrix()

        if len(state) >= 8:
            gl.glPushMatrix()            
            gl.glTranslatef(0, self.h_body, 0)
            gl.glRotatef(R2D*state[3], 0, 0, 1)
            gl.glTranslatef(0, -self.h_body+self.r_roller+.05, 0)
            gl.glColor3f(0,0,0);
            draw_mass_center(.03, (0,0))
            gl.glPopMatrix()
        
        gl.glPopMatrix();
Esempio n. 4
0
    def drawSpace(self, window):

        gl.glPushMatrix()

        # GL matrices are applied last-added-first, so this *is* the right
        # order for pushing them.
        gl.glTranslatef(-self.viewportOrigin[0], -self.viewportOrigin[1], 0.0)

        if self.shake is not None:
            # We want to rotate around the center of the current viewport
            # vpc = view port center
            vpc_x = self.viewportOrigin[0] + self.windowProps.windowWidth//2
            vpc_y = self.viewportOrigin[1] + self.windowProps.windowHeight//2
            
            gl.glTranslatef(vpc_x, vpc_y, 0.0)
            gl.glRotatef(self.shake.getAngle(), 0, 0, 1)
            gl.glTranslatef(-vpc_x, -vpc_y, 0.0)
        
        ge = self.gameElements

        ge.starField.draw()
        ge.swarm.draw()

        if not self.explodedMarker.done():
            ge.ship.draw()

        if self.endGame and not self.drawFrameMarker.done():
            self.endGame.draw(window)

        for shot in ge.shots:
            if shot.alive:
                shot.draw()
        
        gl.glPopMatrix()
Esempio n. 5
0
    def transform(self):
        """
        Apply ModelView transformations.

        You will most likely want to wrap calls to this function with
        ``glPushMatrix()``/``glPopMatrix()``
        """
        x, y = director.get_window_size()

        if not (self.grid and self.grid.active):
            # only apply the camera if the grid is not active
            # otherwise, the camera will be applied inside the grid
            self.camera.locate()

        gl.glTranslatef(self.position[0], self.position[1], 0)
        gl.glTranslatef(self.transform_anchor_x, self.transform_anchor_y, 0)

        if self.rotation != 0.0:
            gl.glRotatef(-self._rotation, 0, 0, 1)

        if self.scale != 1.0 or self.scale_x != 1.0 or self.scale_y != 1.0:
            gl.glScalef(self._scale * self._scale_x,
                        self._scale * self._scale_y, 1)

        if self.transform_anchor != (0, 0):
            gl.glTranslatef(-self.transform_anchor_x, -self.transform_anchor_y,
                            0)
Esempio n. 6
0
    def render_labels(self):
        # Render for errors and labels of pins

        if not self.active and not self.hover:
            return

        if self.problem:
            self.er_label.x = self.x - self.cw - self.offset
            self.er_label.y = self.y
            self.er_label.draw()

        if self.hover:
            for label, put in zip(self.in_labels, self.put_pos(self.inputs)):
                gl.glPushMatrix()
                gl.glTranslatef(put['pos'], self.y + self.ch + 15, 0.0)
                gl.glRotatef(45.0, 0.0, 0.0, 1.0)
                label.draw()
                gl.glPopMatrix()

            for label, put in zip(self.out_labels, self.put_pos(self.outputs)):
                gl.glPushMatrix()
                gl.glTranslatef(put['pos'], self.y - self.ch - 20, 0.0)
                gl.glRotatef(45.0, 0.0, 0.0, 1.0)
                label.draw()
                gl.glPopMatrix()
Esempio n. 7
0
 def on_draw ():
     window.clear()
     gl.glLoadIdentity()
     gl.glTranslatef(0, -128, -512)
     gl.glRotatef(rotation[1],0,1,0)
     vertex_list.draw(gl.GL_LINES)
     window.invalid = False
Esempio n. 8
0
    def drawAgent(self, b):
        glPushMatrix()
        # apply the transformation for the boid
        glTranslatef(b.body.location.x / self.scaleFactor,
                     b.body.location.y / self.scaleFactor, 0.0)

        # a = signedAngle()
        glRotatef(
            math.degrees(math.atan2(b.body.velocity.x, b.body.velocity.y)),
            0.0, 0.0, -1.0)

        # render the boid's velocity
        if False:
            self.render_velocity(b)

        # render the boid's view
        if self.printFustrum:
            if b.type == "Taxi":
                self.render_view(b)
            elif b.type == "Client":
                if b.onboard != 1:
                    self.render_view(b)
        # render the boid itself
        self.render_agent(b)
        glPopMatrix()
Esempio n. 9
0
    def render(self):
        gl.glPushMatrix()

        gl.glTranslatef(self.x + self.width / 2, self.y + self.height / 2, 0)
        gl.glRotatef(self.angle, 0, 0, 1)
        gl.glTranslatef(-self.x - self.width / 2, -self.y - self.height / 2, 0)

        self.batch.draw()

        gl.glPopMatrix()

        gl.glPushMatrix()

        cx, cy, cw, ch = cannon_rects[0]

        gl.glTranslatef(self.x + cx + cw / 2, self.y + cy + ch / 2, 0)
        gl.glRotatef(self.cannon_angle - 90, 0, 0, 1)
        gl.glTranslatef(-self.x - cx - cw / 2, -self.y - cy, 0)

        self.cannon_batch.draw()

        gl.glPopMatrix()

        self.batch = pyglet.graphics.Batch()
        self.cannon_batch = pyglet.graphics.Batch()
Esempio n. 10
0
 def draw_ents(self, ents):
     for ent in ents:
         glPushMatrix()
         glTranslatef(ent.body.position.x, ent.body.position.y, 0)
         glRotatef(ent.body.angle * 180 / pi, 0, 0, 1)
         ent.batch.draw()
         glPopMatrix()
Esempio n. 11
0
 def rotate(self,ang,rx,ry,rz):
     glPushMatrix()
     glLoadIdentity()
     glRotatef(ang,rx,ry,rz)
     glMultMatrixf(self.matrix)
     self.matrix=get_model_matrix()
     glPopMatrix()
Esempio n. 12
0
def on_resize(width, height):
    pgl.glBlendFunc(pgl.GL_SRC_ALPHA, pgl.GL_ONE_MINUS_SRC_ALPHA)
    pgl.glViewport(0, 0, 400, 400)
    #pgl.glEnable(pgl.GL_CULL_FACE)
    pgl.glScalef(100, 100, 0.01)
    pgl.glTranslatef(2, 2, 2)
    pgl.glRotatef(10, 0, 0, 1)
Esempio n. 13
0
 def __enter__(self):
     gl.glPushMatrix()
     gl.glLoadIdentity()
     x, y = self.position
     gl.glTranslatef(self.w // 2, self.h // 2, 0)
     gl.glRotatef(degrees(self.angle), 0, 0, -1)
     gl.glTranslatef(-int(x), -int(y), 0)
Esempio n. 14
0
    def draw_objects(self):
        '''called in the middle of ondraw after the buffer has been cleared'''
        self.create_objects()

        glPushMatrix()
        if self.orthographic:
            glTranslatef(0, 0, -3 * self.dist)  # Move back
        else:
            glTranslatef(0, 0, -self.dist)  # Move back
        # Rotate according to trackball
        glMultMatrixd(build_rotmatrix(self.basequat))
        # Move origin to bottom left of platform
        platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2
        platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2
        glTranslatef(platformx0, platformy0, 0)

        for obj in self.parent.objects:
            if not obj.model \
               or not obj.model.loaded \
               or not obj.model.initialized:
                continue
            glPushMatrix()
            glTranslatef(*(obj.offsets))
            glTranslatef(*(obj.centeroffset))
            glRotatef(obj.rot, 0.0, 0.0, 1.0)
            glScalef(*obj.scale)

            obj.model.display()
            glPopMatrix()
        glPopMatrix()
Esempio n. 15
0
    def render(self, draw_bbox):
        """
        Renders the object to screen
        """
        if not self.visible:
            return

        from pyglet import gl

        # Draw the bounding box
        if draw_bbox:
            gl.glColor3f(1, 0, 0)
            gl.glBegin(gl.GL_LINE_LOOP)
            gl.glVertex3f(self.obj_corners.T[0, 0], 0.01,
                          self.obj_corners.T[1, 0])
            gl.glVertex3f(self.obj_corners.T[0, 1], 0.01,
                          self.obj_corners.T[1, 1])
            gl.glVertex3f(self.obj_corners.T[0, 2], 0.01,
                          self.obj_corners.T[1, 2])
            gl.glVertex3f(self.obj_corners.T[0, 3], 0.01,
                          self.obj_corners.T[1, 3])
            gl.glEnd()

        gl.glPushMatrix()
        gl.glTranslatef(*self.pos)
        gl.glScalef(self.scale, self.scale, self.scale)
        gl.glRotatef(self.y_rot, 0, 1, 0)
        gl.glColor3f(*self.color)
        self.mesh.render()
        gl.glPopMatrix()
Esempio n. 16
0
    def _setup_3d(self):
        w, h = self.get_size()
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glDepthFunc(gl.GL_LEQUAL)

        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_CULL_FACE)

        viewport = self.get_viewport_size()
        gl.glViewport(0, 0, max(1, viewport[0]), max(1, viewport[1]))

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.gluPerspective(*self.perspective)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        y, x = self.rotation
        gl.glRotatef(x, 0, 1, 0)
        gl.glRotatef(-y, math.cos(math.radians(x)), 0,
                     math.sin(math.radians(x)))
        # NOTE: for GL render, its x-z plane is the ground plane,
        # so we unpack the position using `(x, z, y)` instead of `(x, y, z)`
        x, z, y = self.position
        if not self.debug_mode:
            y += self.perspective_over_drone[0]
        z += self.perspective_over_drone[1]
        gl.glTranslatef(-x, -y, -z)
Esempio n. 17
0
def on_draw(*args):
    global time, particles

    t = time / FRAMES

    window.clear()

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.gluPerspective(90, 1, 0.1, 100)

    gl.glTranslatef(0, 0, -10)

    gl.glRotatef(t * 360, 0, 1, 0)
    # gl.glRotatef(t * 360, 1, 0, 0)

    batch = pyglet.graphics.Batch()

    if time == FRAMES:
        exit()

    points = []

    for i in range(K):
        points.append(gen_point((i + t) / K, i))

    # print(points)
    points_to_lines(points, batch)

    batch.draw()

    save_frame(time % FRAMES)
    time += 1
Esempio n. 18
0
    def render(self):
        """
        Draws Line
        """
        p1 = self.a2
        p2 = self.b2
        gl.glColor4f(*self.color)
        color = (gl.GLfloat * 4)(*self.color)

        gl.glPushMatrix()

        gl.glTranslatef(self.x, self.y, -self.z)  # translate to GL loc ppint
        gl.glRotatef(self.rotation, 0, 0, 0.1)

        if self.style:
            gl.glEnable(gl.GL_LINE_STIPPLE)
            gl.glLineStipple(1, self.style)


##        else :
##            glDisable(GL_LINE_STIPPLE)

        if self.stroke <= 0:
            self.stroke = 1
        gl.glLineWidth(self.stroke)

        gl.glBegin(gl.GL_LINES)
        gl.glVertex2i(int(p1[0]), int(p1[1]))  # draw pixel points
        gl.glVertex2i(int(p2[0]), int(p2[1]))
        gl.glEnd()

        if self.style:
            gl.glDisable(gl.GL_LINE_STIPPLE)

        gl.glPopMatrix()
Esempio n. 19
0
    def render(self, draw_bbox, annotated=False):
        """
        Renders the object to screen
        """
        if not self.visible:
            return

        from pyglet import gl

        # Draw the bounding box
        if draw_bbox:
            gl.glColor3f(1, 0, 0)
            gl.glBegin(gl.GL_LINE_LOOP)
            gl.glVertex3f(self.obj_corners.T[0, 0], 0.01,
                          self.obj_corners.T[1, 0])
            gl.glVertex3f(self.obj_corners.T[0, 1], 0.01,
                          self.obj_corners.T[1, 1])
            gl.glVertex3f(self.obj_corners.T[0, 2], 0.01,
                          self.obj_corners.T[1, 2])
            gl.glVertex3f(self.obj_corners.T[0, 3], 0.01,
                          self.obj_corners.T[1, 3])
            gl.glEnd()

        gl.glPushMatrix()
        gl.glTranslatef(*self.pos)
        gl.glScalef(self.scale, self.scale, self.scale)
        gl.glRotatef(self.y_rot, 0, 1, 0)
        gl.glColor3f(*self.color)

        annotated = annotated and self.on_driveable_tile
        if annotated and self.annotated_mesh is not None:
            self.annotated_mesh.render(annotated=annotated)
        else:
            self.mesh.render(annotated=annotated)
        gl.glPopMatrix()
Esempio n. 20
0
File: shapes.py Progetto: msarch/py
 def paint(self, peg):
     batch = self.get_batch()
     glPushMatrix()
     glTranslatef(peg.x, peg.y, 0)
     glRotatef(peg.angle, 0, 0, 1)
     batch.draw()
     glPopMatrix()
Esempio n. 21
0
    def draw_objects(self):
        '''called in the middle of ondraw after the buffer has been cleared'''
        self.create_objects()

        glPushMatrix()
        # Rotate according to trackball
        glMultMatrixd(build_rotmatrix(self.basequat))
        # Move origin to bottom left of platform
        platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2
        platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2
        glTranslatef(platformx0, platformy0, 0)

        for obj in self.parent.objects:
            if not obj.model \
               or not obj.model.loaded:
                continue
            # Skip (comment out) initialized check, which safely causes empty
            # model during progressive load. This can cause exceptions/garbage
            # render, but seems fine for now
            # May need to lock init() and draw_objects() together
            # if not obj.model.initialized:
            #     continue
            glPushMatrix()
            glTranslatef(*(obj.offsets))
            glRotatef(obj.rot, 0.0, 0.0, 1.0)
            glTranslatef(*(obj.centeroffset))
            glScalef(*obj.scale)

            obj.model.display()
            glPopMatrix()
        glPopMatrix()
Esempio n. 22
0
def nakresli_tank(x, y, rotace, barva):
    """Nakresli tank na dane pozici, s rotaci a v dane barve."""

    # Zacentruj kresleni na stred tela tanku.
    gl.glTranslatef(x, y, 0.0)

    # Aplikuj aktualni rotaci.
    gl.glRotatef(rotace, 0.0, 0.0, 1.0)

    # Nakresli telo tanku ve zvolene barve.
    gl.glColor3f(*barva)
    gl.glBegin(gl.GL_TRIANGLE_FAN)
    gl.glVertex2f(-TANK_SIRKA / 2, -TANK_DELKA / 2)
    gl.glVertex2f(-TANK_SIRKA / 2, +TANK_DELKA / 2)
    gl.glVertex2f(+TANK_SIRKA / 2, +TANK_DELKA / 2)
    gl.glVertex2f(+TANK_SIRKA / 2, -TANK_DELKA / 2)
    gl.glEnd()

    # Nakresli hlaven tanku ve standardni barve.
    gl.glColor3f(*BARVA_HLAVNE)
    gl.glBegin(gl.GL_TRIANGLE_FAN)
    gl.glVertex2f(-HLAVEN_SIRKA / 2, -HLAVEN_DELKA / 2 + HLAVEN_POSUN)
    gl.glVertex2f(-HLAVEN_SIRKA / 2, +HLAVEN_DELKA / 2 + HLAVEN_POSUN)
    gl.glVertex2f(+HLAVEN_SIRKA / 2, +HLAVEN_DELKA / 2 + HLAVEN_POSUN)
    gl.glVertex2f(+HLAVEN_SIRKA / 2, -HLAVEN_DELKA / 2 + HLAVEN_POSUN)
    gl.glEnd()

    # Vrat rotaci a centrovani do puvodniho stavu.
    gl.glRotatef(-rotace, 0.0, 0.0, 1.0)
    gl.glTranslatef(-x, -y, 0.0)
Esempio n. 23
0
 def draw(self):
     """Render the view object"""
     gl.glPushMatrix()
     gl.glTranslatef(self.x, self.y, 0)
     gl.glRotatef(self.angle, *self.axis)
     self.draw_aligned()
     gl.glPopMatrix()
Esempio n. 24
0
 def draw(self):
     """Render the particle."""
     gl.glPushMatrix()
     gl.glTranslatef(self.x, self.y, self.z)
     gl.glRotatef(self.angle, *self.axis)
     self.draw_aligned()
     gl.glPopMatrix()
Esempio n. 25
0
    def set_3d(self):
        """ Configure OpenGL to draw in 3d.

        """
        width, height = self.get_size()

        gl.glEnable(gl.GL_DEPTH_TEST)

        gl.glViewport(0, 0, width, height)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.gluPerspective(65.0, width / float(height), 0.1, DIST)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        x, y = self.rotation
        gl.glRotatef(x, 0, 1, 0)
        gl.glRotatef(-y, math.cos(math.radians(x)), 0, math.sin(math.radians(x)))
        x, y, z = self.position
        gl.glTranslatef(-x, -y, -z)

        gl.glEnable(gl.GL_LIGHTING)
        gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, GLfloat4(0.05,0.05,0.05,1.0))
        gl.glEnable(gl.GL_COLOR_MATERIAL)
        gl.glColorMaterial(gl.GL_FRONT, gl.GL_AMBIENT_AND_DIFFUSE)
        #gl.glLightfv(gl.GL_LIGHT1,gl.GL_SPOT_DIRECTION, GLfloat3(0,0,-1))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_AMBIENT, GLfloat4(0.5,0.5,0.5,1.0))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, GLfloat4(1.0,1.0,1.0,1.0))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, GLfloat4(0.35,1.0,0.65,0.0))
        #gl.glLightfv(gl.GL_LIGHT0,gl.GL_SPECULAR, GLfloat4(1,1,1,1))
        gl.glDisable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_LIGHT1)
Esempio n. 26
0
    def draw_objects(self):
        '''called in the middle of ondraw after the buffer has been cleared'''
        self.create_objects()

        glPushMatrix()
        # Rotate according to trackball
        glMultMatrixd(build_rotmatrix(self.basequat))
        # Move origin to bottom left of platform
        platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2
        platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2
        glTranslatef(platformx0, platformy0, 0)

        for obj in self.parent.objects:
            if not obj.model \
               or not obj.model.loaded \
               or not obj.model.initialized:
                continue
            glPushMatrix()
            glTranslatef(*(obj.offsets))
            glRotatef(obj.rot, 0.0, 0.0, 1.0)
            glTranslatef(*(obj.centeroffset))
            glScalef(*obj.scale)

            obj.model.display()
            glPopMatrix()
        glPopMatrix()
Esempio n. 27
0
    def render(self):
        """ Draw Circle
            x, y, z, width in pixel, rotation, color and line width in px
            style choices are : GLU_LINE, GLU_FILL, GLU_SILHOUETTE, GLU_POINT
            TO DO : textured circles
        """

        gl.glColor4f(*self.color)
        gl.glPushMatrix()

        gl.glTranslatef(self.x, self.y, -self.z)
        gl.glRotatef(*self.rotation)  #angle, bool per axis (x,y,z)

        if self.radius < 1: self.radius = 1

        if self.stroke:
            inner = self.radius - self.stroke  # outline width
            if inner < 0: inner = 0
        else:
            inner = 0  # filled

        gl.gluQuadricDrawStyle(self.q, self.style)

        gl.gluDisk(self.q, inner, self.radius, self.circleresolution,
                   1)  # gluDisk(quad, inner, outer, slices, loops)

        gl.glPopMatrix()
Esempio n. 28
0
    def render(self):
        gl.glPushMatrix()

        gl.glTranslatef(self.x + self.width / 2, self.y + self.height / 2, 0)
        gl.glRotatef(self.angle, 0, 0, 1)
        gl.glTranslatef(-self.x - self.width / 2, -self.y - self.height / 2, 0)

        self.batch.draw()

        gl.glPopMatrix()

        gl.glPushMatrix()

        cx, cy, cw, ch = cannon_rects[0]

        gl.glTranslatef(self.x + cx + cw / 2, self.y + cy + ch / 2, 0)
        gl.glRotatef(self.cannon_angle - 90, 0, 0, 1)
        gl.glTranslatef(-self.x - cx - cw / 2, -self.y - cy, 0)

        self.cannon_batch.draw()

        gl.glPopMatrix()

        self.batch = pyglet.graphics.Batch()
        self.cannon_batch = pyglet.graphics.Batch()
Esempio n. 29
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()
Esempio n. 30
0
def draw_ellipse_filled(center_x: float, center_y: float,
                        width: float, height: float, color: Color,
                        tilt_angle: float = 0):
    num_segments = 128

    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    gl.glEnable(gl.GL_LINE_SMOOTH)
    gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
    gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)

    gl.glLoadIdentity()
    gl.glTranslatef(center_x, center_y, 0)
    gl.glRotatef(tilt_angle, 0, 0, 1)

    # Set color
    if len(color) == 4:
        gl.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        gl.glColor4ub(color[0], color[1], color[2], 255)

    gl.glBegin(gl.GL_TRIANGLE_FAN)

    gl.glVertex3f(0, 0, 0.5)

    for segment in range(num_segments + 1):
        theta = 2.0 * 3.1415926 * segment / num_segments

        x = width * math.cos(theta)
        y = height * math.sin(theta)

        gl.glVertex3f(x, y, 0.5)

    gl.glEnd()
    gl.glLoadIdentity()
Esempio n. 31
0
 def display(self, width, height):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     gl.gluPerspective(60., width / float(height), .1, 1000.)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     gl.glTranslatef(self.trans[0], self.trans[1], self.trans[2])
     gl.glRotatef(self.rot[0], 1.0, 0.0, 0.0)
     gl.glRotatef(self.rot[1], 0.0, 1.0, 0.0)
     gl.glRotatef(self.rz, 0, 0, 1)
     gl.glRotatef(self.ry, 0, 1, 0)
     gl.glRotatef(self.rx, 1, 0, 0)
     gl.glEnable(gl.GL_LIGHTING)
     gl.glColor3f(1, 0, 0)
     self.torus.draw()
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     gl.glOrtho(0, width, 0, height, -1, 1)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     gl.glDisable(gl.GL_LIGHTING)
     gl.glColor3f(0, 1, 0)
     self.lowerlabel.text = 'Rx %.2f Ry %.2f Rz %.2f' % (self.rx, self.ry,
                                                         self.rz)
     self.lowerlabel.draw()
     self.upperlabel.text = time.strftime('Now is %H:%M:%S')
     self.upperlabel.x = width - self.upperlabel.content_width - 5
     self.upperlabel.y = height - self.upperlabel.content_height
     self.upperlabel.draw()
Esempio n. 32
0
def on_draw(*args):
    global time, particles

    t = time / FRAMES

    window.clear()

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.gluPerspective(90, 1, 0.1, 100)

    gl.glTranslatef(0, 0, -10)

    gl.glRotatef(t * 360, 0, 1, 0)

    batch = pyglet.graphics.Batch()

    if time == FRAMES:
        exit()

    points = np.empty((K, 3))

    for i in range(K):
        points[i] = gen_point((i + t) / K, i, t)

    # points = points.reshape(-1)
    # batch.add(len(points) // 3, pyglet.graphics.GL_POINTS, None, ("v3f", points))
    # print(points)
    points_to_lines(points, batch, 1.2)

    batch.draw()

    save_frame(time % FRAMES)
    time += 1
Esempio n. 33
0
def draw_text(text: str,
              start_x: float, start_y: float,
              color: Color,
              font_size: float = 12,
              width: int = 2000,
              align="left",
              font_name=('Calibri', 'Arial'),
              bold: bool = False,
              italic: bool = False,
              anchor_x="left",
              anchor_y="baseline",
              rotation=0
              ):
    if len(color) == 3:
        color = (color[0], color[1], color[2], 255)

    label = pyglet.text.Label(text,
                              font_name=font_name,
                              font_size=font_size,
                              x=0, y=0,
                              color=color,
                              multiline=True,
                              width=width,
                              align=align,
                              anchor_x=anchor_x,
                              anchor_y=anchor_y,
                              bold=bold,
                              italic=italic)
    gl.glLoadIdentity()
    gl.glTranslatef(start_x, start_y, 0)
    gl.glRotatef(rotation, 0, 0, 1)

    label.draw()
Esempio n. 34
0
    def render_cylinder(self,
                        base_radius,
                        height,
                        slices,
                        stacks,
                        top_radius=None):
        """ Generate the polygons for a cylinder

        :param base_radius: The radius of the bottom of the cylinder.
        :type base_radius: float
        :param height: The cylinder's height
        :type height: float
        :param slices: The number of longitudinal lines
        :type slices: int
        :param stacks: The number of latitudinal lines
        :type stacks: int
        :param top_radius: The radius of the top of the cylinder. If undefined,
         the top radius will be the same as the base radius
        :type top_radius: float
        """
        # rotate the cylinder so that it is drawn along the VPython axis
        # convention
        gl.glRotatef(90, 0, 1, 0)
        if top_radius is None:
            gl.glu.gluCylinder(self.quadric, base_radius, base_radius, height,
                               slices, stacks)
        else:
            gl.glu.gluCylinder(self.quadric, base_radius, top_radius, height,
                               slices, stacks)
        gl.glRotatef(-90, 0, 1, 0)
Esempio n. 35
0
 def update(self):
     self.ry += self.ryv
     gl.glPushMatrix()
     gl.glTranslatef(self.x, self.y, self.z)
     gl.glRotatef(self.ry, 0, 1, 0)
     self.vertex_list.draw(gl.GL_LINES)
     gl.glPopMatrix()
Esempio n. 36
0
 def paint(self, peg):
     glPushMatrix()
     glTranslatef(peg.x, peg.y, 0)
     glRotatef(peg.angle, 0, 0, 1)
     batch = self.get_batch()
     batch.draw()
     glPopMatrix()
Esempio n. 37
0
    def draw_objects(self):
        '''called in the middle of ondraw after the buffer has been cleared'''
        self.create_objects()

        glPushMatrix()
        # Rotate according to trackball
        glMultMatrixd(build_rotmatrix(self.basequat))
        # Move origin to bottom left of platform
        platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2
        platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2
        glTranslatef(platformx0, platformy0, 0)

        light_z = max(self.parent.platform.width, self.parent.platform.depth)
        glLightfv(GL_LIGHT0, GL_POSITION, vec(0,
                                              self.parent.platform.depth / 2,
                                              light_z, 0))
        glLightfv(GL_LIGHT1, GL_POSITION, vec(self.parent.platform.width,
                                              self.parent.platform.depth / 2,
                                              light_z, 0))

        for obj in self.parent.objects:
            if not obj.model \
               or not obj.model.loaded \
               or not obj.model.initialized:
                continue
            glPushMatrix()
            glTranslatef(*(obj.offsets))
            glTranslatef(*(obj.centeroffset))
            glRotatef(obj.rot, 0.0, 0.0, 1.0)
            glScalef(*obj.scale)

            obj.model.display()
            glPopMatrix()
        glPopMatrix()
Esempio n. 38
0
    def render_cylinder(self, base_radius, height, slices, stacks,
                        top_radius=None):
        """ Generate the polygons for a cylinder

        :param base_radius: The radius of the bottom of the cylinder.
        :type base_radius: float
        :param height: The cylinder's height
        :type height: float
        :param slices: The number of longitudinal lines
        :type slices: int
        :param stacks: The number of latitudinal lines
        :type stacks: int
        :param top_radius: The radius of the top of the cylinder. If undefined,
         the top radius will be the same as the base radius
        :type top_radius: float
        """
        # rotate the cylinder so that it is drawn along the VPython axis
        # convention
        gl.glRotatef(90, 0, 1, 0)
        if top_radius is None:
            gl.glu.gluCylinder(self.quadric, base_radius, base_radius,
                               height, slices, stacks)
        else:
            gl.glu.gluCylinder(self.quadric, base_radius, top_radius,
                               height, slices, stacks)
        gl.glRotatef(-90, 0, 1, 0)
Esempio n. 39
0
    def transform(self):
        """
        Apply ModelView transformations.

        You will most likely want to wrap calls to this function with
        ``glPushMatrix()``/``glPopMatrix()``
        """
        x, y = director.get_window_size()

        if not(self.grid and self.grid.active):
            # only apply the camera if the grid is not active
            # otherwise, the camera will be applied inside the grid
            self.camera.locate()

        gl.glTranslatef(self.position[0], self.position[1], 0)
        gl.glTranslatef(self.transform_anchor_x, self.transform_anchor_y, 0)

        if self.rotation != 0.0:
            gl.glRotatef(-self._rotation, 0, 0, 1)

        if self.scale != 1.0 or self.scale_x != 1.0 or self.scale_y != 1.0:
            gl.glScalef(self._scale * self._scale_x, self._scale * self._scale_y, 1)

        if self.transform_anchor != (0, 0):
            gl.glTranslatef(
                -self.transform_anchor_x,
                -self.transform_anchor_y,
                0)
Esempio n. 40
0
def rotate(p, state, kwargs):
    x, y = p.x, p.y
    xp = x + (p.width / 2)
    yp = y + (p.height / 2)
    gl.glTranslatef(xp, yp, 0)
    gl.glRotatef(kwargs['angle'], 0.0, 0.0, 1.0)
    gl.glTranslatef(-xp, -yp, 0)
Esempio n. 41
0
 def draw(self):
     glPushMatrix()
     glRotatef(self.angle, 0., 0., 1.)
     glScalef(self.scale, 1., 1.)
     glTranslatef(0., -common_res.ray.height/2, 0.)
     glColor4f(1., 1., 1., self.alpha)
     common_res.ray.blit(0, 0)
     glPopMatrix()
Esempio n. 42
0
 def draw(self, scale=1):
     gl.glPushMatrix()
     gl.glEnable(gl.GL_TEXTURE_2D)
     gl.glTranslatef(*self.position)
     gl.glRotatef(self.angle, 0, 0, 1)
     gl.glScalef(scale, scale, scale)
     self.batch.draw()
     gl.glPopMatrix()
Esempio n. 43
0
 def _draw_local(self):
     super(ShipPartConfigurationView, self)._draw_local()
     glPushMatrix()
     glRotatef(-self.yaw, 0, 1, 0)
     glRotatef(-90, 1, 0, 0)
     glScalef(0.025, 0.025, 0.025)
     self.infobox.draw()
     glPopMatrix()
Esempio n. 44
0
 def on_draw():
     window.clear()
     gl.glLoadIdentity()
     gl.gluLookAt(0, 8, 8, 0, 0, 0, 0, 1, 0)
     gl.glRotatef(rot, 1, 0, 0)
     gl.glRotatef(rot/2, 0, 1, 0)
     batch.draw()
     gl.glFinish()
Esempio n. 45
0
def rotate(f,
           angle,
           x=0.0, y=0.0, z=1.0):
    push()
    gl.glRotatef(angle * 180 / pi,
                 x, y, z)
    f()
    pop()
Esempio n. 46
0
 def draw_at(self, x, y):
     draw.set_color(1,1,1,1)
     for unit in self.units:
         ix, iy = x-unit.offset[1], y+unit.offset[0]
         gl.glPushMatrix()
         gl.glTranslatef(ix,iy,0)
         gl.glRotatef(unit.local_angle-90,0,0,-1)
         unit.image.blit(0,0)
         gl.glPopMatrix()
Esempio n. 47
0
 def draw(self):
     ray = L('c-ray')
     glPushMatrix()
     glRotatef(self.angle, 0., 0., 1.)
     glScalef(self.scale, 1., 1.)
     glTranslatef(0., -ray.height/2, 0.)
     glColor4f(1., 1., 1., self.alpha)
     ray.blit(0, 0)
     glPopMatrix()
Esempio n. 48
0
    def draw(self, win=None):
        
        #set the window to draw to
        if win==None: win=self.win
        if win.winType=='pyglet': win.winHandle.switch_to()
        
        #work out next default depth
        if self.depth==0:
            thisDepth = self.win._defDepth
            self.win._defDepth += _depthIncrements[self.win.winType]
        else:
            thisDepth=self.depth

        GL.glPushMatrix()

        #scale and rotate
        prevScale = self.win.setScale(self._winScale)
        GL.glTranslatef(self._posRendered[0],self._posRendered[1],thisDepth)#NB depth is set already
        GL.glRotatef(self.ori,0.0,0.0,1.0)
        self.win.setScale('pix',None, prevScale)
        
        if self._useShaders: #then rgb needs to be set as glColor
            #setup color
            desiredRGB = (self.rgb*self.contrast+1)/2.0#RGB in range 0:1 and scaled for contrast
            if numpy.any(desiredRGB**2.0>1.0):
                desiredRGB=[0.6,0.6,0.4]
            GL.glColor4f(desiredRGB[0],desiredRGB[1],desiredRGB[2], self.opacity)
        else: #color is set in texture, so set glColor to white
            GL.glColor4f(1,1,1,1)

        GL.glDisable(GL.GL_DEPTH_TEST) #should text have a depth or just on top?
        #update list if necss and then call it
        if self.win.winType=='pyglet':
            
            #and align based on x anchor
            if self.alignHoriz=='right':
                GL.glTranslatef(-self.width,0,0)#NB depth is set already
            if self.alignHoriz in ['center', 'centre']:
                GL.glTranslatef(-self.width/2,0,0)#NB depth is set already
                
            #unbind the mask texture regardless
            GL.glActiveTexture(GL.GL_TEXTURE1)
            GL.glEnable(GL.GL_TEXTURE_2D)
            GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
            #unbind the main texture
            GL.glActiveTexture(GL.GL_TEXTURE0)
            GL.glEnable(GL.GL_TEXTURE_2D)
            #then allow pyglet to bind and use texture during drawing
            
            self.glyphStr.draw()            
            GL.glDisable(GL.GL_TEXTURE_2D) 
        else: 
            #for pygame we should (and can) use a drawing list   
            if self.needUpdate: self._updateList()
            GL.glCallList(self._listID)
        GL.glEnable(GL.GL_DEPTH_TEST)                   # Enables Depth Testing
        GL.glPopMatrix()
Esempio n. 49
0
	def zoomAndRotate(self):
		"""Performs zooming and rotation. Suggested to use with pan during displazing the scene:
		1.cam.zoomAndRotate()
		2.cam.pan()
		3.draw(some 3D objects)
		"""
		glTranslatef(0, 0, -self.radius)
		glRotatef(self.psi - 90, 1, 0, 0)
		glRotatef(self.fi, 0, 0, 1)
Esempio n. 50
0
def draw_rectangle_outline(center_x, center_y, width, height, color,
                           border_width=1, tilt_angle=0):
    """
    Draw a rectangle outline.

    Args:
        :x: x coordinate of top left rectangle point.
        :y: y coordinate of top left rectangle point.
        :width: width of the rectangle.
        :height: height of the rectangle.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
        :border_width: width of the lines, in pixels.
        :angle: rotation of the rectangle. Defaults to zero.
    Returns:
        None
    Raises:
        None

    Example:

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> arcade.draw_rectangle_outline(278, 150, 45, 105, \
arcade.color.BRITISH_RACING_GREEN, 2)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """

    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)

    GL.glLoadIdentity()
    GL.glTranslatef(center_x, center_y, 0)
    if tilt_angle:
        GL.glRotatef(tilt_angle, 0, 0, 1)

    # Set line width
    GL.glLineWidth(border_width)

    # Set color
    if len(color) == 4:
        GL.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        GL.glColor4ub(color[0], color[1], color[2], 255)

    GL.glBegin(GL.GL_LINE_LOOP)
    GL.glVertex3f(-width // 2, -height // 2, 0.5)
    GL.glVertex3f(width // 2, -height // 2, 0.5)
    GL.glVertex3f(width // 2, height // 2, 0.5)
    GL.glVertex3f(-width // 2, height // 2, 0.5)
    GL.glEnd()
Esempio n. 51
0
File: shapes.py Progetto: msarch/py
 def paint(self):
     if self.batch is None:
         self.get_batch()
     glPushMatrix()
     glTranslatef(self.peg.x, self.peg.y, self.peg.z)
     glRotatef(self.peg.angle, 0, 0, 1)
     self.batch.draw()
     glPopMatrix()
     print'.',
Esempio n. 52
0
 def draw_axis_label( name, xyz):
     'draw a single label'
     gl.glPushMatrix()
     gl.glTranslatef( xyz[0], xyz[1], xyz[2] )
     gl.glScalef( .01, .01, .01 )
     gl.glRotatef( 90, 0, 1, 0 )
     gl.glRotatef( 90, 0, 0, 1 )
     pyglet.text.Label(name).draw()
     gl.glPopMatrix()
Esempio n. 53
0
File: shapes.py Progetto: msarch/py
 def paint(self):
     if self.drawable:
         glPushMatrix()
         glTranslatef(self.posx, self.posy, 0)
         glRotatef(self.angle, 0, 0, 1)
         batch = self.get_batch()
         batch.draw()
         glPopMatrix()
     else:
         print 'cell', self, 'is not drawable'
Esempio n. 54
0
File: shape.py Progetto: msarch/py
 def paint(self):
     for sh in self.get_instances(self):
         if sh.batch is None:
             sh.get_batch()
         glPushMatrix()
         glTranslatef(sh.peg.x, sh.peg.y, sh.peg.z)
         glRotatef(sh.peg.angle, 0, 0, 1)
         sh.batch.draw()
         glPopMatrix()
         print'.',
Esempio n. 55
0
File: shapes.py Progetto: msarch/py
 def paint(self):
     print ':: displaying C-Shape :', self
     batch = self.get_batch()
     glPushMatrix()
     glTranslatef(self.peg.x, self.peg.y, 0)
     glRotatef(self.peg.angle, 0, 0, 1)
     batch.draw()
     # OPTIMISATION : cs.batch.draw() directement avec batch déjà à jour TODO
     glPopMatrix()
     print ''
Esempio n. 56
0
File: shape.py Progetto: msarch/py
 def gl_output(self):
     for sh in self.yeld_simple_shapes(self):
         if sh.batch is None:
             sh.get_batch()
         glPushMatrix()
         glTranslatef(sh.peg.x, sh.peg.y, 0)
         glRotatef(sh.peg.angle, 0, 0, 1)
         sh.batch.draw()
         print ('.'),
         glPopMatrix()
Esempio n. 57
0
 def on_draw(self):
     rendr_components, trans_components = self.entity_manager.get_all_components_of_types([Render, Transform])
     
     for render, trans in zip(rendr_components, trans_components):
         gl.glPushMatrix()
         gl.glTranslatef(trans.x, trans.y, 0.0)
         gl.glRotatef(trans.rotation, 0, 0, 1)
         gl.glScalef(trans.scale, trans.scale, 1.0)
         render.image.blit(trans.anchor_x, trans.anchor_y)
         gl.glPopMatrix()
Esempio n. 58
0
File: shapes.py Progetto: msarch/py
 def paint(self):
     if self.batch is None:
         self.get_batch()
     glPushMatrix()
     glTranslatef(self.peg.x, self.peg.y, self.peg.z)
     glRotatef(self.peg.angle, 0, 0, 1)
     self.batch.draw()
     # OPTIMISATION : cs.batch.draw() directement avec batch déjà à jour TODO
     glPopMatrix()
     print '+',
Esempio n. 59
0
 def draw(self):
   #print self.body.postion
   s = self.size # just a shorthand
   gl.glColor4f(*(self.colour + (self.opacity,)))
   with shiftView(Vec2d(self.body.position)):
     gl.glRotatef(degrees(self.body.angle), 0.1,0.2,1.0)
     gl.glBegin(gl.GL_POLYGON)
     for vertex in self.verticies:
       gl.glVertex2f(*vertex)
     gl.glEnd()