def draw_axises(grayed_out=False):

    with ms.push_matrix(ms.MatrixStack.model):
        ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0)

        # x axis
        with ms.push_matrix(ms.MatrixStack.model):
            ms.rotate_z(ms.MatrixStack.model, math.radians(-90.0))

            glColor3f(1.0, 0.0, 0.0)
            if grayed_out:
                glColor3f(0.5, 0.5, 0.5)
            draw_y_axis()

        # z
        glColor3f(0.0, 0.0, 1.0)  # blue z
        with ms.push_matrix(ms.MatrixStack.model):
            ms.rotate_y(ms.MatrixStack.model, math.radians(90.0))
            ms.rotate_z(ms.MatrixStack.model, math.radians(90.0))

            glColor3f(0.0, 0.0, 1.0)
            if grayed_out:
                glColor3f(0.5, 0.5, 0.5)
            draw_y_axis()

        # y
        glColor3f(0.0, 1.0, 0.0)  # green y
        if grayed_out:
            glColor3f(0.5, 0.5, 0.5)
        draw_y_axis()
示例#2
0
    ms.rotate_y(ms.MatrixStack.view, -camera.rot_y)
    ms.translate(ms.MatrixStack.view, -camera.x, -camera.y, -camera.z)

    with ms.push_matrix(ms.MatrixStack.model):
        # draw paddle 1
        # Unlike in previous demos, because the transformations
        # are on a stack, the fns on the model stack can
        # be read forwards, where each operation translates/rotates/scales
        # the current space
        ms.translate(
            ms.MatrixStack.model,
            paddle1.position[0],
            paddle1.position[1],
            0.0,
        )
        ms.rotate_z(ms.MatrixStack.model, paddle1.rotation)
        paddle1.render()

        with ms.push_matrix(ms.MatrixStack.model):
            # # draw the square

            # since the modelstack is already in paddle1's space
            # just add the transformations relative to it
            # before paddle 2 is drawn, we need to remove
            # the square's 3 model_space transformations

            ms.translate(ms.MatrixStack.model, 0.0, 0.0, -10.0)
            ms.rotate_z(ms.MatrixStack.model, square.rotation_around_paddle1)

            ms.translate(ms.MatrixStack.model, 20.0, 0.0, 0.0)
            ms.rotate_z(ms.MatrixStack.model, square.rotation)
        if animation_time > 5.0:
            # draw paddle 1
            ms.translate(
                ms.MatrixStack.model,
                paddle1.offset_x * min(1.0, (animation_time - 5.0) / 5.0),
                paddle1.offset_y * min(1.0, (animation_time - 5.0) / 5.0), 0.0)

        if animation_time > 10.0:
            ms.translate(
                ms.MatrixStack.model, paddle1.global_position[0] *
                min(1.0, (animation_time - 10.0) / 5.0),
                paddle1.global_position[1] *
                min(1.0, (animation_time - 10.0) / 5.0), 0.0)
        if (animation_time > 15.0):
            ms.rotate_z(
                ms.MatrixStack.model,
                paddle1.rotation * min(1.0, (animation_time - 15.0) / 5.0))

        if animation_time > 5.0 and animation_time < 20.0:
            draw_axises()
        glColor3f(paddle1.r, paddle1.g, paddle1.b)
        if animation_time > 20.0:
            # ascontiguousarray puts the array in column major order
            glLoadMatrixf(
                np.ascontiguousarray(
                    ms.getCurrentMatrix(ms.MatrixStack.modelview).T))
            glBegin(GL_QUADS)
            for model_space in paddle1.vertices:
                glVertex3f(model_space[0], model_space[1], model_space[2])
            glEnd()
