Exemplo n.º 1
0
        def Movimiento (x,y):
            if x ==1:
                return tr.matmul([tr.translate(0,0,0),tr.translate(y*np.cos(t1*y)
            *np.sin(t1),y*np.cos(t1),0), tr.shearing(np.sin(t1)/50,np.cos(t1)/8,0,0,0,0)])

            elif x ==2 :
                return tr.matmul([tr.translate(np.cos(t1*y),
            y*np.sin(t1*y)*np.sin(t1*y),0),tr.uniformScale(0.5), tr.shearing(np.sin(t1)/8,np.cos(t1)/8,0,0,0,0)])

            elif x ==3 :
                return tr.matmul([tr.translate(y*np.sin(t1*y),np.cos(t1*y),0), tr.uniformScale(0.8), tr.shearing(np.sin(t1)/8,np.cos(t1)/8,0,0,0,0)])

            elif x == 4:
                return tr.matmul([tr.translate(1000000000000,100000000000000,0)])
Exemplo n.º 2
0
def getTransform(showTransform, theta):

    if showTransform == TR_STANDARD:
        return tr.identity()

    elif showTransform == TR_ROTATE_ZP:
        return tr.rotationZ(theta)

    elif showTransform == TR_ROTATE_ZM:
        return tr.rotationZ(-theta)

    elif showTransform == TR_TRANSLATE:
        return tr.translate(0.3 * np.cos(theta), 0.3 * np.cos(theta), 0)

    elif showTransform == TR_UNIFORM_SCALE:
        return tr.uniformScale(0.7 + 0.5 * np.cos(theta))

    elif showTransform == TR_NONUNIF_SCALE:
        return tr.scale(1.0 - 0.5 * np.cos(1.5 * theta),
                        1.0 + 0.5 * np.cos(2 * theta), 1.0)

    elif showTransform == TR_REFLEX_Y:
        return tr.scale(1, -1, 1)

    elif showTransform == TR_SHEARING_XY:
        return tr.shearing(0.3 * np.cos(theta), 0, 0, 0, 0, 0)

    else:
        # This should NEVER happend
        raise Exception()
Exemplo n.º 3
0
def setTransform(n, theta, translation, scale, x):

    t = translation
    shearing = tr.shearing(0.1 * np.sin(theta), 0.1 * np.cos(theta), 0, 0, 0,
                           0)
    scale = tr.uniformScale(scale)
    theta = theta / 4

    if n == 1:
        tx = 0.7 * np.cos(theta / (2 * x))
        ty = 0.4 * np.cos(theta / x) + 0.3 * np.cos(theta)
    elif n == 2:
        tx = 0.4 * np.sin(theta) + 0.7 * np.cos(theta / 2)
        ty = 0.2 * np.sin(theta) * np.cos(theta / x) + 0.1 * np.sin(theta)
    elif n == 3:
        tx = 0.5 * np.cos(theta) * np.sin(theta /
                                          (2 * x)) + 0.4 * np.cos(theta)
        ty = 0.2 * np.cos(theta) * np.sin(theta / x) + 0.3 * np.cos(theta)
    elif n == 4:
        tx = 0.4 * np.cos(theta / x) * np.cos(theta)
        ty = 0.2 * np.cos(theta / (x))
    elif n == 5:
        tx = 0.4 * np.cos(theta / x) * np.sin(theta / x)
        ty = 0.2 * np.cos(theta / x) * np.sin(theta) * np.cos(theta)
    else:
        return tr.identity()

    tx = t[0] + tx
    ty = t[1] + ty
    pos = posInLimits(tx, ty)
    translation = tr.translate(pos[0], pos[1], 0)

    return tr.matmul([shearing, scale, translation])
