Esempio n. 1
0
class GLWidget(QGLWidget):
    def __init__(self, parent=None):
        super(GLWidget, self).__init__(parent)
        self.camera = MayaCamera()

    def initializeGL(self):
        glEnable(GL_DEPTH_TEST)

    def paintGL(self):
        # Clear the depth buffer
        glClear(GL_DEPTH_BUFFER_BIT)

        # Clear the screen with gradient
        drawGradient()

        # Setup camera
        glMatrixMode(GL_PROJECTION)
        glLoadMatrixf(self.camera.proj_matrix.data())
        glMatrixMode(GL_MODELVIEW)
        glLoadMatrixf(self.camera.view_matrix.data())

        # Draw a square
        glColor3f(0.8, 0.3, 0)
        glBegin(GL_QUADS)
        glVertex3f(-1, -1, 0)
        glVertex3f(1, -1, 0)
        glVertex3f(1, 1, 0)
        glVertex3f(-1, 1, 0)
        glEnd()

        # Tell the widget to redraw next time
        self.update()

    def resizeGL(self, width, height):
        glViewport(0, 0, width, height)
        self.camera.aspect = float(width) / height

    def mousePressEvent(self, event):
        self.last_pos = event.posF()

    def mouseMoveEvent(self, event):
        dxy = event.posF() - self.last_pos
        dx = dxy.x() / self.width()
        dy = dxy.y() / self.height()
        if event.buttons() & Qt.LeftButton:
            self.camera.rotate(dx, dy)
        elif event.buttons() & Qt.MidButton:
            self.camera.pan(dx, dy)
        elif event.buttons() & Qt.RightButton:
            self.camera.zoom(dx, dy)
        self.last_pos = event.posF()

    def wheelEvent(self, event):
        self.camera.zoom(event.delta() / 360.0, 0.0)
Esempio n. 2
0
class OrangeWidget(QtOpenGL.QGLWidget):
    def __init__(self, parent=None):
        super(OrangeWidget, self).__init__(parent)
        self.camera = MayaCamera()
        self.timer = QtCore.QTime()
        self.reset_fps()

    @property
    def fps(self):
        return 1000.0 * self.frames / max(1, self.timer.elapsed())

    def reset_fps(self):
        self.frames = 0
        self.timer.start()

    def cleanup(self):
        self.orange = None

    def initializeGL(self):
        self.cleanup()
        self.orange = Orange()
        self.orange.set_camera_xform(self.camera.view_matrix_inv.data())
        log.info('OpenGL %s' % glGetString(GL_VERSION))

    def paintGL(self):
        fb = self.orange.render()
        self.drawTexture(QtCore.QRectF(-1,-1,2,2), fb)
        glFinish()
        self.update()
        self.frames += 1

    def resizeGL(self, width, height):
        glViewport(0, 0, width, height)
        self.camera.aspect = float(width) / height

    def mousePressEvent(self, event):
        self.last_pos = event.posF()

    def mouseMoveEvent(self, event):
        dxy = event.posF() - self.last_pos
        dx = dxy.x() / self.width()
        dy = dxy.y() / self.height()
        if event.buttons() & QtCore.Qt.LeftButton:
            self.camera.rotate(dx, dy)
        elif (event.buttons() & Qt.MidButton) or event.modifiers():
            self.camera.pan(dx, dy)
        elif event.buttons() & QtCore.Qt.RightButton:
            self.camera.zoom(dx, dy)
        self.orange.set_camera_xform(self.camera.view_matrix_inv.data())
        self.last_pos = event.posF()

    def wheelEvent(self, event):
        self.camera.zoom(event.delta() / 360.0, 0.0)
        self.orange.set_camera_xform(self.camera.view_matrix_inv.data())
Esempio n. 3
0
class OrangeWidget(QtOpenGL.QGLWidget):
    def __init__(self, parent=None):
        super(OrangeWidget, self).__init__(parent)
        self.camera = MayaCamera()
        self.timer = QtCore.QTime()
        self.reset_fps()

    @property
    def fps(self):
        return 1000.0 * self.frames / max(1, self.timer.elapsed())

    def reset_fps(self):
        self.frames = 0
        self.timer.start()

    def cleanup(self):
        self.orange = None

    def initializeGL(self):
        self.cleanup()
        self.orange = Orange()
        self.orange.set_camera_xform(self.camera.view_matrix_inv.data())
        log.info('OpenGL %s' % glGetString(GL_VERSION))

    def paintGL(self):
        fb = self.orange.render()
        self.drawTexture(QtCore.QRectF(-1, -1, 2, 2), fb)
        glFinish()
        self.update()
        self.frames += 1

    def resizeGL(self, width, height):
        glViewport(0, 0, width, height)
        self.camera.aspect = float(width) / height

    def mousePressEvent(self, event):
        self.last_pos = event.posF()

    def mouseMoveEvent(self, event):
        dxy = event.posF() - self.last_pos
        dx = dxy.x() / self.width()
        dy = dxy.y() / self.height()
        if event.buttons() & QtCore.Qt.LeftButton:
            self.camera.rotate(dx, dy)
        elif (event.buttons() & QtCore.Qt.MidButton) or event.modifiers():
            self.camera.pan(dx, dy)
        elif event.buttons() & QtCore.Qt.RightButton:
            self.camera.zoom(dx, dy)
        self.orange.set_camera_xform(self.camera.view_matrix_inv.data())
        self.last_pos = event.posF()

    def wheelEvent(self, event):
        self.camera.zoom(event.delta() / 360.0, 0.0)
        self.orange.set_camera_xform(self.camera.view_matrix_inv.data())