示例#4
0
    def render(self, time, grayed_out=False):
        glDisable(GL_DEPTH_TEST)
        glUseProgram(self.shader)
        glBindVertexArray(self.vao)

        # pass projection parameters to the shader
        fov_loc = glGetUniformLocation(self.shader, "fov")
        glUniform1f(fov_loc, 45.0)
        aspect_loc = glGetUniformLocation(self.shader, "aspectRatio")
        glUniform1f(aspect_loc, 1.0)
        nearZ_loc = glGetUniformLocation(self.shader, "nearZ")
        glUniform1f(nearZ_loc, -5.0)
        farZ_loc = glGetUniformLocation(self.shader, "farZ")
        glUniform1f(farZ_loc, -150.00)
        # TODO, set the color

        with ms.push_matrix(ms.MatrixStack.model):

            # x axis
            with ms.push_matrix(ms.MatrixStack.model):
                ms.rotate_z(ms.MatrixStack.model, math.radians(-90.0))

                if enlarged_axis:
                    ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0)
                glUniform3f(self.colorLoc, 1.0, 0.0, 0.0)
                if grayed_out:
                    glUniform3f(self.colorLoc, 0.5, 0.5, 0.5)

                # ascontiguousarray puts the array in column major order
                glUniformMatrix4fv(
                    self.mMatrixLoc,
                    1,
                    GL_TRUE,
                    np.ascontiguousarray(ms.getCurrentMatrix(
                        ms.MatrixStack.model),
                                         dtype=np.float32),
                )
                glUniformMatrix4fv(
                    self.vMatrixLoc,
                    1,
                    GL_TRUE,
                    np.ascontiguousarray(ms.getCurrentMatrix(
                        ms.MatrixStack.view),
                                         dtype=np.float32),
                )
                glUniformMatrix4fv(
                    self.pMatrixLoc,
                    1,
                    GL_TRUE,
                    np.ascontiguousarray(ms.getCurrentMatrix(
                        ms.MatrixStack.projection),
                                         dtype=np.float32),
                )
                glDrawArrays(GL_LINES, 0, self.numberOfVertices)

            # y
            if enlarged_axis:
                ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0)
            glUniform3f(self.colorLoc, 0.0, 1.0, 0.0)
            # glColor3f(0.0,1.0,0.0) # green y
            if grayed_out:
                glUniform3f(self.colorLoc, 0.5, 0.5, 0.5)
            # ascontiguousarray puts the array in column major order
            glUniformMatrix4fv(
                self.mMatrixLoc,
                1,
                GL_TRUE,
                np.ascontiguousarray(ms.getCurrentMatrix(ms.MatrixStack.model),
                                     dtype=np.float32),
            )
            glUniformMatrix4fv(
                self.vMatrixLoc,
                1,
                GL_TRUE,
                np.ascontiguousarray(ms.getCurrentMatrix(ms.MatrixStack.view),
                                     dtype=np.float32),
            )
            glUniformMatrix4fv(
                self.pMatrixLoc,
                1,
                GL_TRUE,
                np.ascontiguousarray(ms.getCurrentMatrix(
                    ms.MatrixStack.projection),
                                     dtype=np.float32),
            )
            glDrawArrays(GL_LINES, 0, self.numberOfVertices)
            glBindVertexArray(0)
        glEnable(GL_DEPTH_TEST)
示例#5
0
                 top=100.0,
                 near=0.0,
                 far=550.0)

    # note - opengl matricies use degrees
    ms.translate(ms.MatrixStack.view, 0.0, 0.0, -camera.r)
    ms.rotate_x(ms.MatrixStack.view, camera.rot_x)
    ms.rotate_y(ms.MatrixStack.view, -camera.rot_y)

    # draw NDC in global space, so that we can see the camera space
    # go to NDC
    with ms.PushMatrix(ms.MatrixStack.model):
        cube.render(animation_time)
    with ms.PushMatrix(ms.MatrixStack.model):
        ms.rotate_y(ms.MatrixStack.model, math.radians(90.0))
        ms.rotate_z(ms.MatrixStack.model, math.radians(90.0))
        ground.render(animation_time)

    if animation_time > 60.0:
        ms.translate(
            ms.MatrixStack.model,
            -virtual_camera_position[0] * min(1.0,
                                              (animation_time - 60.0) / 5.0),
            -virtual_camera_position[1] * min(1.0,
                                              (animation_time - 60.0) / 5.0),
            -virtual_camera_position[2] * min(1.0,
                                              (animation_time - 60.0) / 5.0),
        )

    # draw virtual camera
    if animation_time > 55.0:
