Exemple #1
0
    def draw_obj(self,obj,_id,pos,circle,lines,attacked):
        # Кружок
        GL.glLoadIdentity()
        GL.glTranslatef(pos[0]-1,pos[1]-1,0)
        red,green,blue = obj.color # берём цвет
        GL.glColor3f(red,green,blue)
        GLU.gluDisk(self.quad,*circle)

        #Глазки
        GL.glColor3f(1-red,1-green,1-blue)
        try:
            eyes = obj.eyes
        except NameError:
            pass
        else:
            self.draw_eyes(obj.eyes.eyes,obj.radius * k_screen,obj.pos[1])
        # Прикосновения
        GL.glColor3f(1,0,0)
        try:
            sensitivity = obj.sensitivity
        except NameError:
            pass
        else:
            self.draw_sensitivity(obj.sensitivity._sens,obj.radius * k_screen,obj.pos[1])
        # Полосочки
        GL.glBegin(GL.GL_LINES)
        for color,x,y in lines:
            GL.glColor3f(*color)
            GL.glVertex3f(0,0,0)
            GL.glVertex3f(x,y,0)
        GL.glEnd()
Exemple #2
0
 def draw(self):
     y1, r1, y2, r2 = self.coords()
     if y1 > y2:
         tmp = y1
         y1 = y2
         y2 = tmp
         tmp = r1
         r1 = r2
         r2 = tmp
     GL.glPushMatrix()
     # GL creates cylinders along Z, so need to rotate
     z1 = y1
     z2 = y2
     GL.glRotatef(-90, 1, 0, 0)
     # need to translate the whole thing to z1
     GL.glTranslatef(0, 0, z1)
     # the cylinder starts out at Z=0
     GLU.gluCylinder(self.q, r1, r2, z2 - z1, 32, 1)
     # bottom cap
     GL.glRotatef(180, 1, 0, 0)
     GLU.gluDisk(self.q, 0, r1, 32, 1)
     GL.glRotatef(180, 1, 0, 0)
     # the top cap needs flipped and translated
     GL.glPushMatrix()
     GL.glTranslatef(0, 0, z2 - z1)
     GLU.gluDisk(self.q, 0, r2, 32, 1)
     GL.glPopMatrix()
     GL.glPopMatrix()
Exemple #3
0
    def _glcylinder(quadric, radius, height, slices, stacks, loops):
        """
        Internal method to render a quadric cylinder with OpenGL commands

        @param quadric  The OpenGL quadric object
        @param radius   The radius of the cylinder's base.
        @param height   The height of the cylunder.
        @param slices   The number of subdivisions around the z-axis (similar to lines of longitude).
        @param stacks   The number of subdivisions along the z-axis (similar to lines of latitude).
        @param loops    The number of concentric rings about the origin into which the cylinder's base is subdivided.
        """
        GLU.gluCylinder(quadric, radius, radius, height, slices, stacks)

        # The positive Z-axis is the default direction fo Cylinder Quadrics in OpenGL.
        # The top disc is 'height' units away from the origin.
        with GLMatrixScope(GL.GL_MODELVIEW, False):        
            GL.glTranslate(0, 0, height);
            GLU.gluDisk(quadric, 0.0, radius, slices, loops)
        
        # The positive Z-axis is the default direction for Cylinder Quadrics in OpenGL.
        # The base disc renders at the origin, but must be rotated to face the opposite
        # along the negative z axis.
        with GLMatrixScope(GL.GL_MODELVIEW, False):        
            GL.glRotate(180, 0, 1, 0)
            GLU.gluDisk(quadric, 0.0, radius, slices, loops)
 def render_cylinder(self, pos, r, h, num_seg1=20, num_seg2=10):
     GL.glPushMatrix()
     GL.glTranslated(*pos)
     GLU.gluCylinder(self.quadric, r, r, h, num_seg1, num_seg2)
     GL.glRotatef(180, 1, 0, 0)
     GLU.gluDisk(self.quadric, 0.0, r, num_seg1, 1)
     GL.glRotatef(180, 1, 0, 0)
     GL.glTranslatef(0.0, 0.0, h)
     GLU.gluDisk(self.quadric, 0.0, r, num_seg1, 1)
     GL.glPopMatrix()
