Esempio n. 1
0
def createBackground(pipeline, i):
    # Se crea el fondo con un grafo de escena de shapes
    greenQuad = bs.createColorQuad(0.0, 0.6, 0.0)
    greyQuad = bs.createColorQuad(0.6, 0.6, 0.6)
    whiteQuad = bs.createColorQuad(255 / 255, 242 / 255, 0)

    gpuGrass = createGPUShape(greenQuad, pipeline)
    gpuStreet = createGPUShape(greyQuad, pipeline)
    gpuLine = createGPUShape(whiteQuad, pipeline)

    grassNode = sg.SceneGraphNode("grass")
    grassNode.transform = tr.scale(4, 2, 1)
    grassNode.childs = [gpuGrass]

    streetNode = sg.SceneGraphNode("street")
    streetNode.transform = tr.scale(1, 2, 1)
    streetNode.childs = [gpuStreet]

    lineNode = sg.SceneGraphNode("line")
    lineNode.transform = tr.scale(0.1, 0.25, 1)
    lineNode.childs = [gpuLine]

    trLineNode1 = sg.SceneGraphNode("trline1")
    trLineNode1.transform = tr.identity()
    trLineNode1.childs = [lineNode]

    trLineNode2 = sg.SceneGraphNode("trline2")
    trLineNode2.transform = tr.translate(0, 0.4, 0)
    trLineNode2.childs = [lineNode]

    trLineNode3 = sg.SceneGraphNode("trline3")
    trLineNode3.transform = tr.translate(0, -0.4, 0)
    trLineNode3.childs = [lineNode]

    trLineNode4 = sg.SceneGraphNode("trline4")
    trLineNode4.transform = tr.translate(0, -0.8, 0)
    trLineNode4.childs = [lineNode]

    trLineNode5 = sg.SceneGraphNode("trline5")
    trLineNode5.transform = tr.translate(0, 0.8, 0)
    trLineNode5.childs = [lineNode]

    lineGroupNode = sg.SceneGraphNode("lineGroup")
    lineGroupNode.transform = tr.translate(0, 0, 0)
    lineGroupNode.childs = [
        trLineNode1, trLineNode2, trLineNode3, trLineNode4, trLineNode5
    ]

    finalNode = sg.SceneGraphNode("final" + str(i))
    finalNode.childs = [grassNode, streetNode, lineGroupNode]

    return finalNode
Esempio n. 2
0
def createText(tex_pipeline):
    # Se crean los textos de victoria y game over como texturas en un grafo de escena
    quadShape = bs.createTextureQuad(1, 1)

    gpuGameOver = createTextureGPUShape(
        quadShape, tex_pipeline, getAssetPath("game_over_transparent.png"))
    gpuVictory = createTextureGPUShape(quadShape, tex_pipeline,
                                       getAssetPath("win_transparent.png"))

    gameOverNode = sg.SceneGraphNode("gameOver")
    gameOverNode.childs = [gpuGameOver]

    victoryNode = sg.SceneGraphNode("victory")
    victoryNode.childs = [gpuVictory]

    finalNode = sg.SceneGraphNode("final")
    finalNode.childs = [gameOverNode, victoryNode]

    return finalNode
def createCars(pipeline, N):

    # First we scale a car
    scaledCar = sg.SceneGraphNode("traslatedCar")
    scaledCar.transform = tr.uniformScale(0.15)
    scaledCar.childs += [createCar(pipeline)]  # Re-using the previous function

    cars = sg.SceneGraphNode("cars")

    baseName = "scaledCar"
    for i in range(N):
        # A new node is only locating a scaledCar in the scene depending on index i
        newNode = sg.SceneGraphNode(baseName + str(i))
        newNode.transform = tr.translate(0.4 * i - 0.9, 0.9 - 0.4 * i, 0)
        newNode.childs += [scaledCar]

        # Now this car is added to the 'cars' scene graph
        cars.childs += [newNode]

    return cars