示例#6
0
    def render(self, time, grayed_out=False):
        glDisable(GL_DEPTH_TEST)

        glUseProgram(self.shader)
        glBindVertexArray(self.vao)

        with ms.push_matrix(ms.MatrixStack.model):

            # x axis
            with ms.push_matrix(ms.MatrixStack.model):
                ms.rotate_z(ms.MatrixStack.model, math.radians(-90.0))

                if enlarged_axis:
                    ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0)
                glUniform3f(self.colorLoc, 1.0, 0.0, 0.0)
                if grayed_out:
                    glUniform3f(self.colorLoc, 0.5, 0.5, 0.5)

                # ascontiguousarray puts the array in column major order
                glUniformMatrix4fv(
                    self.mMatrixLoc,
                    1,
                    GL_TRUE,
                    np.ascontiguousarray(
                        ms.getCurrentMatrix(ms.MatrixStack.model), dtype=np.float32
                    ),
                )
                glUniformMatrix4fv(
                    self.vMatrixLoc,
                    1,
                    GL_TRUE,
                    np.ascontiguousarray(
                        ms.getCurrentMatrix(ms.MatrixStack.view), dtype=np.float32
                    ),
                )
                glUniformMatrix4fv(
                    self.pMatrixLoc,
                    1,
                    GL_TRUE,
                    np.ascontiguousarray(
                        ms.getCurrentMatrix(ms.MatrixStack.projection), dtype=np.float32
                    ),
                )
                glDrawArrays(GL_LINES, 0, self.numberOfVertices)

            # z
            # glColor3f(0.0,0.0,1.0) # blue z
            with ms.push_matrix(ms.MatrixStack.model):
                ms.rotate_y(ms.MatrixStack.model, math.radians(90.0))
                ms.rotate_z(ms.MatrixStack.model, math.radians(90.0))
                if enlarged_axis:
                    ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0)

                glUniform3f(self.colorLoc, 0.0, 0.0, 1.0)
                if grayed_out:
                    glUniform3f(self.colorLoc, 0.5, 0.5, 0.5)
                # ascontiguousarray puts the array in column major order
                glUniformMatrix4fv(
                    self.mMatrixLoc,
                    1,
                    GL_TRUE,
                    np.ascontiguousarray(
                        ms.getCurrentMatrix(ms.MatrixStack.model), dtype=np.float32
                    ),
                )
                glUniformMatrix4fv(
                    self.vMatrixLoc,
                    1,
                    GL_TRUE,
                    np.ascontiguousarray(
                        ms.getCurrentMatrix(ms.MatrixStack.view), dtype=np.float32
                    ),
                )
                glUniformMatrix4fv(
                    self.pMatrixLoc,
                    1,
                    GL_TRUE,
                    np.ascontiguousarray(
                        ms.getCurrentMatrix(ms.MatrixStack.projection), dtype=np.float32
                    ),
                )
                if enlarged_axis:
                    ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0)
                glDrawArrays(GL_LINES, 0, self.numberOfVertices)

            # y
            if enlarged_axis:
                ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0)

            glUniform3f(self.colorLoc, 0.0, 1.0, 0.0)
            # glColor3f(0.0,1.0,0.0) # green y
            if grayed_out:
                glUniform3f(self.colorLoc, 0.5, 0.5, 0.5)
            # ascontiguousarray puts the array in column major order
            glUniformMatrix4fv(
                self.mMatrixLoc,
                1,
                GL_TRUE,
                np.ascontiguousarray(
                    ms.getCurrentMatrix(ms.MatrixStack.model), dtype=np.float32
                ),
            )
            glUniformMatrix4fv(
                self.vMatrixLoc,
                1,
                GL_TRUE,
                np.ascontiguousarray(
                    ms.getCurrentMatrix(ms.MatrixStack.view), dtype=np.float32
                ),
            )
            glUniformMatrix4fv(
                self.pMatrixLoc,
                1,
                GL_TRUE,
                np.ascontiguousarray(
                    ms.getCurrentMatrix(ms.MatrixStack.projection), dtype=np.float32
                ),
            )
            glDrawArrays(GL_LINES, 0, self.numberOfVertices)
            glBindVertexArray(0)
            glEnable(GL_DEPTH_TEST)
示例#7
0
    # set the projection matrix to be perspective
    ms.perspective(
        fov=45.0, aspectRatio=float(width) / float(height), nearZ=0.1, farZ=10000.0
    )

    # note - opengl matricies use degrees
    if view_ndc:
        ms.translate(ms.MatrixStack.view, 0.0, 0.0, -camera.r)
        ms.rotate_x(ms.MatrixStack.view, camera.rot_x)
        ms.rotate_y(ms.MatrixStack.view, -camera.rot_y)

    if view_paddle1 or view_square:
        if view_square:
            ms.rotate_z(
                ms.MatrixStack.model,
                -square_rotation,
            )
            ms.translate(
                ms.MatrixStack.model,
                -15.0,
                0.0,
                0.0,
            )
            ms.rotate_z(
                ms.MatrixStack.model,
                -rotation_around_paddle1,
            )
            ms.translate(
                ms.MatrixStack.model,
                0.0,
                0.0,
示例#8
0
        axis.render(animation_time)
    else:
        axis.render(animation_time, grayed_out=True)

    with ms.PushMatrix(ms.MatrixStack.model):

        if animation_time > 5.0:
            ms.translate(
                ms.MatrixStack.model,
                paddle1.position[0] * min(1.0, (animation_time - 5.0) / 5.0),
                paddle1.position[1] * min(1.0, (animation_time - 5.0) / 5.0),
                0.0,
            )
        if animation_time > 10.0:
            ms.rotate_z(
                ms.MatrixStack.model,
                paddle1.rotation * min(1.0, (animation_time - 10.0) / 5.0),
            )

        if animation_time > 15.0:
            # ascontiguousarray puts the array in column major order
            paddle1.render(animation_time)
        if animation_time > 0.0 and animation_time < 15.0:
            axis.render(animation_time)

        # # draw the square

        if animation_time > 15.0:
            ms.translate(
                ms.MatrixStack.model,
                0.0,
                0.0,