Ejemplo n.º 1
0
def projetaPoligonoWireframe(poligono, janela):

    arestas = poligonos.get_arestas(poligono)
    cos = math.cos(3.14/4)
    sin = math.sin(3.14/4)

    matrizP = np.array([[1,0,0,0],
                        [0,1,0,0],
                        [cos,sin,0,0],
                        [0,0,0,1]])

    vertices = poligonos.get_vertices(poligono)
    temp = []
    for a in vertices:
        temp.append(a)

    temp = np.array(temp)

    R = np.dot(temp, matrizP)

    for i in range(len(R)):
        for j in range(len(R[i])):
            R[i][j] = R[i][j] / R[i][len(R[i])-1]

    for i in range(len(arestas)):
        pygame.draw.line(janela, (255, 255, 255),
                         (R[arestas[i][0]][0], R[arestas[i][0]][1]),
                         (R[arestas[i][1]][0], R[arestas[i][1]][1]), 1)
Ejemplo n.º 2
0
def rotate(figura, x, y, z, fator):

    deslocamentoX = figura.getDeslocamentoX()
    deslocamentoY = figura.getDeslocamentoY()
    sentidoX = figura.getSentidoX()
    sentidoY = figura.getSentidoY()
    moveX = figura.getMoveX()
    moveY = figura.getMoveY()
    scale = figura.getScale()

    cos = m.cos(fator)
    sin = m.sin(fator)
    Rx = np.array([[1, 0, 0, 0], [0, cos, -sin, 0], [0, sin, cos, 0],
                   [0, 0, 0, 1]])

    Ry = np.array([[cos, 0, sin, 0], [0, 1, 0, 0], [-sin, 0, cos, 0],
                   [0, 0, 0, 1]])

    Rz = np.array([[cos, -sin, 0, 0], [sin, cos, 0, 0], [0, 0, 1, 0],
                   [0, 0, 0, 1]])
    vertices = poligonos.get_vertices(figura)
    temp = []
    arestas = poligonos.get_arestas(figura)
    for a in vertices:
        temp.append(a)
    B = np.array(temp)
    if (x == 1):
        C = np.dot(B, Rx)
        figura = poligonos.Poligono(arestas, figura.centro,
                                    poligonos.get_faces(figura))
        figura.addVertice(C)
        figura.addVerticeO(C)
    elif (y == 1):
        C = np.dot(B, Ry)
        figura = poligonos.Poligono(arestas, figura.centro,
                                    poligonos.get_faces(figura))
        figura.addVertice(C)
        figura.addVerticeO(C)
    elif (z == 1):
        C = np.dot(B, Rz)
        figura = poligonos.Poligono(arestas, figura.centro,
                                    poligonos.get_faces(figura))
        figura.addVertice(C)
        figura.addVerticeO(C)

    figura = poligonos.setCentro(figura)
    figura.setDeslocamentoX(deslocamentoX)
    figura.setDeslocamentoY(deslocamentoY)
    figura.setSentidoX(sentidoX)
    figura.setSentidoY(sentidoY)
    figura.setMoveX(moveX)
    figura.setMoveY(moveY)
    figura.setScale(scale)

    return figura
Ejemplo n.º 3
0
def translate(figura, x, y, z):

    deslocamentoX = figura.deslocamentoX()
    deslocamentoY = figura.deslocamentoY()

    if (quadrosChave.quadroChaveTransX(figura)):

        if (figura.getMoveY()):
            figura.setMoveY(False)
            figura.setSentidoY(False)
        else:
            figura.setMoveY(True)

        figura.inverteSentidoX()

    if (quadrosChave.quadroChaveTransY(figura)):
        figura.inverteSentidoY()

    T = np.array([[1, 0, 0, x + deslocamentoX], [0, 1, 0, y + deslocamentoY],
                  [0, 0, 1, z], [0, 0, 0, 1]])
    vertices = poligonos.get_vertices(figura)
    temp = []
    arestas = poligonos.get_arestas(figura)
    for a in vertices:
        temp.append(a)
    B = np.array(temp)

    C = []
    for i in B:
        temp = np.dot(T, [[i[0]], [i[1]], [i[2]], [i[3]]])
        linha = []
        for j in temp:
            linha.append(j[0])

        C.append(linha)
    fig = poligonos.Poligono(arestas, figura.centro,
                             poligonos.get_faces(figura))

    fig.addVertice(C)
    fig.addVerticeO(C)
    fig = poligonos.setCentro(fig)
    fig.setDeslocamentoX(deslocamentoX)
    fig.setDeslocamentoY(deslocamentoY)
    fig.setSentidoX(figura.getSentidoX())
    fig.setSentidoY(figura.getSentidoY())
    fig.setMoveX(figura.getMoveX())
    fig.setMoveY(figura.getMoveY())
    fig.setScale(figura.getScale())

    return fig