def createCar(pipeline):

    # Creating shapes on GPU memory
    blackQuad = bs.createColorQuad(0, 0, 0)
    gpuBlackQuad = es.GPUShape().initBuffers()
    pipeline.setupVAO(gpuBlackQuad)
    gpuBlackQuad.fillBuffers(blackQuad.vertices, blackQuad.indices,
                             GL_STATIC_DRAW)

    redQuad = bs.createColorQuad(1, 0, 0)
    gpuRedQuad = es.GPUShape().initBuffers()
    pipeline.setupVAO(gpuRedQuad)
    gpuRedQuad.fillBuffers(redQuad.vertices, redQuad.indices, GL_STATIC_DRAW)

    # Cheating a single wheel
    wheel = sg.SceneGraphNode("wheel")
    wheel.transform = tr.uniformScale(0.2)
    wheel.childs += [gpuBlackQuad]

    wheelRotation = sg.SceneGraphNode("wheelRotation")
    wheelRotation.childs += [wheel]

    # Instanciating 2 wheels, for the front and back parts
    frontWheel = sg.SceneGraphNode("frontWheel")
    frontWheel.transform = tr.translate(0.3, -0.3, 0)
    frontWheel.childs += [wheelRotation]

    backWheel = sg.SceneGraphNode("backWheel")
    backWheel.transform = tr.translate(-0.3, -0.3, 0)
    backWheel.childs += [wheelRotation]

    # Creating the chasis of the car
    chasis = sg.SceneGraphNode("chasis")
    chasis.transform = tr.scale(1, 0.5, 1)
    chasis.childs += [gpuRedQuad]

    car = sg.SceneGraphNode("car")
    car.childs += [chasis]
    car.childs += [frontWheel]
    car.childs += [backWheel]

    traslatedCar = sg.SceneGraphNode("traslatedCar")
    traslatedCar.transform = tr.translate(0, 0.3, 0)
    traslatedCar.childs += [car]

    return traslatedCar
def createCar(pipeline, r, g, b):

    # Creating shapes on GPU memory
    blackCube = bs.createColorCube(0, 0, 0)
    gpuBlackCube = es.GPUShape().initBuffers()
    pipeline.setupVAO(gpuBlackCube)
    gpuBlackCube.fillBuffers(blackCube.vertices, blackCube.indices,
                             GL_STATIC_DRAW)

    chasisCube = bs.createColorCube(r, g, b)
    gpuChasisCube = es.GPUShape().initBuffers()
    pipeline.setupVAO(gpuChasisCube)
    gpuChasisCube.fillBuffers(chasisCube.vertices, chasisCube.indices,
                              GL_STATIC_DRAW)

    # Cheating a single wheel
    wheel = sg.SceneGraphNode("wheel")
    wheel.transform = tr.scale(0.2, 0.8, 0.2)
    wheel.childs += [gpuBlackCube]

    wheelRotation = sg.SceneGraphNode("wheelRotation")
    wheelRotation.childs += [wheel]

    # Instanciating 2 wheels, for the front and back parts
    frontWheel = sg.SceneGraphNode("frontWheel")
    frontWheel.transform = tr.translate(0.3, 0, -0.3)
    frontWheel.childs += [wheelRotation]

    backWheel = sg.SceneGraphNode("backWheel")
    backWheel.transform = tr.translate(-0.3, 0, -0.3)
    backWheel.childs += [wheelRotation]

    # Creating the chasis of the car
    chasis = sg.SceneGraphNode("chasis")
    chasis.transform = tr.scale(1, 0.7, 0.5)
    chasis.childs += [gpuChasisCube]

    # All pieces together
    car = sg.SceneGraphNode("car")
    car.childs += [chasis]
    car.childs += [frontWheel]
    car.childs += [backWheel]

    return car
