Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Constantor committed May 28, 2021
2 parents 829852f + fdec8c1 commit eebcaf9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 28 deletions.
3 changes: 3 additions & 0 deletions headers/FractalData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class FractalData {
QVector3D camera = baseCamera;
qreal zoomCoefficient = defaultZoom;
qreal rotateSpeed = defaultSpeed;
qreal absoluteSpeed = defaultSpeed;
bool isRotating = false;


Expand All @@ -48,6 +49,8 @@ class FractalData {

void setZoomCoefficient(qreal zoomCoefficient = defaultZoom);

void setAbsoluteSpeed(qreal absoluteSpeed);

[[nodiscard]] QJsonObject serialize() const;

void readFrom(QJsonDocument &in);
Expand Down
6 changes: 5 additions & 1 deletion headers/FractalWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
#include "FractalData.hpp"
#include "GeometryEngine.hpp"

#include <QApplication>
#include <QElapsedTimer>
#include <QMatrix4x4>
#include <QMouseEvent>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>
#include <QOpenGLWidget>
#include <QQuaternion>
#include <QTimer>
#include <QVector2D>
#include <cmath>
#include <utility>

class FractalWidget : public QOpenGLWidget, protected QOpenGLFunctions {
Q_OBJECT
Expand Down Expand Up @@ -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;
};
4 changes: 4 additions & 0 deletions src/FractalData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
44 changes: 20 additions & 24 deletions src/FractalWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "FractalWidget.hpp"

#include <QApplication>
#include <QMouseEvent>
#include <cmath>
#include <utility>

namespace {
QVector3D transformColor(const QColor &color) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<QApplication *>(QCoreApplication::instance())->devicePixelRatio() * QVector2D(this->width(), this->height()));
Expand All @@ -179,9 +175,9 @@ void FractalWidget::setFractalData(FractalData *data) {

void FractalWidget::autoRotate() {
if(fractalData->isRotating) {
qreal nextPos = static_cast<qreal>(elapsedTimer->elapsed());
qreal dx = (nextPos - autoRotationPos) / 5;
auto nextPos = static_cast<qreal>(elapsedTimer->elapsed());
qreal dx = (nextPos - autoRotationPos) * fractalData->absoluteSpeed;
autoRotationPos = nextPos;
rotateFractal({dx, 0.0});
rotateFractal({static_cast<float>(dx), 0.0});
}
}
9 changes: 7 additions & 2 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
}
}
Expand Down
19 changes: 18 additions & 1 deletion ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1000</width>
<height>855</height>
<height>871</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -275,6 +275,23 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="rotationLabel">
<property name="text">
<string>Rotation speed</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="rotationSlider">
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame8">
<property name="frameShape">
Expand Down

0 comments on commit eebcaf9

Please sign in to comment.