fixed some coordinate issues

This commit is contained in:
arvid schröder 2022-12-06 18:12:58 +01:00
parent 3f19627975
commit 43760a1683

View file

@ -16,25 +16,25 @@ Texture KDTreeRenderer::renderKDTree(FastScene const &scene, Camera const &camer
// IMPLEMENT ME
std::vector<std::vector<int>> intersections;
intersections.reserve(height);
intersections.reserve(width);
int max = 0;
float const aspectRatio = static_cast<float>(height) / static_cast<float>(width);
for (int x = 0; x < image.width(); ++x) {
std::vector<int> ints;
ints.reserve(width);
ints.reserve(height);
for (int y = 0; y < image.height(); ++y) {
Ray ray = camera.createRay((static_cast<float>(x) / image.width() * 2.0f - 1),
-(static_cast<float>(y) / image.height() * 2 - 1) * aspectRatio);
ints.push_back(scene.countNodeIntersections(ray));
max = std::max(ints[x], max);
max = std::max(ints[y], max);
}
intersections.push_back(std::move(ints));
}
std::cout << "done\n";
for (int x = 0; x < image.width(); ++x) {
for (int y = 0; y < image.height(); ++y) {
image.setPixelAt(x, y, clamped((max - intersections[y][x]) * GREEN + intersections[y][x] * RED));
image.setPixelAt(x, y, clamped(static_cast<float>(max - intersections[x][y]) / max * GREEN +
static_cast<float>(intersections[x][y]) / max * RED));
}
}
return image;