Ejemplo n.º 1
1
    def onRender(self):
        gl.glDepthMask(gl.GL_TRUE)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45, self.width / self.height, 0.01, 80.0)

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

        gl.glTranslated(0.0, 0.0, -self.camPosZ)  # apply camera zooming
        gl.glRotated(self.angleX, 1.0, 0.0, 0.0)  # apply camera rotation
        gl.glRotated(self.angleY, 0.0, 1.0, 0.0)

        # draw fountain
        if self.renderEnv:
            gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE,
                         gl.GL_MODULATE)
            gl.glCallList(self.DISPLAY_LIST_OBJECT)

            gl.glMatrixMode(gl.GL_TEXTURE)

            # scroll water texture
            angle = self.totalTime * 2.0 * math.pi / 12000.0
            sinA = math.sin(angle) * 0.2
            cosA = math.cos(angle) * 0.2

            gl.glRotatef(angle, 0.0, 0.0, 1.0)
            gl.glTranslatef(sinA, cosA, 1.0)
            gl.glScalef(1.0 + sinA * 0.2, 1.0 + cosA * 0.2, 1.0)

        # draw bounding box(F2 key)
        drawBoundingBox(self.group, 1.0, 0.0, 0.0)

        # draw fountain water
        if self.renderEnv:
            gl.glCallList(self.DISPLAY_LIST_WATER)
            gl.glLoadIdentity()

        # draw particles
        self.system.render()

        # draw texts(F1 key)
        if not notext and self.text != 0:
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluOrtho2D(0, self.width, 0, self.height)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glColor3d(1.0, 1.0, 1.0)
            if self.text == 2:
                self.drawText(self.nbParticles, 4.0, 40.0)
            self.drawText(self.fps, 4.0, 8.0)

        # refresh
        sdl2.SDL_GL_SwapWindow(self.window)
Ejemplo n.º 2
0
    def onRender(self):
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45, self.width / self.height, 0.01, 80.0)

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

        gl.glTranslated(0.0, 0.0, -self.camPosZ)  # apply camera zooming
        gl.glRotated(self.angleX, 1.0, 0.0, 0.0)  # apply camera rotation
        gl.glRotated(self.angleY, 0.0, 1.0, 0.0)

        # draw obstacles
        if self.renderEnv:
            gl.glDisable(gl.GL_BLEND)
            gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE,
                         gl.GL_MODULATE)
            gl.glCallList(self.DISPLAY_LIST_WORLD)

        # draw bounding box(F2 key)
        drawBoundingBox(self.group, 1.0, 0.0, 0.0)

        # draw outlines of the boxes(F6 key)
        if self.enableBoxDrawing:
            for box in self.boxes:  # blue for crates
                drawBox(box.getPosition() - box.getDimension() * 0.5,
                        box.getPosition() + box.getDimension() * 0.5, 0.0, 0.0,
                        1.0)
            for box in self.partitions:  # green for partitions
                drawBox(box.getPosition() - box.getDimension() * 0.5,
                        box.getPosition() + box.getDimension() * 0.5, 0.0, 1.0,
                        0.0)

        # draw particles
        gl.glDisable(gl.GL_LIGHTING)
        self.system.render()

        # draw texts(F1 key)
        if not notext and self.text != 0:
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluOrtho2D(0, self.width, 0, self.height)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glColor3d(1.0, 1.0, 1.0)
            if self.text == 2:
                self.drawText(self.nbParticles, 4.0, 40.0)
            self.drawText(self.fps, 4.0, 8.0)

        # refresh
        sdl2.SDL_GL_SwapWindow(self.window)
Ejemplo n.º 3
0
    def onRender(self):
        gl.glDepthMask(gl.GL_TRUE)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45, self.width / self.height, 0.01, 33.0)

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

        gl.glTranslated(0.0, 0.0, -self.camPosZ)  # apply camera zooming
        gl.glRotated(self.angleX, 1.0, 0.0, 0.0)  # apply camera rotation
        gl.glRotated(self.angleY, 0.0, 1.0, 0.0)

        # draw particles
        self.galaxySystem.render()
        if self.renderEnv:
            self.starSystem.render()

        # draw bounding box(F2 key)
        gl.glDisable(gl.GL_BLEND)
        drawBoundingBox(self.galaxyGroup, 1.0, 0.0, 0.0)

        # draw texts(F1 key)
        if not notext and self.text != 0:
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluOrtho2D(0, self.width, 0, self.height)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glColor3d(1.0, 1.0, 1.0)
            if self.text == 2:
                self.drawText(self.nbParticles, 4.0, 40.0)
            self.drawText(self.fps, 4.0, 8.0)

        # refresh
        sdl2.SDL_GL_SwapWindow(self.window)
