aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/camera/camera.cpp7
-rw-r--r--src/mainwindow.cpp24
-rw-r--r--src/mainwindow.h4
-rw-r--r--src/raytracer/raytracer.cpp85
-rw-r--r--src/raytracer/raytracer.h4
-rw-r--r--src/utils/sceneparser.cpp10
6 files changed, 73 insertions, 61 deletions
diff --git a/src/camera/camera.cpp b/src/camera/camera.cpp
index 78ae483..704be7e 100644
--- a/src/camera/camera.cpp
+++ b/src/camera/camera.cpp
@@ -2,6 +2,8 @@
#include "camera.h"
#include "vec4ops/vec4ops.h"
#include "settings.h"
+#include <glm/glm.hpp>
+#include <glm/gtc/matrix_transform.hpp> // Include this header for glm::rotate
Camera::Camera(SceneCameraData cameraData) :
m_pos(cameraData.pos),
@@ -10,6 +12,11 @@ Camera::Camera(SceneCameraData cameraData) :
m_aperture(cameraData.aperture)
{
m_viewMatrix = Vec4Ops::getViewMatrix4(cameraData.look, cameraData.up, cameraData.over);
+ // add settings.xy rotation
+ m_viewMatrix = glm::rotate(m_viewMatrix, glm::radians(settings.xy), glm::vec3(0.f, 1.f, 0.f));
+ m_viewMatrix = glm::rotate(m_viewMatrix, glm::radians(settings.yz), glm::vec3(1.f, 0.f, 0.f));
+ m_viewMatrix = glm::rotate(m_viewMatrix, glm::radians(settings.xz), glm::vec3(0.f, 0.f, 1.f));
+
m_translationVector = -cameraData.pos;
m_inverseViewMatrix = glm::inverse(m_viewMatrix);
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 973d5a7..cb6b7a4 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -206,10 +206,12 @@ void MainWindow::initialize() {
maxTimeLayout->addWidget(maxTimeSpinBox);
maxTimeGroupBox->setLayout(maxTimeLayout);
- // // checkbox
- // rotateNegative = new QCheckBox();
- // rotateNegative->setText(QStringLiteral("Reverse Rotation"));
- // rotateNegative->setChecked(false);
+ // checkbox
+ // bulkRender = new QPushButton();
+ // bulkRender->setText(QStringLiteral("Bulk Render"));
+ rotateNegative = new QPushButton();
+ rotateNegative->setText(QStringLiteral("Render the Scene!"));
+ rotateNegative->setChecked(false);
// w Slider
QGroupBox *wLayout = new QGroupBox(); // horizontal w slider alignment
@@ -224,7 +226,7 @@ void MainWindow::initialize() {
wBox = new QDoubleSpinBox();
wBox->setMinimum(-100.0f);
wBox->setMaximum(100.f);
- wBox->setSingleStep(0.01f);
+ wBox->setSingleStep(0.1f);
wBox->setValue(0.f);
lw->addWidget(wSlider);
@@ -253,7 +255,7 @@ void MainWindow::initialize() {
vLayout->addWidget(maxTimeGroupBox);
vLayout->addWidget(bulkRender);
- // vLayout->addWidget(rotateNegative);
+ vLayout->addWidget(rotateNegative);
connectUIElements();
@@ -284,7 +286,7 @@ void MainWindow::connectUIElements() {
connect(rayTracer, &RayTracer::ywRotationChanged, this, &MainWindow::updateYwSlider);
connect(rayTracer, &RayTracer::zwRotationChanged, this, &MainWindow::updateZwSlider);
connect(rayTracer, &RayTracer::rotationChanged, this, &MainWindow::updateRotationSlider);
- connect(rayTracer, &RayTracer::cameraPositionChanged, this, &MainWindow::updateCameraPosition);
+ // connect(rayTracer, &RayTracer::cameraPositionChanged, this, &MainWindow::updateCameraPosition);
connectW();
}
@@ -343,7 +345,7 @@ void MainWindow::connectMaxTimeSlider() {
}
void MainWindow::connectNegativeRotation() {
- connect(rotateNegative, &QCheckBox::clicked, this, &MainWindow::onRotateNegative);
+ connect(rotateNegative, &QPushButton::clicked, this, &MainWindow::onRotateNegative);
}
void MainWindow::connectW() {
@@ -563,6 +565,6 @@ void MainWindow::updateRotationSlider(float value) {
rayTracer->settingsChanged(imageLabel);
}
-void MainWindow::updateCameraPosition() {
- rayTracer->wSliderChanged(imageLabel);
-}
+// void MainWindow::updateCameraPosition() {
+// rayTracer->wSliderChanged(imageLabel);
+// }
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 06f27be..d8a1dc1 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -53,7 +53,7 @@ private:
QDoubleSpinBox *zwBox;
QSlider *maxTimeSlider;
QSpinBox *maxTimeSpinBox;
- QCheckBox *rotateNegative;
+ QPushButton *rotateNegative;
QSlider *wSlider;
QDoubleSpinBox *wBox;
@@ -86,5 +86,5 @@ private slots:
void updateRotationSlider(float newValue);
void onValChangeWSlider(int newValue);
void onValChangeWBox(double newValue);
- void updateCameraPosition();
+ // void updateCameraPosition();
};
diff --git a/src/raytracer/raytracer.cpp b/src/raytracer/raytracer.cpp
index d6fa14f..3a06910 100644
--- a/src/raytracer/raytracer.cpp
+++ b/src/raytracer/raytracer.cpp
@@ -26,6 +26,14 @@ RayTracer::RayTracer(QWidget *parent) : QWidget(parent) {
m_depth = 500;
m_image = QImage(m_width, m_height, QImage::Format_RGBX8888);
+// m_camera = nullptr;
+}
+
+glm::vec4 getPt(glm::vec3 n1 , glm::vec3 n2 , float perc )
+{
+ glm::vec3 diff = n2 - n1;
+
+ return glm::vec4(n1 + ( diff * perc ), 0.0f);
}
// updated to use 4D
@@ -79,6 +87,7 @@ void RayTracer::render(RGBA *imageData, const RayTraceScene &scene) {
emit settingsChanged(m_imageLabel); // emit to allow the UI to update then render the next frame
}
}
+ emit cameraPositionChanged(m_metaData.cameraData.pos);
}
@@ -219,12 +228,44 @@ void RayTracer::settingsChanged(QLabel* imageLabel) {
image.fill(Qt::black);
RGBA *data = reinterpret_cast<RGBA *>(image.bits());
- RayTraceScene rtScene{ width, height, m_metaData };
+ RayTraceScene rtScene{ m_width, m_height, m_metaData, m_depth };
+ Camera camera = rtScene.getCamera();
+ if (m_controlPointIndex % 3 == 0) {
+ m_controlPoints = camera.m_controlPoints;
+ }
+
+ auto P1 = m_controlPoints[m_controlPointIndex];
+ auto P2 = m_controlPoints[m_controlPointIndex];
+ auto P3 = m_controlPoints[m_controlPointIndex];
+ auto P4 = m_controlPoints[m_controlPointIndex];
+
+ glm::vec4 xa = getPt(P1, P2, settings.currentTime);
+ glm::vec4 xb = getPt(P2, P3, settings.currentTime);
+ glm::vec4 xc = getPt(P3, P4, settings.currentTime);
+
+ // Calculate points on the lines between the above points
+ glm::vec4 xm = getPt(xa, xb, settings.currentTime);
+ glm::vec4 xn = getPt(xb, xc, settings.currentTime);
+
+ // Calculate the final point on the Bezier curve
+ glm::vec4 pointOnCurve = getPt(xm, xn, settings.currentTime);
+ m_metaData.cameraData.pos = pointOnCurve;
+
+ settings.xy += 4.f;
+ if (m_controlPointIndex % 1 == 0) {
+ settings.xz += 8.f;
+ }
+ if (m_controlPointIndex % 3 == 0){
+ settings.yz += 8.f;
+ }
this->render(data, rtScene);
QImage flippedImage = image.mirrored(false, false);
flippedImage = flippedImage.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
imageLabel->setPixmap(QPixmap::fromImage(flippedImage));
+ m_controlPointIndex++;
+
+
// QTimer::singleShot(3500, this, [this, imageLabel]() {
// // This code will be executed after a 2-second delay
// emit rotationChanged(settings.rotation);
@@ -232,48 +273,6 @@ void RayTracer::settingsChanged(QLabel* imageLabel) {
m_image = image;
}
-glm::vec4 getPt(glm::vec3 n1 , glm::vec3 n2 , float perc )
-{
- glm::vec3 diff = n2 - n1;
-
- return glm::vec4(n1 + ( diff * perc ), 0.0f);
-}
-
-void RayTracer::wSliderChanged(QLabel* imageLabel) {
- // auto P1 = cameraControlPoints[0];
- // auto P2 = scene.getCamera().controlPoints[1];
- // auto P3 = scene.getCamera().controlPoints[2];
- // auto P4 = scene.getCamera().controlPoints[3];
- // for( float i = 0 ; i < 1 ; i += 0.01 )
- // {
- // glm::vec3 xa = getPt(P1, P2, i);
- // glm::vec3 xb = getPt(P2, P3, i);
- // glm::vec3 xc = getPt(P3, P4, i);
-
- // // Calculate points on the lines between the above points
- // glm::vec3 xm = getPt(xa, xb, i);
- // glm::vec3 xn = getPt(xb, xc, i);
-
- // // Calculate the final point on the Bezier curve
- // glm::vec3 pointOnCurve = getPt(xm, xn, i);
-
- // // update the camera position
- // m_metaData.cameraData.pos = pointOnCurve;
- // RayTraceScene rtScene{ m_width, m_height, m_metaData, m_depth };
- // this->render(m_imageData, rtScene);
- // QTimer::singleShot(3500, this, [this, imageLabel]() {
- // // This code will be executed after a 2-second delay
- // // emit rotationChanged(settings.rotation);
- // QImage flippedImage = m_image.mirrored(false, false);
- // flippedImage = flippedImage.scaled(m_width, m_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- // imageLabel->setPixmap(QPixmap::fromImage(flippedImage));
- // });
- // }
-
- // emit cameraPositionChanged(m_metaData.cameraData.pos);
-
-}
-
void RayTracer::keyPressEvent(QKeyEvent *event) {
m_keyMap[Qt::Key(event->key())] = true;
std::cout << "key pressed" << std::endl;
diff --git a/src/raytracer/raytracer.h b/src/raytracer/raytracer.h
index 52fc05a..58b1815 100644
--- a/src/raytracer/raytracer.h
+++ b/src/raytracer/raytracer.h
@@ -179,6 +179,10 @@ public:
QImage m_image;
void saveViewportImage(std::string filename);
void wSliderChanged(QLabel* imageLabel);
+
+// Camera m_camera;
+ std::vector<glm::vec3> m_controlPoints;
+ int m_controlPointIndex = 0;
signals:
void xyRotationChanged(float value);
void xzRotationChanged(float value);
diff --git a/src/utils/sceneparser.cpp b/src/utils/sceneparser.cpp
index bc39109..e2015cd 100644
--- a/src/utils/sceneparser.cpp
+++ b/src/utils/sceneparser.cpp
@@ -37,11 +37,11 @@ TextureData loadTextureFromFile(const QString &file) {
// helper to handle recursive creation of tree
void initTree(SceneNode* currentNode, std::vector<RenderShapeData> *shapes, std::vector<SceneLightData> *lights, glm::mat4 currentCTM, glm::vec4 currentTranslation4d) {
- if (currentNode->transformations.size() == 0) {
- SceneParser::translate4(currentTranslation4d, glm::vec4(0.f, -0.0098f * settings.rotation, 0.f, settings.w));
- // currentCTM = glm::translate(glm::mat4(1.0f), glm::vec3(currentTranslation4d));
- currentCTM *= SceneParser::getRotationMatrix4(1.f, glm::vec3(settings.xy, settings.xz, settings.yz), glm::vec3(settings.xw, settings.yw, settings.zw));
- }
+ // if (currentNode->transformations.size() == 0) {
+ // SceneParser::translate4(currentTranslation4d, glm::vec4(0.f, -0.0098f * settings.rotation, 0.f, settings.w));
+ // // currentCTM = glm::translate(glm::mat4(1.0f), glm::vec3(currentTranslation4d));
+ // currentCTM *= SceneParser::getRotationMatrix4(1.f, glm::vec3(settings.xy, settings.xz, settings.yz), glm::vec3(settings.xw, settings.yw, settings.zw));
+ // }
SceneParser::translate4(currentTranslation4d, glm::vec4(0.f, 0.f, 0.f, settings.w));