Ejemplo n.º 4
0
def reflect(figura, qx, qy, qz):

    x = 1
    y = 1
    z = 1

    if (qx == True):
        y = -1
        z = -1
    if (qy == True):
        x = -1
        z = -1
    if (qz == True):
        x = -1
        y = -1

    A = np.array([[x, 0, 0, 0], [0, y, 0, 0], [0, 0, z, 0], [0, 0, 0, 1]])
    vertices = poligonos.get_vertices(figura)
    temp = []
    arestas = poligonos.get_arestas(figura)
    for a in vertices:
        temp.append(a)
    B = np.array(temp)

    C = np.dot(B, A)

    fig = poligonos.Poligono(arestas, figura.centro,
                             poligonos.get_faces(figura))
    fig.addVertice(C)
    fig.addVerticeO(C)
    fig = poligonos.setCentro(fig)
    fig.setDeslocamentoX(figura.getDeslocamentoX())
    fig.setDeslocamentoY(figura.getDeslocamentoY())
    fig.setSentidoX(figura.getSentidoX())
    fig.setSentidoY(figura.getSentidoY())
    fig.setMoveX(figura.getMoveX())
    fig.setMoveY(figura.getMoveY())
    fig.setScale(figura.getScale())

    return fig
Ejemplo n.º 5
0
def scale(figura, fator):

    if (figura.getScale() != 0):
        aux = figura.getScale()
        figura.setScale(0)
        figura = scale(figura, 1 / aux)

    EX = EY = EZ = fator
    A = np.array([[EX, 0, 0, 0], [0, EY, 0, 0], [0, 0, EZ, 0], [0, 0, 0, 1]])

    vertices = poligonos.get_vertices(figura)

    centro = figura.getCentro()

    vertices = transladaParaOrigem(vertices, True, centro)
    temp = []
    arestas = poligonos.get_arestas(figura)
    for a in vertices:
        temp.append(a)
    B = np.array(temp)

    C = np.dot(B, A)

    C = transladaParaOrigem(C, False, centro)

    fig = poligonos.Poligono(arestas, figura.centro,
                             poligonos.get_faces(figura))
    fig.addVertice(C)
    fig = poligonos.setCentro(fig)
    fig.setDeslocamentoX(figura.getDeslocamentoX())
    fig.setDeslocamentoY(figura.getDeslocamentoY())
    fig.setSentidoX(figura.getSentidoX())
    fig.setSentidoY(figura.getSentidoY())
    fig.setMoveX(figura.getMoveX())
    fig.setMoveY(figura.getMoveY())
    fig.setScale(fator)

    return fig
Ejemplo n.º 6
0
def shearing(figura, x, y, z, matriz):

    if (matriz == 1):
        S = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [x, y, 1, 0], [0, 0, 0, 1]])

    elif (matriz == 2):
        S = np.array([[1, 0, 0, 0], [x, 1, z, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

    elif (matriz == 3):

        S = np.array([[1, y, z, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

    else:  #Caso não digite nada multiplica pela identidade.
        S = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

    vertices = poligonos.get_vertices(figura)
    temp = []
    arestas = poligonos.get_arestas(figura)
    for a in vertices:
        temp.append(a)
    B = np.array(temp)

    R = np.dot(B, S)

    fig = poligonos.Poligono(arestas, figura.centro,
                             poligonos.get_faces(figura))
    fig.addVertice(R)
    fig = poligonos.setCentro(fig)
    fig.setDeslocamentoX(figura.getDeslocamentoX())
    fig.setDeslocamentoY(figura.getDeslocamentoY())
    fig.setSentidoX(figura.getSentidoX())
    fig.setSentidoY(figura.getSentidoY())
    fig.setMoveX(figura.getMoveX())
    fig.setMoveY(figura.getMoveY())
    fig.setScale(figura.getScale())

    return fig