def createSnowman(pipeline):

    # Convenience function to ease initialization
    def createGPUShape(shape):
        gpuShape = es.GPUShape().initBuffers()
        pipeline.setupVAO(gpuShape)
        gpuShape.fillBuffers(shape.vertices, shape.indices, GL_STATIC_DRAW)
        return gpuShape

    # basic GPUShapes
    gpuWhiteCircle = createGPUShape(createColorCircle(30, 1, 1, 1, 1))
    gpuBlackCircle = createGPUShape(createColorCircle(10, 1, 0, 0, 0))
    gpuBrownQuad = createGPUShape(bs.createColorQuad(0.6, 0.3, 0))
    gpuOrangeTriangle = createGPUShape(createColorTriangle(1, 0.6, 0))
    
    # Leaf nodes
    whiteCircleNode = sg.SceneGraphNode("whiteCircleNode")
    whiteCircleNode.childs = [gpuWhiteCircle]

    blackCircleNode = sg.SceneGraphNode("blackCircleNode")
    blackCircleNode.childs = [gpuBlackCircle]

    brownQuadNode = sg.SceneGraphNode("brownQuadNode")
    brownQuadNode.childs = [gpuBrownQuad]
    
    orangeTriangleNode = sg.SceneGraphNode("orangeTriangleNode")
    orangeTriangleNode.childs = [gpuOrangeTriangle]
    
    # Body
    snowballBody = sg.SceneGraphNode("snowballBody")
    snowballBody.transform = tr.scale(10, 10, 0)
    snowballBody.childs = [whiteCircleNode]

    arm = sg.SceneGraphNode("arm")
    arm.transform = tr.matmul([
        tr.translate(0, 5, 0),
        #tr.rotationZ(0),
        tr.scale(2, 10, 1)
    ])
    arm.childs = [brownQuadNode]

    leftArm = sg.SceneGraphNode("leftArm")
    leftArm.transform = tr.matmul([
        tr.translate(-7, 7, 0),
        tr.rotationZ(60 * np.pi / 180),
        #tr.scale(1, 1, 1)
    ])
    leftArm.childs = [arm]

    rightArm = sg.SceneGraphNode("rightArm")
    rightArm.transform = tr.matmul([
        tr.translate(7, 7, 0),
        tr.rotationZ(-60 * np.pi / 180),
        #tr.scale(1, 1, 1)
    ])
    rightArm.childs = [arm]
    
    body = sg.SceneGraphNode("body")
    body.transform = tr.translate(0,10,0)
    body.childs = [snowballBody, leftArm, rightArm]
    
    # Head
    snowballHead = sg.SceneGraphNode("snowballHead")
    snowballHead.transform = tr.scale(8, 8, 0)
    snowballHead.childs = [whiteCircleNode]
    
    leftEye = sg.SceneGraphNode("leftEye")
    leftEye.transform = tr.matmul([
        tr.translate(0, 5, 0),
        #tr.rotationZ(0),
        tr.scale(2, 2, 1)
    ])
    leftEye.childs = [blackCircleNode]
    
    rightEye = sg.SceneGraphNode("rightEye")
    rightEye.transform = tr.matmul([
        tr.translate(5, 5, 0),
        #tr.rotationZ(0),
        tr.scale(2, 2, 1)
    ])
    rightEye.childs = [blackCircleNode]
    
    baseTriangle = sg.SceneGraphNode("baseTriangle")
    baseTriangle.transform = tr.matmul([
        tr.translate(0, 3.5, 0),
        #tr.rotationZ(0),
        tr.scale(2, 7, 1)
    ])
    baseTriangle.childs = [orangeTriangleNode]
    
    nose = sg.SceneGraphNode("nose")
    nose.transform = tr.matmul([
        tr.translate(2, 0, 0),
        tr.rotationZ(-70 * np.pi / 180),
        #tr.scale(1, 1, 1)
    ])
    nose.childs = [baseTriangle]
    
    head = sg.SceneGraphNode("head")
    head.transform = tr.translate(0, 27, 0)
    head.childs = [snowballHead, leftEye, rightEye, nose]
   
    # Snowman, the one and only
    snowman = sg.SceneGraphNode("snowman")
    snowman.childs = [body, head]

    return snowman
Esempio n. 7
0
    # Creacion de escenas
    decorations = createDecorations(pipeline, statictex_pipeline, 0.6, [-1, 1],
                                    treeN, 1)
    decorations_2 = createDecorations(pipeline, statictex_pipeline, 0.6,
                                      [-1, 1], treeN, 2)
    decorations_2.transform = tr.translate(0, 2, 0)

    decoration_scene = csg.CustomSceneGraphNode("decoration_node")
    decoration_scene.childs = [decorations, decorations_2]

    scene = createBackground(pipeline, 0)
    scene_2 = createBackground(pipeline, 1)
    scene_2.transform = tr.translate(0, 2, 0)

    full_scene = sg.SceneGraphNode("full_scene")
    full_scene.childs = [scene, scene_2]

    # Creacion jugador
    player = Player(sprite_size, P)

    playerModel = createPlayerModel(tex_pipeline)

    player.set_model(playerModel)
    player.set_controller(controller)

    entityList = [player]
    entityModelsList = [playerModel]

    # Creacion zombies
    gpuZombie = createZombieModel(tex_pipeline)