#include "camera/camera.h" #include "renderer/simplerenderer.h" #include "scene/scene.h" #include #include #include Texture SimpleRenderer::renderImage(Scene const &scene, Camera const &camera, int width, int height) { Texture image(width, height); // Calculate the aspect ratio float max_x = std::min(1.0f, static_cast(width) / height); float max_y = std::min(1.0f, static_cast(height) / width); // Create the image by casting one ray into the scene for each pixel float pixel_step_x = 2 * max_x / width; float pixel_step_y = 2 * max_y / width; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Ray ray = camera.createRay((x - width/2) * pixel_step_x, (y - width/2) * pixel_step_y); image.setPixelAt(x, y, scene.traceRay(ray)); } } return image; }