Exemplo n.º 4
0
def createWoz(advanced = False):

    # Variable used to change the colors
    # I preferred to use this over a different shader program
    # because I also need to use a different logic for the
    # advanced ships and they had a slighty different model
    channel =  1- int(advanced)

    gpuVariantTriangle = es.toGPUShape(ve.createColorTriangle(channel, 0.6, 0))

    gpuBlueTrapeze = es.toGPUShape(ve.createColorTrapeze(0, 0, 1))
    gpuVariantTrapeze0 = es.toGPUShape(ve.createColorTrapeze(channel, 1 - channel, 0))
    gpuVariantTrapeze1 = es.toGPUShape(ve.createColorTrapeze(channel, 0.4, 0))
    
    # Creating the cannon of the ship
    cannon = sg.SceneGraphNode("cannon")
    cannon.transform = tr.translate(0, -1.22, 1)
    cannon.childs += [createCannon()]

    # Creating the motor of the ship
    motor = sg.SceneGraphNode("motor")
    motor.transform = tr.translate(0, 0.62, 0)
    motor.childs += [createMotor()]

    # Creating the front of the ship
    front = sg.SceneGraphNode("front")
    front.transform = tr.matmul([tr.translate(0, -0.87, 0.5), tr.scale(0.6, -0.75, 1)])
    front.childs += [gpuVariantTriangle]

    # Creating the center of the ship
    center = sg.SceneGraphNode("center")
    center.transform = tr.scale(1, -1, 1)
    center.childs += [gpuVariantTrapeze0]

    # Creating the cabin of the ship
    cabin = sg.SceneGraphNode("cabin")
    cabin.transform = tr.matmul([tr.translate(0, 0, 1), tr.uniformScale(-0.5)])
    cabin.childs += [gpuBlueTrapeze]

    # Creating the wings of the ship
    wing0 = sg.SceneGraphNode("wing0")
    wing0.transform = tr.matmul([tr.uniformScale(0.5), tr.rotationZ(math.pi / 2)])
    wing0.transform = tr.matmul([tr.shearing(0, 1.2, 0, 0, 0, 0), wing0.transform])
    wing0.transform = tr.matmul([tr.translate(-0.6, -0.25, 0), tr.rotationZ(0.2), wing0.transform])
    wing0.childs += [gpuVariantTrapeze1]

    wing1 = sg.SceneGraphNode("wing1")
    wing1.transform = tr.matmul([tr.scale(-1, 1, 1), wing0.transform])
    wing1.childs += [gpuVariantTrapeze1]

    woz = sg.SceneGraphNode("woz")
    woz.childs += [wing0, wing1]
    woz.childs += [motor, center, front]
    woz.childs += [cabin]
    woz.childs += [cannon]

    # Upgrading the Woz
    if advanced:
        extraCannon0 = sg.SceneGraphNode("extraCannon0")
        extraCannon0.transform = tr.matmul([tr.translate(0.75, 0.5, 0), cannon.transform])
        extraCannon0.childs += [createCannon()]

        extraCannon1 = sg.SceneGraphNode("extraCannon1")
        extraCannon1.transform = tr.matmul([tr.scale(-1, 1, 1), extraCannon0.transform])
        extraCannon1.childs += [createCannon()]

        woz.childs += [extraCannon0, extraCannon1]

    return woz
