Пример #1
0
    def test_sphere(self, painter):
        s = scene.from_string("s 0 0 0 1", "nff")
        self.assertIsNotNone(s)
        self.assertEqual(len(s.meshes), 1)
        self.assertEqual(len(s.materials), 1)
        mesh = s.meshes[0]
        mat = s.materials[0]
        self.assertIsNotNone(mesh)
        self.assertIsNotNone(mat)
        mat.ambient = gl.Color3f("white")

        painter.state.look_at(gl.vec3f(0, 0.8, -3), gl.vec3f(0, 0, 0), gl.vec3f(0, 1, 0))
        painter.state.perspective(angle.deg(45), 200 / 200, 0.005, 30.0)
        with painter.bind([mat.bindable(self.renderer)]):
            painter.draw([mesh.drawable(self.renderer)])
Пример #2
0
    def test_sphere_light(self, painter):
        s = scene.from_string("s 0 0 0 1", "nff")
        self.assertIsNotNone(s)
        self.assertEqual(len(s.meshes), 1)
        self.assertEqual(len(s.materials), 1)
        mesh = s.meshes[0]
        mat = s.materials[0]
        self.assertIsNotNone(mesh)
        self.assertIsNotNone(mat)
        mat.ambient = gl.Color3f("#222")
        mat.shading_model = gl.material.ShadingModel.gouraud
        mat.diffuse = gl.Color3f("white")
        mat.specular = gl.Color3f("white")
        mat.shininess = 3

        painter.state.look_at(gl.vec3f(0, 0.8, -3), gl.vec3f(0, 0, 0), gl.vec3f(0, 1, 0))
        painter.state.perspective(angle.deg(45), 200 / 200, 0.005, 30.0)
        light = self.renderer.new_light(
            gl.PointLightInfo(gl.vec3f(5, -1, 0), gl.Color3f("black"), gl.Color3f("#0f0f0f"))
        )
        with painter.bind([light, mat.bindable(self.renderer)]):
            painter.draw([mesh.drawable(self.renderer)])
Пример #3
0
def create(entity_manager, event_manager, renderer, initial_player_pos=(0, 0)):
    s = """
tess 6
shader img/rabbit.tif
s 1.0 -4.0 2.0 4.0 20 20
    """
    sc = scene.from_string(s, "nff")
    mesh = sc.meshes[0]
    mat = sc.materials[0]
    light = renderer.new_light(
        gl.PointLightInfo(
            gl.vec3f(0, 8, -1),
            gl.Color3f("#888"),
            gl.Color3f("#333"),
        ))
    #mat.textures[0].texture.generate_mipmap()

    player = entity_manager.create(
        'player',
        velocity=gl.vec3f(0),
        gravity=gl.vec3f(0, 1000, 0),
        force=gl.vec3f(0),
        impulsion=gl.vec3f(0),
        radius=30,
    )
    player.pos = initial_player_pos

    transform = player.add_component(
        Transform(player_matrix(player.pos, player.radius)))
    player.add_component(Bindable(mat, name='material'))
    player.add_component(Drawable(mesh))
    player.add_component(Controller(MovePlayer(player, event_manager)))
    player.add_component(
        Controller(AnimatePlayer(
            player=player,
            event_manager=event_manager,
        )))
    return player