rethink interaction with the program #38

Closed
opened 2019-07-26 14:31:58 +02:00 by neoq · 0 comments
neoq commented 2019-07-26 14:31:58 +02:00 (Migrated from github.com)

The use case decribed:

  • continuously accumulate image and display it.
  • save the result when pressing enter. (also save camera or scene maybe)
  • reset the image when i move the camera.

This will be achieved mainly by the new Write function.
This and the "gameloop" are displayed in the code below.

auto write_to_buf_and_update_image = [&](auto x, auto y, auto c) {
    colors[x][y] += c;
    image.setPixel(x, y, sf::Color{colors[x][y] / current_samples});
}

while (true) {
    for (sf::Event event; window.pollEvent(event);) {
        switch (event.type) {
            case sf::Event::Closed:
            window.close();
            return State::Exit;
            break;

            case sf::Event::KeyPressed:
            if (event.key.code == sf::Keyboard::Key::Enter) {
                result.saveToFile("output.png");
            }
            break;
            
            default:
            ;
        } //event type switch
    } //event loop

    window.clear();

    // raytracer.samples == 1
    raytracer.render(write_to_buf_and_update_image);
    ++current_samples;
    //literally the perfect name
    if (const auto changed_camera = control_camera()) {
        neop::all(colors) = Color::black;
        raytracer.camera = changed_camera;
        current_samples = 1;
    }

    texture.update(result);
    window.draw(sprite);
    window.display();
}
The use case decribed: - continuously accumulate image and display it. - save the result when pressing enter. (also save camera or scene maybe) - reset the image when i move the camera. This will be achieved mainly by the new Write function. This and the "gameloop" are displayed in the code below. ```cpp auto write_to_buf_and_update_image = [&](auto x, auto y, auto c) { colors[x][y] += c; image.setPixel(x, y, sf::Color{colors[x][y] / current_samples}); } while (true) { for (sf::Event event; window.pollEvent(event);) { switch (event.type) { case sf::Event::Closed: window.close(); return State::Exit; break; case sf::Event::KeyPressed: if (event.key.code == sf::Keyboard::Key::Enter) { result.saveToFile("output.png"); } break; default: ; } //event type switch } //event loop window.clear(); // raytracer.samples == 1 raytracer.render(write_to_buf_and_update_image); ++current_samples; //literally the perfect name if (const auto changed_camera = control_camera()) { neop::all(colors) = Color::black; raytracer.camera = changed_camera; current_samples = 1; } texture.update(result); window.draw(sprite); window.display(); } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
neop/raytracer#38
No description provided.