Exemple #1
0
    def on_resize(self, width, height):
        # Override the default on_resize handler to create a 3D projection
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(60., width / float(height), .1, 1000.)
        
        glMatrixMode(GL_MODELVIEW)
        
        self.rotspeed = 45 # degrees per second
        
        from ArcBall import ArcBallT
        self.arcball = ArcBallT(width, height)

        return pyglet.event.EVENT_HANDLED
Exemple #2
0
class AppWindow(Window):

    def __init__(self, *args, **kwargs):
        clock.schedule(self.update)
        self.autoRun = False
        #self.autoRun = True
        self.translatex = self.translatey = 0
        self.rotx = 0
        self.depthtarget = self.depth = -7
        super(AppWindow, self).__init__(*args,**kwargs)
    
    def on_resize(self, width, height):
        # Override the default on_resize handler to create a 3D projection
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(60., width / float(height), .1, 1000.)
        
        glMatrixMode(GL_MODELVIEW)
        
        self.rotspeed = 45 # degrees per second
        
        from ArcBall import ArcBallT
        self.arcball = ArcBallT(width, height)

        return pyglet.event.EVENT_HANDLED

    def on_key_press(self, symbol, modifier):
        global counter
        
        if symbol == key.ESCAPE:
            pyglet.app.exit()
            
        elif symbol == key.SPACE:
            self.autoRun = not self.autoRun
            
        elif symbol == key.LEFT:
            
            counter -= 1
            update_vlist()
            
        elif symbol == key.RIGHT:
            
            counter += 1
            update_vlist()
        
    def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
        self.depthtarget += scroll_y / 4
        
    def on_mouse_press(self, x, y, button, modifiers):
        if button == mouse.RIGHT:
            self.arcball.reset()
        
        elif button == mouse.LEFT:
            self.arcball.click((x, y))
        
    def on_mouse_release(self, x, y, button, modifiers):
        if button != mouse.LEFT: return
        
        self.arcball.release()

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        if buttons & mouse.MIDDLE:
            self.translatex += dx / 50
            self.translatey += dy / 50
            return
            
        if not buttons & mouse.LEFT: 
            return
        
        self.arcball.move((x, y))
    
    def update(self, dt):
        if abs(self.depth - self.depthtarget) > 1e-4:
            self.depth += (self.depthtarget - self.depth) / 2
        
        if not self.autoRun:
            return
            
        self.rotx += dt * self.rotspeed
        
        if self.rotx > 360:
            
            global counter
            counter += 1
            update_vlist()
            
            self.rotx = 0

    def makeLabel(self, text):
        return Label(text, font_name='Times New Roman', font_size=20, anchor_x='center')

    def on_draw(self):
         
        glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA)

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        
        glTranslate(self.translatex, self.translatey, self.depth)
        
        if self.autoRun:
            glRotate(self.rotx,  0, 1, 0)
        
        else:
            # Perform arcball rotation.
            glScale(1,-1,1)
            glMultMatrixf(self.arcball.transform)
            glScale(1,-1,1)
        
        with displayListify("cubeTranslate") as shouldLeave:
            if shouldLeave: raise LeaveWith
                
            # Scale the co-ordinates so that they are correct
            glScale(2/128, 2/128, 2/128)
            
            glColor(0.25, 0.25, 0.25, 1)
            glutWireCube(255)
            
            glTranslate(-128, -128, -128)
        
        with displayListify("allPoints") as shouldLeave:
            if shouldLeave: raise LeaveWith
            
            with SaveMatrix():
                # Flip the co-ordinates and translate upwards
                glScale(1,-1,1)
                glColor(0.25, 0.25, 0.25, 0.5)
                glTranslate(0,-255,0)
                glPointSize(pointSize)
                for dat in reversed(vLists):
                    glTranslate(0., 0., 1./nChunks*255)
                    dat.draw(GL_POINTS)

        with displayListify("axisLabels") as shouldLeave:
            if shouldLeave: raise LeaveWith
        #if True:
            with SaveMatrix():
                glTranslate(128,0,0)
                self.makeLabel("End").draw()
                
                glTranslate(0,0,255)
                self.makeLabel("Beginning").draw()
                
                with SaveMatrix():
                    glTranslate(-128,128,0)
                    glRotate(90,0,0,1)
                    self.makeLabel("Byte 1").draw()
                
                glTranslate(0,255,0)
                self.makeLabel("Byte 2").draw()
        
        with displayListify("fileName") as shouldLeave:
            if shouldLeave: raise LeaveWith
            glLoadIdentity()
            
            with SaveMatrix():
                glColor(1,0,0)
                glTranslate(0,-2.2,-4)
                glScale(1/64, 1/64, 1/64)
                l = self.makeLabel(basename(currentInputFile))
                l.color = (0, 128, 230, 255)
                l.draw()
        
        glTranslate(0,0,-1)
        
        if self.autoRun:
        
            if self.rotx > 360 - 45:
                vlist = vertex_list(4, ('v2i', (-1, -1, 1, -1, 1, 1, -1, 1)))
                glColor(0,0,0,(self.rotx-(360-45))/45)
                vlist.draw(GL_QUADS)
                
            if self.rotx < 45:
                vlist = vertex_list(4, ('v2i', (-1, -1, 1, -1, 1, 1, -1, 1)))
                glColor(0,0,0,1-(self.rotx/45))
                vlist.draw(GL_QUADS)