diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-12-08 15:03:20 -0500 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-12-08 15:03:24 -0500 |
commit | 480c22ce9b50caad259e254d0127e99294b4c6ab (patch) | |
tree | 2edd19cfbf756aef0f9b2f1060ca458a5c27cd4f /src | |
parent | 3c39ba9ce8710332c87e713d0881fcc7a510b8f2 (diff) |
rename src directory for vec4ops
Diffstat (limited to 'src')
-rw-r--r-- | src/raytracer/raytracer.cpp | 48 | ||||
-rw-r--r-- | src/vec4ops/rotations4d.cpp (renamed from src/4dvecops/rotations4d.cpp) | 0 | ||||
-rw-r--r-- | src/vec4ops/transform4d.cpp (renamed from src/4dvecops/transform4d.cpp) | 0 | ||||
-rw-r--r-- | src/vec4ops/vec4ops.cpp (renamed from src/4dvecops/vec4ops.cpp) | 0 | ||||
-rw-r--r-- | src/vec4ops/vec4ops.h (renamed from src/4dvecops/vec4ops.h) | 0 |
5 files changed, 26 insertions, 22 deletions
diff --git a/src/raytracer/raytracer.cpp b/src/raytracer/raytracer.cpp index be31b8a..6b33150 100644 --- a/src/raytracer/raytracer.cpp +++ b/src/raytracer/raytracer.cpp @@ -7,7 +7,7 @@ #include "mainwindow.h" #include <QKeyEvent> #include <QTimerEvent> - +#include "vec4ops/vec4ops.h" // RayTracer::RayTracer(const Config &config) : m_config(config) {} RayTracer::RayTracer(QWidget *parent) : QWidget(parent) { @@ -23,13 +23,8 @@ RayTracer::RayTracer(QWidget *parent) : QWidget(parent) { } +// updated to use 4D void RayTracer::render(RGBA *imageData, const RayTraceScene &scene) { - if(m_enableParallelism) - { - renderParallel(imageData, scene); - return; - } - // naive rendering Camera camera = scene.getCamera(); float cameraDepth = 1.f; @@ -39,21 +34,30 @@ void RayTracer::render(RGBA *imageData, const RayTraceScene &scene) { for (int imageRow = 0; imageRow < scene.height(); imageRow++) { for (int imageCol = 0; imageCol < scene.width(); imageCol++) { - float xCameraSpace = viewplaneWidth * - (-.5f + (imageCol + .5f) / scene.width()); - float yCameraSpace = viewplaneHeight * - (-.5f + (imageRow + .5f) / scene.height()); - - glm::vec4 pixelDirCamera{xCameraSpace, -yCameraSpace, -cameraDepth, 0.f}; //w=0 for dir - glm::vec4 eyeCamera{0.f, 0.f, 0.f, 1.f}; // w=1.f for point - - // convert to world space - glm::vec4 pWorld = camera.getInverseViewMatrix() * eyeCamera; - glm::vec4 dWorld = glm::normalize(camera.getInverseViewMatrix() * pixelDirCamera); - - // cast ray! - glm::vec4 pixel = getPixelFromRay(pWorld, dWorld, scene); - imageData[imageRow * scene.width() + imageCol] = toRGBA(pixel); + // FIXME: for now, use height as depth + for (int imageDepth = 0; imageDepth < scene.height(); imageDepth++) { + // compute the ray + float x = (imageCol - scene.width()/2.f) * viewplaneWidth / scene.width(); + float y = (imageRow - scene.height()/2.f) * viewplaneHeight / scene.height(); + float z = (imageDepth - scene.height()/2.f) * viewplaneHeight / scene.height(); + float camera4dDepth = 1; + + glm::vec4 pCamera = + glm::vec4 pWorld = Vec4Ops::transformPoint4(camera.getvec4(x, y, z, camera4dDepth); + glm::vec4 dWorld = glm::vec4(0.f, 0.f, -1.f, 0.f); + + // get the pixel color + glm::vec4 pixelColor = getPixelFromRay(pWorld, dWorld, scene, 0); + + // set the pixel color + int index = imageRow * scene.width() + imageCol; + imageData[index] = RGBA{ + (std::uint8_t) (pixelColor.r * 255.f), + (std::uint8_t) (pixelColor.g * 255.f), + (std::uint8_t) (pixelColor.b * 255.f), + (std::uint8_t) (pixelColor.a * 255.f) + }; + } } } } diff --git a/src/4dvecops/rotations4d.cpp b/src/vec4ops/rotations4d.cpp index 4943c7f..4943c7f 100644 --- a/src/4dvecops/rotations4d.cpp +++ b/src/vec4ops/rotations4d.cpp diff --git a/src/4dvecops/transform4d.cpp b/src/vec4ops/transform4d.cpp index 5cc51f3..5cc51f3 100644 --- a/src/4dvecops/transform4d.cpp +++ b/src/vec4ops/transform4d.cpp diff --git a/src/4dvecops/vec4ops.cpp b/src/vec4ops/vec4ops.cpp index 80cebaf..80cebaf 100644 --- a/src/4dvecops/vec4ops.cpp +++ b/src/vec4ops/vec4ops.cpp diff --git a/src/4dvecops/vec4ops.h b/src/vec4ops/vec4ops.h index d1c3ac8..d1c3ac8 100644 --- a/src/4dvecops/vec4ops.h +++ b/src/vec4ops/vec4ops.h |