Exemple #5
0
 def render_cylinder(self, pos, r, h, num_seg1=20, num_seg2=10):
     GL.glPushMatrix()
     GL.glTranslated(*pos)
     GLU.gluCylinder(self.quadric, r, r, h, num_seg1, num_seg2)
     GL.glRotatef(180, 1, 0, 0)
     GLU.gluDisk(self.quadric, 0.0, r, num_seg1, 1)
     GL.glRotatef(180, 1, 0, 0)
     GL.glTranslatef(0.0, 0.0, h)
     GLU.gluDisk(self.quadric, 0.0, r, num_seg1, 1)
     GL.glPopMatrix()
Exemple #6
0
 def to_OpenGL(self):
     if not GL_enabled:
         return
     GL.glPushMatrix()
     GL.glTranslate(self.center.x, self.center.y, self.center.z)
     if not hasattr(self, "_cylinder"):
         self._cylinder = GLU.gluNewQuadric()
     GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height,
             10, 10)
     if not hasattr(self, "_disk"):
         self._disk = GLU.gluNewQuadric()
     GLU.gluDisk(self._disk, 0, self.radius, 10, 10)
     GL.glPopMatrix()
Exemple #7
0
 def to_opengl(self):
     if not GL_enabled:
         return
     GL.glPushMatrix()
     GL.glTranslate(self.center[0], self.center[1], self.center[2])
     if not hasattr(self, "_cylinder"):
         self._cylinder = GLU.gluNewQuadric()
     GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height,
                     10, 10)
     if not hasattr(self, "_disk"):
         self._disk = GLU.gluNewQuadric()
     GLU.gluDisk(self._disk, 0, self.radius, 10, 10)
     GL.glPopMatrix()
Exemple #8
0
def drawCylinder(Start=np.array([0, 0, 0]),
                 End=np.array([1.0, 0.0, 0.0]),
                 Radius1=1.0,
                 Radius2=1.0,
                 Color=None):
    if type(Start) is not np.ndarray or type(End) is not np.ndarray:
        raise RuntimeError('Start and End need to be Numpy arrays.')

    Direction = End - Start
    Length = np.linalg.norm(Direction)
    if (Length <= 0.0):
        return
    Direction = Direction / Length

    # Find out the axis of rotation and angle of rotation to rotate the
    # gluCylinder (oriented along the z axis) into the desired direction
    Z = np.array([0., 0., 1.])
    Axis = np.cross(Z, Direction)
    Angle = math.acos(np.dot(Z, Direction)) * (180. / math.pi
                                               )  # Should be degrees

    gl.glPushMatrix()
    gl.glTranslate(Start[0], Start[1], Start[2])
    gl.glRotate(Angle, Axis[0], Axis[1], Axis[2])

    # Next the 6 faces
    if (Color != None):
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)  # Orig
        gl.glEnable(gl.GL_BLEND)

        gl.glColor4fv(Color)
    else:
        gl.glColor3f(0.0, 0.0, 0.0)

    # Draw cylinder
    # Bottom:
    glu.gluQuadricOrientation(QUADRIC, glu.GLU_INSIDE)
    glu.gluDisk(QUADRIC, 0, Radius1, 16, 1)

    glu.gluQuadricOrientation(QUADRIC, glu.GLU_OUTSIDE)
    glu.gluCylinder(QUADRIC, Radius1, Radius2, Length, 16, 1)

    # Top:
    gl.glTranslatef(0, 0, Length)
    glu.gluQuadricOrientation(QUADRIC, glu.GLU_OUTSIDE)
    glu.gluDisk(QUADRIC, 0, Radius2, 16, 1)

    gl.glPopMatrix()
Exemple #9
0
 def to_OpenGL(self):
     if not GL_enabled:
         return
     GL.glPushMatrix()
     GL.glTranslate(self.center[0], self.center[1], self.center[2])
     GLUT.glutSolidTorus(self.minorradius, self.majorradius, 10, 20)
     if not hasattr(self, "_cylinder"):
         self._cylinder = GLU.gluNewQuadric()
     GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height,
                     10, 20)
     GL.glPopMatrix()
     GL.glPushMatrix()
     GL.glTranslate(self.location[0], self.location[1], self.location[2])
     if not hasattr(self, "_disk"):
         self._disk = GLU.gluNewQuadric()
     GLU.gluDisk(self._disk, 0, self.majorradius, 20, 10)
     GL.glPopMatrix()