Esempio n. 4
0
class GLWidget(QGLWidget):
    def __init__(self, parent=None):
        super(GLWidget, self).__init__(parent)
        self.camera = MayaCamera()

    def initializeGL(self):
        glEnable(GL_DEPTH_TEST)

    def paintGL(self):
        # Clear the depth buffer
        glClear(GL_DEPTH_BUFFER_BIT)

        # Clear the screen with gradient
        drawGradient()

        # Setup camera
        glMatrixMode(GL_PROJECTION)
        glLoadMatrixf(self.camera.proj_matrix.data())
        glMatrixMode(GL_MODELVIEW)
        glLoadMatrixf(self.camera.view_matrix.data())

        # Draw a square
        glColor3f(0.8, 0.3, 0)
        glBegin(GL_QUADS)
        glVertex3f(-1, -1, 0)
        glVertex3f(1, -1, 0)
        glVertex3f(1, 1, 0)
        glVertex3f(-1, 1, 0)
        glEnd()

        # Tell the widget to redraw next time
        self.update()

    def resizeGL(self, width, height):
        glViewport(0, 0, width, height)
        self.camera.aspect = float(width) / height

    def mousePressEvent(self, event):
        self.last_pos = event.posF()

    def mouseMoveEvent(self, event):
        dxy = event.posF() - self.last_pos
        dx = dxy.x() / self.width()
        dy = dxy.y() / self.height()
        if event.buttons() & Qt.LeftButton:
            self.camera.rotate(dx, dy)
        elif (event.buttons() & Qt.MidButton) or event.modifiers():
            self.camera.pan(dx, dy)
        elif event.buttons() & Qt.RightButton:
            self.camera.zoom(dx, dy)
        self.last_pos = event.posF()

    def wheelEvent(self, event):
        self.camera.zoom(event.delta() / 360.0, 0.0)
Esempio n. 5
0
class GLWidget(QGLWidget):
    def __init__(self, parent=None):
        super(GLWidget, self).__init__(parent)
        self.camera = MayaCamera()
        self.psys = ParticleSystem()

    def initializeGL(self):
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_POINT_SMOOTH)

    def paintGL(self):
        # Update the particle system
        self.psys.update()

        # Clear the screen
        glClear(GL_DEPTH_BUFFER_BIT)
        drawGradient()

        # Setup camera
        glMatrixMode(GL_PROJECTION)
        glLoadMatrixf(self.camera.proj_matrix.data())
        glMatrixMode(GL_MODELVIEW)
        glLoadMatrixf(self.camera.view_matrix.data())

        # Draw the particle system
        self.psys.draw()

        # Tell the widget to redraw next time
        self.update()

    def resizeGL(self, width, height):
        glViewport(0, 0, width, height)
        self.camera.aspect = float(width) / height

    def mousePressEvent(self, event):
        self.last_pos = event.posF()

    def mouseMoveEvent(self, event):
        dxy = event.posF() - self.last_pos
        dx = dxy.x() / self.width()
        dy = dxy.y() / self.height()
        if event.buttons() & Qt.LeftButton:
            self.camera.rotate(dx, dy)
        elif (event.buttons() & Qt.MidButton) or event.modifiers():
            self.camera.pan(dx, dy)
        elif event.buttons() & Qt.RightButton:
            self.camera.zoom(dx, dy)
        self.last_pos = event.posF()

    def wheelEvent(self, event):
        self.camera.zoom(event.delta() / 360.0, 0.0)
Esempio n. 6
0
class GLWidget(QGLWidget):
    def __init__(self, parent=None):
        super(GLWidget, self).__init__(parent)
        self.camera = MayaCamera()
        self.psys = ParticleSystem()

    def initializeGL(self):
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_POINT_SMOOTH)

    def paintGL(self):
        # Update the particle system
        self.psys.update()

        # Clear the screen
        glClear(GL_DEPTH_BUFFER_BIT)
        drawGradient()

        # Setup camera
        glMatrixMode(GL_PROJECTION)
        glLoadMatrixf(self.camera.proj_matrix.data())
        glMatrixMode(GL_MODELVIEW)
        glLoadMatrixf(self.camera.view_matrix.data())

        # Draw the particle system
        self.psys.draw()

        # Tell the widget to redraw next time
        self.update()

    def resizeGL(self, width, height):
        glViewport(0, 0, width, height)
        self.camera.aspect = float(width) / height

    def mousePressEvent(self, event):
        self.last_pos = event.posF()

    def mouseMoveEvent(self, event):
        dxy = event.posF() - self.last_pos
        dx = dxy.x() / self.width()
        dy = dxy.y() / self.height()
        if event.buttons() & Qt.LeftButton:
            self.camera.rotate(dx, dy)
        elif (event.buttons() & Qt.MidButton) or event.modifiers():
            self.camera.pan(dx, dy)
        elif event.buttons() & Qt.RightButton:
            self.camera.zoom(dx, dy)
        self.last_pos = event.posF()

    def wheelEvent(self, event):
        self.camera.zoom(event.delta() / 360.0, 0.0)