Exemplo n.º 1
0
    def animation(self, shader_program, speed=1.0):
        looplen = self.keyframes[-1].time - self.keyframes[0].time
        current_time = (glfw.glfwGetTime() / speed) % looplen

        while (self.keyframes[self.prev_iter].time > current_time) or (
                self.keyframes[self.prev_iter + 1].time < current_time):
            self.prev_iter = (self.prev_iter + 1) % (len(self.keyframes) - 1)

        duration = self.keyframes[self.prev_iter +
                                  1].time - self.keyframes[self.prev_iter].time
        frame_progress = (current_time -
                          self.keyframes[self.prev_iter].time) / (duration)
        pre_frame = self.keyframes[self.prev_iter]
        next_frame = self.keyframes[self.prev_iter + 1]
        self.interpolation_joint = dict()
        # frame_progress = 0.5
        # print("progress: ", frame_progress, "looplen ", looplen, self.prev_iter, self.prev_iter + 1)
        for key, value in pre_frame.joint_transform.items():
            t_m = self.interpolating_translation(
                value[0],
                next_frame.joint_transform.get(key)[0], frame_progress)
            r_m = self.interpolating_rotation(
                value[1],
                next_frame.joint_transform.get(key)[1], frame_progress)
            matrix = np.matmul(t_m, r_m)
            self.interpolation_joint[key] = matrix

        self.load_animation_matrices(self.root_joint, np.identity(4))
        self.render(shader_program)
Exemplo n.º 2
0
def render(window):
    global program, vao, indices, cube_positions

    GLFW.glfwPollEvents()

    GL.glViewport(0, 0, window.width, window.height)

    cameraPos = GLM.vec3(0.0, 0.0, 3.0)
    cameraTarget = GLM.vec3(0.0, 0.0, 0.0)
    cameraDirection = GLM.normalize(cameraPos - cameraTarget)
    up = GLM.vec3(0.0, 1.0, 0.0)
    cameraRight = GLM.normalize(GLM.cross(up, cameraDirection))
    cameraUp = GLM.cross(cameraDirection, cameraRight)

    view = GLM.lookAt(GLM.vec3(0.0, 0.0, 3.0), GLM.vec3(0.0, 0.0, 0.0),
                      GLM.vec3(0.0, 1.0, 0.0))

    GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
    program.useProgram()

    view = GLM.mat4(1.0)
    view = GLM.translate(view, GLM.vec3(0.0, 0.0, -3.0))

    projection = GLM.perspective(GLM.radians(45.0),
                                 window.width / window.height, 0.1, 100.0)

    program.setMat4("projection", projection)

    for w in range(10):
        radius = 10.0
        camX = MATH.sin(GLFW.glfwGetTime()) * radius
        camZ = MATH.cos(GLFW.glfwGetTime()) * radius
        view = GLM.lookAt(GLM.vec3(camX, 0.0, camZ), GLM.vec3(0.0, 0.0, 0.0),
                          GLM.vec3(0.0, 1.0, 0.0))

        model = GLM.mat4(1.0)
        model = GLM.translate(model, cube_positions[w])
        model = GLM.rotate(model, GLM.radians(20.0 * w),
                           GLM.vec3(1.0, 0.3, 0.5))
        program.setMat4("model", model)
        program.setMat4("view", view)
        vao.useVAO(program)
        GL.glDrawArrays(GL.GL_TRIANGLES, 0, 36)

    vao.unBind()

    GLFW.glfwSwapBuffers(window.getWindow())
Exemplo n.º 3
0
def sync(start):
    slot = 1 / 30.0
    end = start + slot

    while GLFW.glfwGetTime() < end:
        time.sleep(1 / 1000.0)
Exemplo n.º 4
0
def loopCallback(window):
    renderer.render(window)
    sync(GLFW.glfwGetTime())