Exemple #10
0
 def to_OpenGL(self):
     if not GL_enabled:
         return
     GL.glPushMatrix()
     GL.glTranslate(self.center[0], self.center[1], self.center[2])
     GLUT.glutSolidTorus(self.minorradius, self.majorradius, 10, 20)
     if not hasattr(self, "_cylinder"):
         self._cylinder = GLU.gluNewQuadric()
     GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height,
             10, 20)
     GL.glPopMatrix()
     GL.glPushMatrix()
     GL.glTranslate(self.location[0], self.location[1], self.location[2])
     if not hasattr(self, "_disk"):
         self._disk = GLU.gluNewQuadric()
     GLU.gluDisk(self._disk, 0, self.majorradius, 20, 10)
     GL.glPopMatrix()
Exemple #11
0
def _caped_cylinder( radius, height, segments ):
    global __quadratic, __legocaptex
    GL.glPushMatrix()
    
    GL.glRotatef(-90, 1.0, 0.0, 0.0)
    GL.glTranslatef(0.0, 0.0, -height/2.0)
    
    #GLU.gluQuadricOrientation(__quadratic, GLU.GLU_INSIDE)
    #gluDisk(__quadratic,0,radius,segments,1)
    #GLU.gluQuadricOrientation(__quadratic, GLU.GLU_OUTSIDE)
    
    GLU.gluCylinder( __quadratic, radius, radius, height, segments, 1 )
    
    GL.glTranslatef( 0.0, 0.0, height )
    GL.glBindTexture( GL.GL_TEXTURE_2D, __legocaptex )
    GLU.gluDisk( __quadratic, 0, radius, segments,1 )
    GL.glBindTexture( GL.GL_TEXTURE_2D, 0 )
    
    GL.glPopMatrix()
Exemple #12
0
 def drawFlashLight(self):
     glPushMatrix()
     glRotate(-self.phi, 1.0, 0.0, 0.0)
     glRotate(-self.theta, 0.0, 1.0, 0.0)
     glTranslate(0, 0, 4)
     glMaterialfv(GL_FRONT, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0])
     glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.0, 0.0, 0.0, 1.0])
     glMaterialfv(GL_FRONT, GL_SPECULAR, [0.0, 0.0, 0.0, 1.0])
     glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 1.0, 0.0, 1.0])
     flashlight = GLU.gluNewQuadric()
     GLU.gluQuadricDrawStyle(flashlight, GLU.GLU_FILL)
     GLU.gluCylinder(flashlight, 0.3, 0.3, 1.5, 30, 30)
     GLU.gluCylinder(flashlight, 0.5, 0.3, 0.4, 30, 30)
     glPushMatrix()
     glTranslate(0, 0, 1.5)
     GLU.gluDisk(flashlight, 0.0, 0.3, 30, 30)
     glPopMatrix()
     glMaterialfv(GL_FRONT, GL_EMISSION, self.diffuse)
     GLU.gluDisk(flashlight, 0.0, 0.5, 30, 30)
     glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0, 1.0])
     glPopMatrix()
Exemple #13
0
    def reset(self):
        self.enable()
        GL.glClearStencil(0)
        GL.glClear(GL.GL_STENCIL_BUFFER_BIT)
        
        GL.glPushMatrix()
        GL.glTranslate(self.pos[0], self.pos[1], 0)

        GL.glDisable(GL.GL_LIGHTING)
        GL.glDisable(GL.GL_DEPTH_TEST)
        GL.glDepthMask(GL.GL_FALSE)
        
        GL.glStencilFunc(GL.GL_NEVER, 0, 0)
        GL.glStencilOp(GL.GL_INCR, GL.GL_INCR, GL.GL_INCR)
        GL.glColor3f(1.0,1.0,1.0)
        GL.glScalef(self.winAspect, 1.0, 1.0)
        GLU.gluDisk(self._quad, 0, self.size, 120, 2)
        GL.glStencilFunc(GL.GL_EQUAL, 1, 1)
        GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP)

        GL.glPopMatrix()
