コード例 #1
0
ファイル: cubes.py プロジェクト: SuperSimon81/bgfx-python
    def update(self, dt):
        self.elapsed_time += dt
        mouse_x, mouse_y, buttons_states = self.get_mouse_state()
        ImGuiExtra.imgui_begin_frame(int(mouse_x), int(mouse_y),
                                     buttons_states, 0, self.width,
                                     self.height)

        show_example_dialog()
        self._create_imgui_cubes_selection_dialog()

        ImGuiExtra.imgui_end_frame()

        at = (c_float * 3)(*[0.0, 0.0, 0.0])
        eye = (c_float * 3)(*[0.0, 0.0, -35.0])
        up = (c_float * 3)(*[0.0, 1.0, 0.0])

        view = look_at(eye, at, up)
        projection = proj(60.0, self.width / self.height, 0.1, 100.0)

        bgfx.set_view_transform(0, as_void_ptr(view), as_void_ptr(projection))
        bgfx.set_view_rect(0, 0, 0, self.width, self.height)

        bgfx.touch(0)

        for yy in range(0, 11):
            for xx in range(0, 11):
                mtx = rotate_xy(self.elapsed_time + xx * 0.21,
                                self.elapsed_time + yy * 0.37)
                mtx[3, 0] = -15.0 + xx * 3.0
                mtx[3, 1] = -15.0 + yy * 3.0
                mtx[3, 2] = 0.0
                bgfx.set_transform(as_void_ptr(mtx), 1)

                # Set vertex and index buffer.
                bgfx.set_vertex_buffer(0, self.vertex_buffer, 0, num_vertices)
                bgfx.set_index_buffer(
                    self.index_buffers[self.primitive_geometry.value],
                    0,
                    primitives[self.primitive_geometry.value].size,
                )

                bgfx.set_state(
                    bgfx_states[self.primitive_geometry.value]
                    | (BGFX_STATE_WRITE_R if self.write_r.value else 0)
                    | (BGFX_STATE_WRITE_G if self.write_g.value else 0)
                    | (BGFX_STATE_WRITE_B if self.write_b.value else 0)
                    | (BGFX_STATE_WRITE_A if self.write_a.value else 0)
                    | BGFX_STATE_WRITE_Z
                    | BGFX_STATE_DEPTH_TEST_LESS
                    | BGFX_STATE_CULL_CW
                    | BGFX_STATE_MSAA,
                    0,
                )

                bgfx.submit(0, self.main_program, 0, False)

        bgfx.frame()
コード例 #2
0
    def update(self, dt):
        self.elapsed_time += dt
        mouse_x, mouse_y, buttons_states = self.get_mouse_state()
        ImGuiExtra.imgui_begin_frame(int(mouse_x), int(mouse_y),
                                     buttons_states, 0, self.width,
                                     self.height)

        show_example_dialog()

        ImGuiExtra.imgui_end_frame()

        at = (c_float * 3)(*[0.0, 0.0, 0.0])
        eye = (c_float * 3)(*[0.0, 0.0, -15.0])
        up = (c_float * 3)(*[0.0, 1.0, 0.0])

        view = look_at(eye, at, up)
        projection = proj(60.0, self.width / self.height, 0.1, 100.0)

        bgfx.set_view_transform(0, as_void_ptr(view), as_void_ptr(projection))
        bgfx.set_view_rect(0, 0, 0, self.width, self.height)

        bgfx.touch(0)

        for yy in range(-2, 2):
            for xx in range(-2, 2):
                mtx = rotate_xy(self.elapsed_time + xx * 0.51,
                                self.elapsed_time + yy * 0.27)
                mtx[3, 0] = 4 + xx * 3.5
                mtx[3, 1] = 2 + yy * 3.5
                mtx[3, 2] = 0
                bgfx.set_transform(as_void_ptr(mtx), 1)

                # Set vertex and index buffer.
                bgfx.set_vertex_buffer(0, self.vertex_buffer, 0, num_vertices)
                bgfx.set_index_buffer(self.index_buffer, 0, cube_indices.size)

                # Set the texture
                bgfx.set_texture(0, self.texture_uniform, self.logo_texture)

                bgfx.set_state(
                    0
                    | BGFX_STATE_WRITE_RGB
                    | BGFX_STATE_WRITE_A
                    | BGFX_STATE_WRITE_Z
                    | BGFX_STATE_DEPTH_TEST_LESS
                    | BGFX_STATE_MSAA,
                    0,
                )

                bgfx.submit(0, self.main_program, 0, False)

        bgfx.frame()
コード例 #3
0
    def update(self, dt):
        mouse_x, mouse_y, buttons_states = self.get_mouse_state()
        ImGuiExtra.imguiBeginFrame(
            int(mouse_x), int(mouse_y), buttons_states, 0, self.fb_width, self.fb_height
        )
        show_properties_dialog(self.fluid_simulator, self.particle_area, self.hidpi)

        ImGuiExtra.imguiEndFrame()

        vel_y = random.uniform(-0.08, 0.08)
        vel_x = random.uniform(-0.01, 0.1)
        strength = random.uniform(0.01, 0.09)

        at = (c_float * 3)(*[0.0, 0.0, 0.0])
        eye = (c_float * 3)(*[0.0, 0.0, 10.0])
        up = (c_float * 3)(*[0.0, 1.0, 0.0])

        view = look_at(eye, at, up)
        projection = proj(11.4, 1, 0.1, 100.0)

        bgfx.setViewRect(0, 0, 0, self.fb_width, self.fb_height)

        bgfx.setViewTransform(0, as_void_ptr(view), as_void_ptr(projection))

        bgfx.setVertexBuffer(0, self.vertex_buffer, 0, 4)
        bgfx.setIndexBuffer(self.index_buffer, 0, cube_indices.size)

        bgfx.setState(BGFX_STATE_DEFAULT)
        bgfx.setImage(0, self.output_texture, 0, bgfx.Access.Write)

        self.fluid_simulator.add_velocity((0.23, 0.5), (vel_x, vel_y), 34.0)
        self.fluid_simulator.add_circle_obstacle((0.5, 0.7), 30.0)
        self.fluid_simulator.add_triangle_obstacle(
            (0.65, 0.5), (0.42, 0.5), (0.42, 0.39)
        )
        self.fluid_simulator.add_triangle_obstacle(
            (0.65, 0.06), (0.65, 0.39), (0.42, 0.39)
        )
        self.fluid_simulator.update(dt)

        self.particle_area.add_particles((0.2, 0.5), 220.0, strength)
        self.particle_area.update(dt)

        bgfx.dispatch(0, self.cs_program, self.fb_width // 16, self.fb_height // 16)
        bgfx.setTexture(0, self.texture_uniform, self.output_texture)
        bgfx.setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A)
        bgfx.submit(0, self.main_program, 0, False)
        bgfx.frame()