feat: animation in main
This commit is contained in:
57
main.cpp
57
main.cpp
@@ -6,7 +6,9 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QTimer>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -102,26 +104,53 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int x = 0; x < 64; x++) {
|
|
||||||
for (int y = 0; y < 64; y++) {
|
|
||||||
uint32_t result[3] = {};
|
|
||||||
addTo((target.width * y * 2 + x * 2) * 3, result);
|
|
||||||
addTo((target.width * (y * 2 + 1) + x * 2) * 3, result);
|
|
||||||
addTo((target.width * y * 2 + (x * 2 + 1)) * 3, result);
|
|
||||||
addTo((target.width * (y * 2 + 1) + (x * 2 + 1)) * 3, result);
|
|
||||||
for (int c = 0; c < 3; c++) {
|
|
||||||
pixel[(WIDTH * (WIDTH - y - 1) + WIDTH - x - 1) * 3 + c] =
|
|
||||||
result[c] >> 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
QWidget widget;
|
QWidget widget;
|
||||||
widget.setAutoFillBackground(true);
|
widget.setAutoFillBackground(true);
|
||||||
widget.setGeometry(0, 0, 500, 500);
|
widget.setGeometry(0, 0, 500, 500);
|
||||||
QLabel display(&widget);
|
QLabel display(&widget);
|
||||||
QImage img((unsigned char *)pixel, 64, 64, QImage::Format_RGB888);
|
QImage img((unsigned char *)pixel, 64, 64, QImage::Format_RGB888);
|
||||||
display.setPixmap(QPixmap::fromImage(img).scaled(widget.size()));
|
|
||||||
|
// display.setPixmap(QPixmap::fromImage(img).scaled(widget.size()));
|
||||||
|
|
||||||
|
float rot = 0.f;
|
||||||
|
std::function<void()> renderLoop = [&addTo, &target, &pixel, &renderer,
|
||||||
|
&display, &widget, &img, &rot]() {
|
||||||
|
std::chrono::steady_clock::time_point begin =
|
||||||
|
std::chrono::steady_clock::now();
|
||||||
|
renderer.render(&testModel, mat4::translation(vec3(0.0f, -1.0f, 5.0f)) *
|
||||||
|
mat4::rotateOnY(rot));
|
||||||
|
std::chrono::steady_clock::time_point end =
|
||||||
|
std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
std::cout << "Time difference = "
|
||||||
|
<< std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
end - begin)
|
||||||
|
.count()
|
||||||
|
<< "[ms]" << std::endl;
|
||||||
|
|
||||||
|
for (int x = 0; x < 64; x++) {
|
||||||
|
for (int y = 0; y < 64; y++) {
|
||||||
|
uint32_t result[3] = {};
|
||||||
|
addTo((target.width * y * 2 + x * 2) * 3, result);
|
||||||
|
addTo((target.width * (y * 2 + 1) + x * 2) * 3, result);
|
||||||
|
addTo((target.width * y * 2 + (x * 2 + 1)) * 3, result);
|
||||||
|
addTo((target.width * (y * 2 + 1) + (x * 2 + 1)) * 3, result);
|
||||||
|
for (int c = 0; c < 3; c++) {
|
||||||
|
pixel[(WIDTH * (WIDTH - y - 1) + WIDTH - x - 1) * 3 + c] =
|
||||||
|
result[c] >> 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// QImage img((unsigned char *)pixel, 64, 64, QImage::Format_RGB888);
|
||||||
|
display.setPixmap(QPixmap::fromImage(img).scaled(widget.size() * 1));
|
||||||
|
rot += 0.1f;
|
||||||
|
};
|
||||||
|
renderLoop();
|
||||||
widget.show();
|
widget.show();
|
||||||
|
QTimer timer;
|
||||||
|
timer.setInterval(20);
|
||||||
|
timer.start();
|
||||||
|
QObject::connect(&timer, &QTimer::timeout, &widget, renderLoop);
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user