Ejemplo n.º 4
0
    def onRender(self):
        gl.glDepthMask(gl.GL_TRUE)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45, self.width / self.height, 0.01, 20.0)

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

        gl.glRotated(self.angleX, 1.0, 0.0, 0.0)  # apply camera rotation
        gl.glRotated(self.angleY, 0.0, 1.0, 0.0)
        gl.glTranslated(-self.posX, -1.0, -self.posZ)

        if self.renderEnv:
            c = self.param_f(0.8, 0.2)
            gl.glFogfv(gl.GL_FOG_COLOR, [c, c, c, 1.0])
            dist = self.param_f(20.0, 5.0)
            gl.glFogf(gl.GL_FOG_DENSITY, 2.0 / dist)

            # Renders floor
            gl.glDisable(gl.GL_BLEND)
            gl.glEnable(gl.GL_TEXTURE_2D)
            gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE,
                         gl.GL_MODULATE)
            gl.glBindTexture(gl.GL_TEXTURE_2D, self.txPaving)
            gl.glBegin(gl.GL_QUADS)
            gl.glColor3f(self.param_f(1.0, 0.3), self.param_f(1.0, 0.3),
                         self.param_f(1.0, 0.3))
            gl.glTexCoord2f(dist + self.posX, dist + self.posZ)
            gl.glVertex3f(dist + self.posX, 0.0, dist + self.posZ)
            gl.glTexCoord2f(dist + self.posX, -dist + self.posZ)
            gl.glVertex3f(dist + self.posX, 0.0, -dist + self.posZ)
            gl.glTexCoord2f(-dist + self.posX, -dist + self.posZ)
            gl.glVertex3f(-dist + self.posX, 0.0, -dist + self.posZ)
            gl.glTexCoord2f(-dist + self.posX, dist + self.posZ)
            gl.glVertex3f(-dist + self.posX, 0.0, dist + self.posZ)
            gl.glEnd()
            gl.glDisable(gl.GL_TEXTURE_2D)

        # draw bounding box(F2 key)
        gl.glLineWidth(1.0)
        drawBoundingBox(self.rainGroup, 1.0, 0.0, 0.0)
        drawBoundingBox(self.dropGroup, 0.0, 1.0, 0.0)
        drawBoundingBox(self.splashGroup, 0.0, 0.0, 1.0)

        # draw particles
        self.system.render()

        # draw texts(F1 key)
        if not notext and self.text != 0:
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluOrtho2D(0, self.width, 0, self.height)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glColor3d(1.0, 1.0, 1.0)
            if self.text == 2:
                self.drawText(self.strRainRate, 4.0, 72.0)
                self.drawText(self.nbParticles, 4.0, 40.0)
            self.drawText(self.fps, 4.0, 8.0)

        # refresh
        sdl2.SDL_GL_SwapWindow(self.window)
Ejemplo n.º 5
0
    def onRender(self):
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45, self.width / self.height, 0.01, 80.0)

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

        gl.glTranslated(0.0, 0.0, -self.camPosZ)  # apply camera zooming
        gl.glRotated(self.angleX, 1.0, 0.0, 0.0)  # apply camera rotation
        gl.glRotated(self.angleY, 0.0, 1.0, 0.0)

        if self.renderEnv:
            # draw 3D object(ground and camp-fire)
            light_position = [0.0, 1.0, 0.0, 1.0]
            if not self.paused:
                # Light blinking simulation
                self.lightTime += self.deltaTime
                if self.lightTime >= 50:
                    lightIntensity = 1.0 + (-spk.random(0.0, 0.05) * 5.0)
                    self.lightTime = 0
                    light_position[0] = spk.random(-0.5, 0.5)
                    light_position[1] = 0.5 + spk.random(-0.5, 0.5)
                    light_position[2] = spk.random(-0.5, 0.5)
                    gl.glLightf(gl.GL_LIGHT0, gl.GL_QUADRATIC_ATTENUATION,
                                15.0 / lightIntensity)

            gl.glDisable(gl.GL_BLEND)
            gl.glEnable(gl.GL_DEPTH_TEST)

            gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light_position)

            gl.glEnable(gl.GL_LIGHTING)
            gl.glEnable(gl.GL_LIGHT0)
            gl.glShadeModel(gl.GL_SMOOTH)
            gl.glColor4d(1.0, 1.0, 1.0, 1.0)
            gl.glPushMatrix()
            gl.glTranslatef(0.0, -1.5, 0.0)
            gl.glScalef(0.01, 0.01, 0.01)
            self.scene.draw()  # rendering of 3D objects
            gl.glPopMatrix()
            gl.glDisable(gl.GL_LIGHTING)
            gl.glDisable(gl.GL_LIGHT0)

        # draw bounding box(F2 key)
        gl.glDisable(gl.GL_TEXTURE_2D)
        gl.glDisable(gl.GL_BLEND)
        drawBoundingBox(self.fireGroup, 1.0, 0.0, 0.0)
        drawBoundingBox(self.smokeGroup, 0.0, 1.0, 0.0)

        # draw particles
        spk.GL.GLRenderer.saveGLStates()
        self.system.render()
        spk.GL.GLRenderer.restoreGLStates()

        # draw texts(F1 key)
        if not notext and self.text != 0:
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluOrtho2D(0, self.width, 0, self.height)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glColor3d(1.0, 1.0, 1.0)
            if self.text == 2:
                self.drawText(self.strSmoke, 4.0, 72.0)
                self.drawText(self.nbParticles, 4.0, 40.0)
            self.drawText(self.fps, 4.0, 8.0)

        # refresh
        sdl2.SDL_GL_SwapWindow(self.window)