Exemple #14
0
 def drawFlashLight(self):
     glPushMatrix()
     glRotate(-self.phi, 1.0, 0.0, 0.0)
     glRotate(-self.theta, 0.0, 1.0, 0.0)
     glTranslate(0, 0, 4)
     glMaterialfv(GL_FRONT, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0])
     glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.0, 0.0, 0.0, 1.0])
     glMaterialfv(GL_FRONT, GL_SPECULAR, [0.0, 0.0, 0.0, 1.0])
     glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 1.0, 0.0, 1.0])
     flashlight = GLU.gluNewQuadric()
     GLU.gluQuadricDrawStyle(flashlight, GLU.GLU_FILL)
     GLU.gluCylinder(flashlight, 0.3, 0.3, 1.5, 30, 30)
     GLU.gluCylinder(flashlight, 0.5, 0.3, 0.4, 30, 30)
     glPushMatrix()
     glTranslate(0, 0, 1.5)
     GLU.gluDisk(flashlight, 0.0, 0.3, 30, 30)
     glPopMatrix()
     glMaterialfv(GL_FRONT, GL_EMISSION, self.diffuse)
     GLU.gluDisk(flashlight, 0.0, 0.5, 30, 30)
     glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0, 1.0])
     glPopMatrix()
Exemple #15
0
    def reset(self):
        self.enable()
        GL.glClearStencil(0)
        GL.glClear(GL.GL_STENCIL_BUFFER_BIT)

        GL.glPushMatrix()
        GL.glTranslate(self.pos[0], self.pos[1], 0)

        GL.glDisable(GL.GL_LIGHTING)
        GL.glDisable(GL.GL_DEPTH_TEST)
        GL.glDepthMask(GL.GL_FALSE)

        GL.glStencilFunc(GL.GL_NEVER, 0, 0)
        GL.glStencilOp(GL.GL_INCR, GL.GL_INCR, GL.GL_INCR)
        GL.glColor3f(1.0, 1.0, 1.0)
        GL.glScalef(self.winAspect, 1.0, 1.0)
        GLU.gluDisk(self._quad, 0, self.size, 120, 2)
        GL.glStencilFunc(GL.GL_EQUAL, 1, 1)
        GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP)

        GL.glPopMatrix()
    def render(self):

        # create openGL list if render has not yet been called
        if not self.has_rendered:
            w = self.width
            h = self.height
            color1 = self.color1
            color2 = self.color2
            board_width = w * self.nrows
            board_height = h * self.nrows
            #gl.glDisable(gl.GL_LIGHTING)

            self.glListIndex = gl.glGenLists(1)
            gl.glNewList(self.glListIndex, gl.GL_COMPILE) # begin OpengGL list
            try:
                for x in range(0, self.nrows):
                    for y in range(0, self.nrows):
                        if (x + y) % 2 == 0:
                            gl.glColor3f(*color1)
                        else:
                            gl.glColor3f(*color2)
                        gl.glRectf(w*x, h*y, w*(x + 1), h*(y + 1))

                if self.show_fixation_dot:
                    gl.glColor3f(*COLORS['red'])
                    gl.glTranslatef(board_width / 2.0, board_height / 2.0, 0)
                    glu.gluDisk(glu.gluNewQuadric(), 0, 0.005, 45, 1)

            finally:
                pass
                #gl.glEnable(gl.GL_LIGHTING)
            gl.glEndList()  # end OpenGL list
            self.has_rendered = True

        # display checkerboard
        gl.glDisable(gl.GL_LIGHTING)
        gl.glCallList(self.glListIndex)
        gl.glEnable(gl.GL_LIGHTING)
Exemple #17
0
 def draw(self):
     z1, r1, z2, r2 = self.coords()
     if z1 > z2:
         tmp = z1
         z1 = z2
         z2 = tmp
         tmp = r1
         r1 = r2
         r2 = tmp
     # need to translate the whole thing to z1
     GL.glPushMatrix()
     GL.glTranslatef(0, 0, z1)
     # the cylinder starts out at Z=0
     GLU.gluCylinder(self.q, r1, r2, z2 - z1, 32, 1)
     # bottom cap
     GL.glRotatef(180, 1, 0, 0)
     GLU.gluDisk(self.q, 0, r1, 32, 1)
     GL.glRotatef(180, 1, 0, 0)
     # the top cap needs flipped and translated
     GL.glPushMatrix()
     GL.glTranslatef(0, 0, z2 - z1)
     GLU.gluDisk(self.q, 0, r2, 32, 1)
     GL.glPopMatrix()
     GL.glPopMatrix()