Exemplo n.º 5
0
            listaPeces[i-1].rotacion = Movimiento(listaPeces[i-1].mov,listaPeces[i-1].azar)  #Pez 1
            if listaPeces[i-1].rotacion[3][0] > 0.97 or listaPeces[i-1].rotacion[3][1] > 0.97:
                listaPeces[i-1].rotacion = tr.matmul([tr.translate(10000000000000000,100000000000000000000,0)])
                listaPeces[i-1].mov = 4

            if controller.leftClickOn:
                if listaPeces[i-1].rotacion[3][0] < mousePosX and listaPeces[i-1].rotacion[3][0]+0.13 > mousePosX and listaPeces[i-1].rotacion[3][1]-0.1 < mousePosY and listaPeces[i-1].rotacion[3][1]+0.1 > mousePosY:
                    listaPeces[i-1].rotacion = tr.matmul([tr.translate(10000000000000000,100000000000000000000,0)])
                    listaPeces[i-1].mov = 4
                    controller.leftClickOn = not controller.leftClickOn


            transformFish = listaPeces[i-1].rotacion 
            drawShape(shaderProgram, listaPeces[i-1].tipo, transformFish)
        
        transformAlgas = tr.matmul([tr.translate(0,-0.75,0), tr.shearing(0,np.sin(t1)/2,0,0,0,0)])
        drawShape(shaderProgram, gpuAlgas, transformAlgas) 

        transformAlgas = tr.matmul([tr.translate(0.05,-0.75,0), tr.shearing(0,np.sin(t1)/4,0,0,0,0)])
        drawShape(shaderProgram, gpuAlgas, transformAlgas)

        transformAlgas = tr.matmul([tr.translate(0.10,-0.75,0), tr.shearing(0,np.sin(t1)/8,0,0,0,0)])
        drawShape(shaderProgram, gpuAlgas, transformAlgas)

        transformAlgas = tr.matmul([tr.translate(0.15,-0.75,0), tr.shearing(0,np.sin(t1)/16,0,0,0,0)])
        drawShape(shaderProgram, gpuAlgas, transformAlgas)

        transformAlgas = tr.matmul([tr.translate(0.20,-0.75,0), tr.shearing(0,np.sin(t1)/32,0,0,0,0)])
        drawShape(shaderProgram, gpuAlgas, transformAlgas)

        transformAlgas = tr.matmul([tr.translate(0.25,-0.75,0), tr.shearing(0,np.sin(t1)/64,0,0,0,0)])
Exemplo n.º 6
0
                [tr.scale(0.05, 0.25, 0),
                 tr.translate(-0.7, -0.63, 0.0)]))
        drawShape(
            shaderProgram, darkVioletSquare,
            tr.matmul(
                [tr.scale(0.15, 0.02, 0),
                 tr.translate(-0.7, -0.58, 0.0)]))

        # Algae
        for j in range(14):
            for i in range(4):
                drawShape(
                    shaderProgram, greenSquare,
                    tr.matmul([
                        tr.scale(0.02, 0.05, 0),
                        tr.shearing(0.2 * np.sin(20 * theta),
                                    0.1 * np.cos(theta), 0, 0, 0, 0),
                        tr.translate(0.5 + j * 0.04,
                                     -0.6 + i * 0.08 + j * 0.002, 0)
                    ]))
                drawShape(
                    shaderProgram, greenSquare,
                    tr.matmul([
                        tr.scale(0.02, 0.05, 0),
                        tr.shearing(-0.2 * np.sin(20 * theta),
                                    0.1 * np.cos(theta), 0, 0, 0, 0),
                        tr.translate(0.5 + j * 0.04,
                                     -0.64 + i * 0.08 + j * 0.002, 0)
                    ]))
                drawShape(
                    shaderProgram, greenSquare,
                    tr.matmul([
Exemplo n.º 7
0
            tr.scale(0.5 + 0.2 * np.cos(1.5 * theta),
                     0.5 + 0.2 * np.sin(2 * theta), 0)
        ])
        glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "transform"), 1,
                           GL_TRUE, triangleTransform2)
        drawShape(shaderProgram, gpuTriangle)

        # Quad
        quadTransform = tr.matmul([
            tr.translate(-0.5, -0.5, 0),
            tr.rotationZ(-theta),
            tr.uniformScale(0.7)
        ])
        glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "transform"), 1,
                           GL_TRUE, quadTransform)
        drawShape(shaderProgram, gpuQuad)

        # Another instance of the Quad
        quadTransform2 = tr.matmul([
            tr.translate(0.5, -0.5, 0),
            tr.shearing(0.3 * np.cos(theta), 0, 0, 0, 0, 0),
            tr.uniformScale(0.7)
        ])
        glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "transform"), 1,
                           GL_TRUE, quadTransform2)
        drawShape(shaderProgram, gpuQuad)

        # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen.
        glfw.swap_buffers(window)

    glfw.terminate()