diff --git a/headers/FractalData.hpp b/headers/FractalData.hpp index a0149b4..ee11bd3 100644 --- a/headers/FractalData.hpp +++ b/headers/FractalData.hpp @@ -37,6 +37,7 @@ class FractalData { QVector3D camera = baseCamera; qreal zoomCoefficient = defaultZoom; qreal rotateSpeed = defaultSpeed; + qreal absoluteSpeed = defaultSpeed; bool isRotating = false; @@ -48,6 +49,8 @@ class FractalData { void setZoomCoefficient(qreal zoomCoefficient = defaultZoom); + void setAbsoluteSpeed(qreal absoluteSpeed); + [[nodiscard]] QJsonObject serialize() const; void readFrom(QJsonDocument &in); diff --git a/headers/FractalWidget.hpp b/headers/FractalWidget.hpp index b3771b9..b82f8fe 100644 --- a/headers/FractalWidget.hpp +++ b/headers/FractalWidget.hpp @@ -3,8 +3,10 @@ #include "FractalData.hpp" #include "GeometryEngine.hpp" +#include #include #include +#include #include #include #include @@ -12,6 +14,8 @@ #include #include #include +#include +#include class FractalWidget : public QOpenGLWidget, protected QOpenGLFunctions { Q_OBJECT @@ -56,5 +60,5 @@ class FractalWidget : public QOpenGLWidget, protected QOpenGLFunctions { QVector2D mousePressPosition; QVector3D pointAxisX = QVector3D(1.0, 0.0, 1.5); QVector3D pointAxisY = QVector3D(0.0, 1.0, 1.5); - qreal autoRotationPos = 0.0; + qreal autoRotationPos = 0.0; }; diff --git a/src/FractalData.cpp b/src/FractalData.cpp index 09239df..e1998b8 100644 --- a/src/FractalData.cpp +++ b/src/FractalData.cpp @@ -118,3 +118,7 @@ FractalData::FractalData(qreal a, qreal b, qreal c, quint8 n, FractalType type, void FractalData::setZoomCoefficient(qreal zoomCoefficient) { FractalData::zoomCoefficient = zoomCoefficient; } + +void FractalData::setAbsoluteSpeed(qreal absoluteSpeed) { + FractalData::absoluteSpeed = absoluteSpeed; +} diff --git a/src/FractalWidget.cpp b/src/FractalWidget.cpp index 10997f5..d564308 100644 --- a/src/FractalWidget.cpp +++ b/src/FractalWidget.cpp @@ -1,9 +1,5 @@ #include "FractalWidget.hpp" -#include -#include -#include -#include namespace { QVector3D transformColor(const QColor &color) { @@ -51,21 +47,21 @@ void FractalWidget::mouseReleaseEvent(QMouseEvent *) { } namespace { -QVector3D rotate(QVector3D point, qreal alpha, QVector3D axis) { - qreal t11 = cos(alpha) + (1 - cos(alpha)) * axis.x() * axis.x(); - qreal t12 = (1 - cos(alpha)) * axis.x() * axis.y() - sin(alpha) * axis.z(); - qreal t13 = (1 - cos(alpha)) * axis.x() * axis.z() + sin(alpha) * axis.y(); - qreal t21 = (1 - cos(alpha)) * axis.x() * axis.y() + sin(alpha) * axis.z(); - qreal t22 = cos(alpha) + (1 - cos(alpha)) * axis.y() * axis.y(); - qreal t23 = (1 - cos(alpha)) * axis.y() * axis.z() - sin(alpha) * axis.x(); - qreal t31 = (1 - cos(alpha)) * axis.x() * axis.z() - sin(alpha) * axis.y(); - qreal t32 = (1 - cos(alpha)) * axis.y() * axis.z() + sin(alpha) * axis.x(); - qreal t33 = cos(alpha) + (1 - cos(alpha)) * axis.z() * axis.z(); - return QVector3D(point.x() * t11 + point.y() * t21 + point.z() * t31, - point.x() * t12 + point.y() * t22 + point.z() * t32, - point.x() * t13 + point.y() * t23 + point.z() * t33); -} -}; + QVector3D rotate(QVector3D point, qreal alpha, QVector3D axis) { + qreal t11 = cos(alpha) + (1 - cos(alpha)) * axis.x() * axis.x(); + qreal t12 = (1 - cos(alpha)) * axis.x() * axis.y() - sin(alpha) * axis.z(); + qreal t13 = (1 - cos(alpha)) * axis.x() * axis.z() + sin(alpha) * axis.y(); + qreal t21 = (1 - cos(alpha)) * axis.x() * axis.y() + sin(alpha) * axis.z(); + qreal t22 = cos(alpha) + (1 - cos(alpha)) * axis.y() * axis.y(); + qreal t23 = (1 - cos(alpha)) * axis.y() * axis.z() - sin(alpha) * axis.x(); + qreal t31 = (1 - cos(alpha)) * axis.x() * axis.z() - sin(alpha) * axis.y(); + qreal t32 = (1 - cos(alpha)) * axis.y() * axis.z() + sin(alpha) * axis.x(); + qreal t33 = cos(alpha) + (1 - cos(alpha)) * axis.z() * axis.z(); + return QVector3D(point.x() * t11 + point.y() * t21 + point.z() * t31, + point.x() * t12 + point.y() * t22 + point.z() * t32, + point.x() * t13 + point.y() * t23 + point.z() * t33); + } +};// namespace void FractalWidget::rotateFractal(QVector2D const &diff) { if(diff.x() == 0 && diff.y() == 0) @@ -154,9 +150,9 @@ void FractalWidget::paintGL() { QMatrix4x4 matrix; matrix.translate(0.0, 0.0, fractalData->zoomCoefficient); - matrix.lookAt(fractalData->camera, -fractalData->camera, pointAxisY - fractalData->camera); + matrix.lookAt(fractalData->camera, -fractalData->camera, pointAxisY - fractalData->camera); - program.setUniformValue("mvp_matrix", projection * matrix); + program.setUniformValue("mvp_matrix", projection * matrix); program.setUniformValue("POWER", (GLint) fractalData->n); program.setUniformValue("Resolution", dynamic_cast(QCoreApplication::instance())->devicePixelRatio() * QVector2D(this->width(), this->height())); @@ -179,9 +175,9 @@ void FractalWidget::setFractalData(FractalData *data) { void FractalWidget::autoRotate() { if(fractalData->isRotating) { - qreal nextPos = static_cast(elapsedTimer->elapsed()); - qreal dx = (nextPos - autoRotationPos) / 5; + auto nextPos = static_cast(elapsedTimer->elapsed()); + qreal dx = (nextPos - autoRotationPos) * fractalData->absoluteSpeed; autoRotationPos = nextPos; - rotateFractal({dx, 0.0}); + rotateFractal({static_cast(dx), 0.0}); } } diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 9755b94..e2f139e 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -24,6 +24,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->setupUi(this); ui->recordWidget->close(); prevSize = this->size(); + ui->rotationSlider->setValue(100 * FractalData::defaultSpeed); connectBoxBar(); connect(ui->recordButton, &QPushButton::clicked, [&]() { recordClickAction(); }); setValues(); @@ -112,11 +113,15 @@ void MainWindow::connectBoxBar() { connect(ui->fractalColorButton, &QPushButton::clicked, [&]() { askColor(FRACTAL); }); connect(ui->ambienceColorButton, &QPushButton::clicked, [&]() { askColor(AMBIENCE); }); connect(ui->randomizeButton, &QPushButton::clicked, [&]() { generateRandom(); }); - connect(ui->rotationBox, &QCheckBox::clicked, [&]() { readAndDraw(); }); + connect(ui->rotationBox, &QCheckBox::stateChanged, [&]() { readAndDraw(); }); connect(ui->zoomButton, &QPushButton::clicked, [&]() { data.setZoomCoefficient(); ui->fractalWidget->repaint(); }); + connect(ui->rotationSlider, &QSlider::valueChanged, [&]() { + ui->rotationBox->setCheckState(Qt::Checked); + data.setAbsoluteSpeed(ui->rotationSlider->value() / 100.0); + }); } void MainWindow::readAndDraw() { @@ -240,7 +245,7 @@ void MainWindow::saveVideo() { return; } //int framerate = frames * 1000 / time; - QString command = QString("ffmpeg -y -pattern_type glob -i '%1/*.png' -c:v libx264 -r 60 -pix_fmt yuv420p -vf \"crop=trunc(iw/2)*2:trunc(ih/2)*2\" %2").arg(temporaryDir->path(), fileName); + QString command = QString("ffmpeg -y -pattern_type glob -i '%1/*.png' -c:v libx264 -r 60 -pix_fmt yuv420p -vf \"crop=trunc(iw/2)*2:trunc(ih/2)*2\" %2 > /dev/null").arg(temporaryDir->path(), fileName); std::system(command.toStdString().data()); } } diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index e04079d..dbe7f8e 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 1000 - 855 + 871 @@ -275,6 +275,23 @@ + + + + Rotation speed + + + + + + + 1 + + + Qt::Horizontal + + +