Exemple #18
0
 def draw_cylinder(self, inside, outside, height, base_thickness):
     gl.glRotate(180, 0.0, 1.0, 0.0)
     glu.gluDisk(self.quad, 0, outside, 100, 5)
     gl.glRotate(-180, 0.0, 1.0, 0.0)
     gl.glTranslatef(0.0, 0.0, height)
     glu.gluDisk(self.quad, inside, outside, 100, 5)
     gl.glTranslatef(0.0, 0.0, -height)
     gl.glTranslatef(0.0, 0.0, base_thickness)
     glu.gluQuadricOrientation(self.quad, glu.GLU_INSIDE)
     glu.gluCylinder(self.quad, inside, inside, height - base_thickness, 100, 1)
     glu.gluQuadricOrientation(self.quad, glu.GLU_OUTSIDE)
     glu.gluDisk(self.quad, 0, inside, 100, 5)
     gl.glTranslatef(0.0, 0.0, -base_thickness)
     glu.gluCylinder(self.quad, outside, outside, height, 100, 1)
Exemple #19
0
 def draw_cylinder(self, inside, outside, height, base_thickness):
     gl.glRotate(180, 0.0, 1.0, 0.0)
     glu.gluDisk(self.quad, 0, outside, 100, 5)
     gl.glRotate(-180, 0.0, 1.0, 0.0)
     gl.glTranslatef(0.0, 0.0, height)
     glu.gluDisk(self.quad, inside, outside, 100, 5)
     gl.glTranslatef(0.0, 0.0, -height)
     gl.glTranslatef(0.0, 0.0, base_thickness)
     glu.gluQuadricOrientation(self.quad, glu.GLU_INSIDE)
     glu.gluCylinder(self.quad, inside, inside, height - base_thickness,
                     100, 1)
     glu.gluQuadricOrientation(self.quad, glu.GLU_OUTSIDE)
     glu.gluDisk(self.quad, 0, inside, 100, 5)
     gl.glTranslatef(0.0, 0.0, -base_thickness)
     glu.gluCylinder(self.quad, outside, outside, height, 100, 1)
    def render(self):
        color1 = self.color1
        color2 = self.color2

        # create display lists if not yet done
        if self.display_list_multi is None:
            w = self.check_width
            h = self.check_height
            board_width = w * self.nrows
            board_height = h * self.nrows

            # get needed display list ints
            if self.fixation_dot_color:
                self.num_lists = 3  # include list for fixation dot
            else:
                self.num_lists = 2
            self.display_list_multi = gl.glGenLists(self.num_lists)

            # Create a display list for color 1
            try:
                gl.glNewList(self.display_list_multi, gl.GL_COMPILE)

                # render the checkerboard's color1 checks
                gl.glDisable(gl.GL_LIGHTING)
                for x in range(0, self.nrows):
                    for y in range(0, self.nrows):
                        if (x + y) % 2 == 0:
                            gl.glRectf(w*x, h*y, w*(x + 1), h*(y + 1))
            finally:
                gl.glEnable(gl.GL_LIGHTING)
                # End the display list
                gl.glEndList()

            # create a display list for color 2
            try:
                gl.glNewList(self.display_list_multi + 1, gl.GL_COMPILE)

                # render the checkerboard's color2 checks
                gl.glDisable(gl.GL_LIGHTING)
                for x in range(0, self.nrows):
                    for y in range(0, self.nrows):
                        if (x + y) % 2 == 1:
                            gl.glRectf(w*x, h*y, w*(x + 1), h*(y + 1))
            finally:
                gl.glEnable(gl.GL_LIGHTING)
                # End the display list
                gl.glEndList()

            # create list for fixation dot
            if not self.fixation_dot_color is None:
                gl.glNewList(self.display_list_multi + 2, gl.GL_COMPILE)
                gl.glDisable(gl.GL_LIGHTING)
                r, g, b = self.fixation_dot_color
                gl.glColor3f(r, g, b)
                gl.glTranslatef(board_width / 2.0, board_height / 2.0, 0)
                glu.gluDisk(glu.gluNewQuadric(), 0, 0.005, 45, 1)
                gl.glEnable(gl.GL_LIGHTING)
                gl.glEndList()

            self.show_display_lists(color1, color2)

        else:
            # render display lists
            self.show_display_lists(color1, color2)