def move(self, rotation, size, translation1, translation2, translation3):
     self.face.transform = tr.matmul([
         tr.scale(size, size, size),
         tr.translate(translation1, translation2, translation3),
         tr.scale(0.3, 0.3, 0.3),
         tr.translate(0, 0, 2),
         tr.rotationZ(rotation)
     ])
     self.body.transform = tr.matmul([
         tr.scale(size, size, size),
         tr.translate(translation1, translation2, translation3),
         tr.rotationZ(rotation)
     ])
Esempio n. 2
0
    def rotationZ(self, theta=0):
        """
        Rotate model.

        :param theta:
        :return:
        """
        self._model = _tr.matmul([_tr.rotationZ(theta), self._model])
Esempio n. 3
0
    def uniformScale(self, s=1):
        """
        Uniform scale model.

        :param s:
        :return:
        """
        self._model = _tr.matmul([_tr.uniformScale(s), self._model])
Esempio n. 4
0
    def applyTemporalTransform(self, t):
        """
        Apply temporal transform to model until drawing.

        :param t:
        :return:
        """
        self._modelPrev = self._model
        self._model = _tr.matmul([t, self._model])
Esempio n. 5
0
    def rotationA(self, theta, axis):
        """
        Rotate model.

        :param theta:
        :param axis:
        :return:
        """
        self._model = _tr.matmul([_tr.rotationA(theta, axis), self._model])
Esempio n. 6
0
    def scale(self, sx=1, sy=1, sz=1):
        """
        Scale model.

        :param sx:
        :param sy:
        :param sz:
        :return:
        """
        self._model = _tr.matmul([_tr.scale(sx, sy, sz), self._model])
Esempio n. 7
0
    def translate(self, tx=0, ty=0, tz=0):
        """
        Translate model.

        :param tx:
        :param ty:
        :param tz:
        :return:
        """
        self._model = _tr.matmul([_tr.translate(tx, ty, tz), self._model])
Esempio n. 8
0
    def shearing(self, xy=0, yx=0, xz=0, zx=0, yz=0, zy=0):
        """
        Apply shear to model.

        :param xy:
        :param yx:
        :param xz:
        :param zx:
        :param yz:
        :param zy:
        :return:
        """
        self._model = _tr.matmul(
            [_tr.shearing(xy, yx, xz, zx, yz, zy), self._model])
    def __init__(self, texture_head):
        gpu_body = es.toGPUShape(bs.createColorCube(1, 0, 0))
        gpu_leg = es.toGPUShape(bs.createColorCube(0, 0, 1))
        gpu_skin = es.toGPUShape(bs.createColorCube(1, 1, 0))
        gpu_head = es.toGPUShape(bs.createTextureCube(texture_head), GL_REPEAT,
                                 GL_LINEAR)

        # Creamos el nucleo
        core = sg.SceneGraphNode('core')
        core.transform = tr.scale(0.32, 0.5, 0.6)
        core.childs += [gpu_body]

        # Piernas
        leg = sg.SceneGraphNode('leg')
        leg.transform = tr.scale(0.14, 0.14, 0.5)
        leg.childs += [gpu_leg]

        leg_left = sg.SceneGraphNode('leg_left')
        leg_left.transform = tr.translate(0, -0.17, -0.5)
        leg_left.childs += [leg]

        leg_right = sg.SceneGraphNode('leg_right')
        leg_right.transform = tr.translate(0, 0.17, -0.5)
        leg_right.childs += [leg]

        # Brazos
        arm = sg.SceneGraphNode('arm')
        arm.transform = tr.scale(0.13, 0.5, 0.13)
        arm.childs += [gpu_skin]

        arm_left = sg.SceneGraphNode('arm_left')
        arm_left.transform = tr.translate(0, -0.4, 0.23)
        arm_left.childs += [arm]

        arm_right = sg.SceneGraphNode('arm_right')
        arm_right.transform = tr.translate(0, 0.4, 0.23)
        arm_right.childs += [arm]

        # Cuello
        neck = sg.SceneGraphNode('neck')
        neck.transform = tr.matmul(
            [tr.scale(0.12, 0.12, 0.2),
             tr.translate(0, 0, 1.6)])
        neck.childs += [gpu_skin]

        # Cabeza
        head = sg.SceneGraphNode('head')
        head.transform = tr.matmul(
            [tr.scale(0.35, 0.35, 0.35),
             tr.translate(-0.08, 0, 1.75)])
        head.childs += [gpu_skin]

        body = sg.SceneGraphNode('body')
        body.childs += [
            arm_left, arm_right, leg_left, leg_right, core, neck, head
        ]

        face = sg.SceneGraphNode('face')
        face.transform = tr.matmul(
            [tr.scale(0.3, 0.3, 0.3),
             tr.translate(0, 0, 2)])
        face.childs += [gpu_head]

        body_tr = sg.SceneGraphNode('bodyTR')
        body_tr.childs += [body, face]

        self.face = face
        self.body = body

        self.model = body_tr
        self.show_face = True
        # Filling or not the shapes depending on the controller state
        if (controller.fillPolygon):
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        if controller.mode == SH_TRANSFORM:
            # Total transformation is computed in the CPU

            glUseProgram(transformPipeline.shaderProgram)

            cubeTransform = tr2.matmul(
                [projection, view, model_traslation, model_rotation])
            axisTransform = tr2.matmul([projection, view])

            glUniformMatrix4fv(
                glGetUniformLocation(transformPipeline.shaderProgram,
                                     "transform"), 1, GL_TRUE, cubeTransform)
            transformPipeline.drawShape(gpuCube)

            glUniformMatrix4fv(
                glGetUniformLocation(transformPipeline.shaderProgram,
                                     "transform"), 1, GL_TRUE, axisTransform)
            transformPipeline.drawShape(gpuAxis, GL_LINES)

        elif controller.mode == SH_TRANSFORM_TRANSPOSED:
            # Total transformation is computed in the CPU, using trasposed matrices
Esempio n. 11
0
        theta = glfw.get_time()
        tx = 0.7 * np.sin(0.5 * theta)
        ty = 0.2 * np.sin(5 * theta)

        # derivative of tx give us the direction
        dtx = 0.7 * 0.5 * np.cos(0.5 * theta)
        if dtx > 0:
            reflex = tr2.scale(-1, 1, 1)
        else:
            reflex = tr2.identity()

        # Drawing the shapes
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "transform"), 1,
            GL_TRUE,
            tr2.matmul(
                [tr2.translate(tx, ty, 0),
                 tr2.scale(0.5, 0.5, 1.0), reflex]))
        pipeline.drawShape(gpuBoo)

        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "transform"), 1,
            GL_TRUE, questionBoxTransform)
        pipeline.drawShape(gpuQuestionBox)

        # Once the render is done, buffers are swapped, showing only the complete scene.
        glfw.swap_buffers(window)

    glfw.terminate()