diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/camera/camera.cpp | 5 | ||||
-rw-r--r-- | src/mainwindow.cpp | 121 | ||||
-rw-r--r-- | src/mainwindow.h | 8 | ||||
-rw-r--r-- | src/physics/physics.cpp | 10 | ||||
-rw-r--r-- | src/raytracer/raytracer.cpp | 171 | ||||
-rw-r--r-- | src/raytracer/raytracer.h | 2 | ||||
-rw-r--r-- | src/settings.h | 4 |
7 files changed, 242 insertions, 79 deletions
diff --git a/src/camera/camera.cpp b/src/camera/camera.cpp index 69f2787..172c5de 100644 --- a/src/camera/camera.cpp +++ b/src/camera/camera.cpp @@ -12,8 +12,9 @@ void Camera::updateViewMatrix(SceneCameraData cameraData) { m_viewMatrix = glm::rotate(m_viewMatrix, glm::radians(settings.xz), glm::vec3(0.f, 0.f, 1.f)); - // TODO: link sliders here. make them smaller changes since our objects are so small - glm::vec4 uiTranslation = glm::vec4(settings.xw, settings.yw, 0.f, settings.zw); + // TODO: rename & link sliders here. also add one more for the fourth dimension. + // make them smaller intervals on the sliders since our objects are so small + glm::vec4 uiTranslation = glm::vec4(settings.xw, settings.yw, settings.z, settings.zw); m_translationVector = -cameraData.pos + uiTranslation; m_inverseViewMatrix = glm::inverse(m_viewMatrix); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ac65c1f..e9a13ac 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -26,34 +26,37 @@ void MainWindow::initialize() { font.setPointSize(12); font.setBold(true); QLabel *xy_label = new QLabel(); // XY label - xy_label->setText("XY value:"); + xy_label->setText("Rotation XY angle (J,L)"); xy_label->setFont(font); QLabel *xz_label = new QLabel(); // XZ label - xz_label->setText("XZ value:"); + xz_label->setText("Rotation XZ angle (I, M)"); xz_label->setFont(font); QLabel *xw_label = new QLabel(); // XW label - xw_label->setText("XW value:"); + xw_label->setText("Translate X (W,S)"); xw_label->setFont(font); QLabel *yz_label = new QLabel(); // YZ label - yz_label->setText("YZ value:"); + yz_label->setText("Rotation YZ angle (O, N):"); yz_label->setFont(font); QLabel *yw_label = new QLabel(); // YW label - yw_label->setText("YW value:"); + yw_label->setText("Translate Y (A, D)"); yw_label->setFont(font); QLabel *zw_label = new QLabel(); // ZW label - zw_label->setText("ZW value:"); + zw_label->setText("Translate W (R, F):"); zw_label->setFont(font); + QLabel *z_label = new QLabel(); // W label + z_label->setText("Translate Z (T, G):"); + z_label->setFont(font); QLabel *w_label = new QLabel(); // W label - w_label->setText("W value:"); + w_label->setText("Voxel Depth:"); w_label->setFont(font); currTimeLabel = new QLabel(); // Current Time label - currTimeLabel->setText("Curr Time: 0"); + currTimeLabel->setText("Curr Time: 0 Max Time:"); currTimeLabel->setFont(font); - QLabel *max_time_label = new QLabel(); // Max Time label - max_time_label->setText("Max Time:"); - max_time_label->setFont(font); + // QLabel *max_time_label = new QLabel(); // Max Time label + // max_time_label->setText("Max Time:"); + // max_time_label->setFont(font); // Create file uploader for scene file @@ -79,7 +82,7 @@ void MainWindow::initialize() { xyBox = new QDoubleSpinBox(); xyBox->setMinimum(0.0f); xyBox->setMaximum(360.f); - xyBox->setSingleStep(1.f); + xyBox->setSingleStep(0.1f); xyBox->setValue(0.f); lxy->addWidget(xySlider); @@ -99,7 +102,7 @@ void MainWindow::initialize() { xzBox = new QDoubleSpinBox(); xzBox->setMinimum(0.0f); xzBox->setMaximum(360.f); - xzBox->setSingleStep(1.f); + xzBox->setSingleStep(0.1f); xzBox->setValue(0.f); lxz->addWidget(xzSlider); @@ -112,14 +115,14 @@ void MainWindow::initialize() { xwSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider xwSlider->setTickInterval(1); - xwSlider->setMinimum(0); - xwSlider->setMaximum(36000); + xwSlider->setMinimum(-10000); + xwSlider->setMaximum(10000); xwSlider->setValue(0); xwBox = new QDoubleSpinBox(); - xwBox->setMinimum(0.0f); - xwBox->setMaximum(360.f); - xwBox->setSingleStep(1.f); + xwBox->setMinimum(-100.0f); + xwBox->setMaximum(100.f); + xwBox->setSingleStep(0.1f); xwBox->setValue(0.f); lxw->addWidget(xwSlider); @@ -139,7 +142,7 @@ void MainWindow::initialize() { yzBox = new QDoubleSpinBox(); yzBox->setMinimum(0.0f); yzBox->setMaximum(360.f); - yzBox->setSingleStep(1.f); + yzBox->setSingleStep(0.1f); yzBox->setValue(0.f); lyz->addWidget(yzSlider); @@ -152,14 +155,14 @@ void MainWindow::initialize() { ywSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider ywSlider->setTickInterval(1); - ywSlider->setMinimum(0); - ywSlider->setMaximum(36000); + ywSlider->setMinimum(-10000); + ywSlider->setMaximum(10000); ywSlider->setValue(0); ywBox = new QDoubleSpinBox(); - ywBox->setMinimum(0.0f); - ywBox->setMaximum(360.f); - ywBox->setSingleStep(1.f); + ywBox->setMinimum(-100.0f); + ywBox->setMaximum(100.f); + ywBox->setSingleStep(0.1f); ywBox->setValue(0.f); lyw->addWidget(ywSlider); @@ -172,20 +175,40 @@ void MainWindow::initialize() { zwSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider zwSlider->setTickInterval(1); - zwSlider->setMinimum(0); - zwSlider->setMaximum(36000); + zwSlider->setMinimum(-10000); + zwSlider->setMaximum(10000); zwSlider->setValue(0); zwBox = new QDoubleSpinBox(); - zwBox->setMinimum(0.0f); - zwBox->setMaximum(360.f); - zwBox->setSingleStep(1.f); + zwBox->setMinimum(-100.0f); + zwBox->setMaximum(100.f); + zwBox->setSingleStep(0.1f); zwBox->setValue(0.f); lzw->addWidget(zwSlider); lzw->addWidget(zwBox); zwLayout->setLayout(lzw); + // translate z + QGroupBox *zLayout = new QGroupBox(); // horizontal w slider alignment + QHBoxLayout *lz = new QHBoxLayout(); + + zSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider + zSlider->setTickInterval(1); + zSlider->setMinimum(-10000); + zSlider->setMaximum(10000); + zSlider->setValue(0); + + zBox = new QDoubleSpinBox(); + zBox->setMinimum(-100.0f); + zBox->setMaximum(100.f); + zBox->setSingleStep(0.1f); + zBox->setValue(0.f); + + lz->addWidget(zSlider); + lz->addWidget(zBox); + zLayout->setLayout(lz); + // Max Time Slider QGroupBox *maxTimeGroupBox = new QGroupBox(); // horizontal QHBoxLayout *maxTimeLayout = new QHBoxLayout(); @@ -235,7 +258,7 @@ void MainWindow::initialize() { vLayout->addWidget(uploadFile); - vLayout->addWidget(saveImage); + // vLayout->addWidget(saveImage); vLayout->addWidget(xy_label); vLayout->addWidget(xyLayout); vLayout->addWidget(xz_label); @@ -248,10 +271,12 @@ void MainWindow::initialize() { vLayout->addWidget(ywLayout); vLayout->addWidget(zw_label); vLayout->addWidget(zwLayout); + vLayout->addWidget(z_label); + vLayout->addWidget(zLayout); vLayout->addWidget(w_label); vLayout->addWidget(wLayout); vLayout->addWidget(currTimeLabel); - vLayout->addWidget(max_time_label); + // vLayout->addWidget(max_time_label); vLayout->addWidget(maxTimeGroupBox); vLayout->addWidget(bulkRender); @@ -277,6 +302,7 @@ void MainWindow::connectUIElements() { connectyz(); connectyw(); connectzw(); + connectz(); connectMaxTimeSlider(); connectNegativeRotation(); connect(rayTracer, &RayTracer::xyRotationChanged, this, &MainWindow::updateXySlider); @@ -285,6 +311,8 @@ void MainWindow::connectUIElements() { connect(rayTracer, &RayTracer::yzRotationChanged, this, &MainWindow::updateYzSlider); connect(rayTracer, &RayTracer::ywRotationChanged, this, &MainWindow::updateYwSlider); connect(rayTracer, &RayTracer::zwRotationChanged, this, &MainWindow::updateZwSlider); + connect(rayTracer, &RayTracer::zChanged, this, &MainWindow::updateZSlider); + connect(rayTracer, &RayTracer::rotationChanged, this, &MainWindow::updateRotationSlider); // connect(rayTracer, &RayTracer::cameraPositionChanged, this, &MainWindow::updateCameraPosition); connect(rayTracer, &RayTracer::timeValueChanged, this, &MainWindow::updateTimeValue); @@ -339,6 +367,26 @@ void MainWindow::connectzw() { this, &MainWindow::onValChangezwBox); } +void MainWindow::connectz() { + connect(zSlider, &QSlider::valueChanged, this, &MainWindow::onValChangezSlider); + connect(zBox, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWindow::onValChangezBox); +} + +void MainWindow::onValChangezSlider(int newValue) { + //wSlider->setValue(newValue); + zBox->setValue(newValue/100.f); + settings.z = zBox->value(); + rayTracer->settingsChanged(imageLabel); +} + +void MainWindow::onValChangezBox(double newValue) { + zSlider->setValue(int(newValue*100.f)); + //wBox->setValue(newValue); + settings.z = zBox->value(); + rayTracer->settingsChanged(imageLabel); +} + void MainWindow::connectMaxTimeSlider() { connect(maxTimeSlider, &QSlider::valueChanged, this, &MainWindow::onValChangeMaxTimeSlider); connect(maxTimeSpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), @@ -526,6 +574,7 @@ void MainWindow::onRotateNegative() { void MainWindow::updateXySlider(double value) { xySlider->setValue(int(value*100.f)); xyBox->setValue(value); + settings.xy = xyBox->value(); rayTracer->settingsChanged(imageLabel); } @@ -570,5 +619,13 @@ void MainWindow::updateRotationSlider(float value) { // } void MainWindow::updateTimeValue() { - currTimeLabel->setText("Curr Time: " + QString::number(settings.currentTime)); + currTimeLabel->setText("Curr Time: " + QString::number(settings.currentTime) + " Max Time:"); + // rayTracer->settingsChanged(imageLabel); +} + +void MainWindow::updateZSlider(double value) { + // TODO IDK why the values are not changin + zSlider->setValue(int(settings.z*100.f)); + zBox->setValue(settings.z); + rayTracer->settingsChanged(imageLabel); } diff --git a/src/mainwindow.h b/src/mainwindow.h index b608dd5..ff0d203 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -33,6 +33,7 @@ private: void connectMaxTimeSlider(); void connectNegativeRotation(); void connectW(); + void connectz(); RayTracer *rayTracer; AspectRatioWidget *aspectRatioWidget; @@ -57,6 +58,8 @@ private: QSlider *wSlider; QDoubleSpinBox *wBox; QLabel *currTimeLabel; + QSlider *zSlider; + QDoubleSpinBox *zBox; private slots: @@ -89,4 +92,9 @@ private slots: void onValChangeWBox(double newValue); // void updateCameraPosition(); void updateTimeValue(); + + void onValChangezSlider(int newValue); + void onValChangezBox(double newValue); + void updateZSlider(double newValue); + }; diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 31b2cc7..53d4537 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -33,7 +33,7 @@ bool sphereCube(RenderShapeData *sphere, RenderShapeData *cube) else if (sphereCenter.w > maxes.w) distSquared -= (sphereCenter.w - maxes.w)*(sphereCenter.w - maxes.w); if (distSquared > 0) { - std::cout << "distanceSquared: " << distSquared << std::endl; + // std::cout << "distanceSquared: " << distSquared << std::endl; // update velocity of the objects sphere->velocity *= -1.f; @@ -74,7 +74,7 @@ bool cubeCube(RenderShapeData *c1, RenderShapeData *c2) { bool intersect = xOverlap && yOverlap && zOverlap && wOverlap; if (intersect) { - std::cout << "intersect: " << intersect << std::endl; + // std::cout << "intersect: " << intersect << std::endl; // update velocity of the objects, based on math, assuming the objects are the same mass c1->velocity *= -1.f; @@ -101,13 +101,13 @@ bool sphereSphere(RenderShapeData *s1, RenderShapeData *s2) // update velocity if (distance <= radius + radius) { - std::cout << "distance: " << distance << std::endl; +// std::cout << "distance: " << distance << std::endl; s1->velocity *= -1.f; s2->velocity *= -1.f; // print the new velocity - std::cout << "s1 velocity: " << s1->velocity.x << ", " << s1->velocity.y << ", " << s1->velocity.z << ", " << s1->velocity.w << std::endl; - std::cout << "s2 velocity: " << s2->velocity.x << ", " << s2->velocity.y << ", " << s2->velocity.z << ", " << s2->velocity.w << std::endl; +// std::cout << "s1 velocity: " << s1->velocity.x << ", " << s1->velocity.y << ", " << s1->velocity.z << ", " << s1->velocity.w << std::endl; +// std::cout << "s2 velocity: " << s2->velocity.x << ", " << s2->velocity.y << ", " << s2->velocity.z << ", " << s2->velocity.w << std::endl; // move the objects in new dir so they don't collide again s1->translation4d += s1->velocity * (1.1f); diff --git a/src/raytracer/raytracer.cpp b/src/raytracer/raytracer.cpp index 6202937..385e57d 100644 --- a/src/raytracer/raytracer.cpp +++ b/src/raytracer/raytracer.cpp @@ -11,6 +11,8 @@ #include <QTimerEvent> #include "vec4ops/vec4ops.h" #include "physics/physics.h" +#include <glm/glm.hpp> +#include <glm/gtc/matrix_transform.hpp> // Include this header for glm::rotate // RayTracer::RayTracer(const Config &config) : m_config(config) {} RayTracer::RayTracer(QWidget *parent) : QWidget(parent) { @@ -51,6 +53,70 @@ void RayTracer::render(RGBA *imageData, const RayTraceScene &scene) { saveViewportImage(filePath); if (settings.currentTime < settings.maxTime) { // still more to render // render the next frame + if (m_enableCameraBezier) { + Camera camera = scene.getCamera(); + if (settings.currentTime % 4 == 0) { + m_controlPoints = camera.m_controlPoints; + } + + auto time = (settings.currentTime % 60)/60.f; + + auto P1 = m_controlPoints[0]; + auto P2 = m_controlPoints[1]; + auto P3 = m_controlPoints[2]; + auto P4 = m_controlPoints[3]; + + glm::vec4 xa = getPt(P1, P2, time); + glm::vec4 xb = getPt(P2, P3, time); + glm::vec4 xc = getPt(P3, P4, time); + + // Calculate points on the lines between the above points + glm::vec4 xm = getPt(xa, xb, time); + glm::vec4 xn = getPt(xb, xc, time); + + // Calculate the final point on the Bezier curve + glm::vec4 pointOnCurve = getPt(xm, xn, time); + // std::cout << "point on curve: " << pointOnCurve.x << ", " << pointOnCurve.y << ", " << pointOnCurve.z << ", " << pointOnCurve.w << std::endl; + // std::cout << "camera pos" << m_metaData.cameraData.pos.x << ", " << m_metaData.cameraData.pos.y << ", " << m_metaData.cameraData.pos.z << ", " << m_metaData.cameraData.pos.w << std::endl; + + // rotate the camera about the origin + glm::vec4 cameraPos = m_metaData.cameraData.pos; + if (settings.currentTime < 22) { + glm::vec4 cameraPosRotated = glm::rotate(glm::mat4(1.f), glm::radians(10.0f), glm::vec3(0.f, 1.f, 0.f)) * glm::vec4(cameraPos.x, cameraPos.y, 0.f, 1.f); + + if (settings.currentTime % 2 == 0) { + cameraPosRotated = glm::rotate(glm::mat4(1.f), glm::radians(2.0f), glm::vec3(1.f, 0.f, 0.f)) * cameraPosRotated; + } + cameraPosRotated = glm::rotate(glm::mat4(1.f), glm::radians(-3.0f), glm::vec3(1.f, 0.f, 0.f)) * cameraPosRotated; + + // if (settings.currentTime % 3 == 0) { + // cameraPosRotated = glm::rotate(glm::mat4(1.f), glm::radians(4.0f), glm::vec3(0.f, 0.f, 1.f)) * cameraPosRotated; + // } + // cameraPosRotated = glm::rotate(glm::mat4(1.f), glm::radians(-2.0f), glm::vec3(0.f, 0.f, 1.f)) * cameraPosRotated; + + m_metaData.cameraData.pos = glm::vec4(cameraPosRotated.x, cameraPosRotated.y, cameraPos.z, 1.f); + } + // m_metaData.cameraData.pos = glm::vec4(pointOnCurve.x, pointOnCurve.y, pointOnCurve.z, 1.f); + + settings.xy += 4.f; + if (settings.currentTime > 22) { + settings.xy -= 4.f; + settings.xz -= 2.f; + } + if (settings.currentTime % 1 == 0) { + settings.xz += 2.f; + if (settings.currentTime > 22) { + settings.yz -= 2.f; + } + } + if (settings.currentTime % 3 == 0){ + settings.xz -= 3.f; + if (settings.currentTime > 2) { + settings.xz += 3.f; + } + } + + } settings.currentTime++; // settings.w++; @@ -181,7 +247,7 @@ void RayTracer::sceneChanged(QLabel* imageLabel) { QImage flippedImage = image.mirrored(false, false); flippedImage = flippedImage.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); imageLabel->setPixmap(QPixmap::fromImage(flippedImage)); - m_controlPointIndex++; + // m_controlPointIndex++; // QTimer::singleShot(3500, this, [this, imageLabel]() { @@ -270,60 +336,89 @@ void RayTracer::sceneChanged(QLabel* imageLabel) { void RayTracer::keyPressEvent(QKeyEvent *event) { m_keyMap[Qt::Key(event->key())] = true; std::cout << "key pressed" << std::endl; - if (m_keyMap[Qt::Key_1]) { + + // J and L for xy rotation + if (m_keyMap[Qt::Key_J]) { std::cout << "key 1" << std::endl; - if (settings.negative) { - settings.xy -= settings.rotation; - } else { settings.xy += settings.rotation; - } + emit xyRotationChanged(settings.xy); + } + if (m_keyMap[Qt::Key_L]) { + settings.xy -= settings.rotation; emit xyRotationChanged(settings.xy); } - if (m_keyMap[Qt::Key_2]) { - if (settings.negative) { - settings.xz -= settings.rotation; - } else { - settings.xz += settings.rotation; - } + // I and M for xz rotation + if (m_keyMap[Qt::Key_I]) { + settings.xz += settings.rotation; emit xzRotationChanged(settings.xz); } - - if (m_keyMap[Qt::Key_3]) { - if (settings.negative) { - settings.xw -= settings.rotation; - } else { - settings.xw += settings.rotation; - } - emit xwRotationChanged(settings.xw); + if (m_keyMap[Qt::Key_M]) { + settings.xz -= settings.rotation; + emit xzRotationChanged(settings.xz); } - if (m_keyMap[Qt::Key_4]) { - if (settings.negative) { - settings.yz -= settings.rotation; - } else { - settings.yz += settings.rotation; - } + // O and N for yz rotation + if (m_keyMap[Qt::Key_O]) { + settings.yz += settings.rotation; + emit yzRotationChanged(settings.yz); + } + if (m_keyMap[Qt::Key_N]) { + settings.yz -= settings.rotation; emit yzRotationChanged(settings.yz); } - if (m_keyMap[Qt::Key_5]) { - if (settings.negative) { - settings.yw -= settings.rotation; - } else { - settings.yw += settings.rotation; - } + // W and S for x translation + if (m_keyMap[Qt::Key_W]) { + settings.xw += settings.translation; + emit xwRotationChanged(settings.xw); + } + if (m_keyMap[Qt::Key_S]) { + settings.xw -= settings.translation; + emit xwRotationChanged(settings.xw); + } + + // A and D for y translation + if (m_keyMap[Qt::Key_A]) { + settings.yw += settings.translation; + emit yzRotationChanged(settings.yw); + } + if (m_keyMap[Qt::Key_D]) { + settings.yw -= settings.translation; emit ywRotationChanged(settings.yw); } - if (m_keyMap[Qt::Key_6]) { - if (settings.negative) { - settings.zw -= settings.rotation; - } else { - settings.zw += settings.rotation; - } + // TODO: add slider for z translation + // T and G for z translation + if (m_keyMap[Qt::Key_T]) { + settings.z += settings.translation; + emit zChanged(settings.zw); + } + + if (m_keyMap[Qt::Key_G]) { + settings.z -= settings.translation; + emit zChanged(settings.zw); + } + + // R & F for w translation using zw + if (m_keyMap[Qt::Key_R]) { + settings.zw += settings.translation; + emit zwRotationChanged(settings.zw); + } + if (m_keyMap[Qt::Key_F]) { + settings.zw -= settings.translation; emit zwRotationChanged(settings.zw); } + + // TODO: ONLY IF HAVE TIME, NOT NEEDED + // Space & V for vorex depth + if (m_keyMap[Qt::Key_Space]) { + settings.w += settings.rotation; + + } + if (m_keyMap[Qt::Key_V]) { + settings.w -= settings.rotation; + } } void RayTracer::keyReleaseEvent(QKeyEvent *event) { diff --git a/src/raytracer/raytracer.h b/src/raytracer/raytracer.h index 1d88de9..7118840 100644 --- a/src/raytracer/raytracer.h +++ b/src/raytracer/raytracer.h @@ -155,6 +155,7 @@ public: bool m_enableAntiAliasing = false; bool m_enableDepthOfField = false; bool m_enableSuperSample = false; + bool m_enableCameraBezier = true; void sceneChanged(QLabel* imageLabel); void settingsChanged(QLabel* imageLabel); @@ -194,5 +195,6 @@ signals: void rotationChanged(float value); void cameraPositionChanged(glm::vec3 value); void timeValueChanged(int value); + void zChanged(int value); }; diff --git a/src/settings.h b/src/settings.h index 32c6484..8a9321f 100644 --- a/src/settings.h +++ b/src/settings.h @@ -12,8 +12,8 @@ struct Settings { float xw = 0.f; float yw = 0.f; float zw = 0.f; - float rotation = 0.f; - bool negative = false; + float rotation = 5.f; + float translation = .1f; float w = 0.f; int currentTime = 0; int maxTime = 0; |