forked from BGTU/computer-graphics-0
105 lines
2.7 KiB
C++
105 lines
2.7 KiB
C++
#pragma once
|
|
|
|
|
|
#include <cstdlib>
|
|
#include <cmath>
|
|
#include <numbers>
|
|
#include <QObject>
|
|
#include <QMutex>
|
|
#include <QElapsedTimer>
|
|
#include <bgtu/computer_graphics_lab_work/renderer_api/point.hpp>
|
|
#include <bgtu/computer_graphics_lab_work/renderer_api/sprite.hpp>
|
|
#include <bgtu/computer_graphics_lab_work/utilities/matrix.hpp>
|
|
#include <bgtu/computer_graphics_lab_work/utilities/default_renderer_linear.hpp>
|
|
#include <bgtu/computer_graphics_lab_work/utilities/zoomed_voxel_painter.hpp>
|
|
|
|
|
|
namespace BGTU::ComputerGraphicsLabWork::Impl {
|
|
class _Lab3SpriteData_Provider;
|
|
|
|
|
|
struct SpriteData {
|
|
public:
|
|
Utilities::Matrix4d transform;
|
|
using Provider = _Lab3SpriteData_Provider;
|
|
|
|
};
|
|
|
|
class _Lab3SpriteData_Provider : public QObject, public RendererApi::Sprite<SpriteData, Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl>::SpriteDataProvider {
|
|
Q_OBJECT
|
|
private:
|
|
QMutex sync;
|
|
double x_angle;
|
|
double y_angle;
|
|
double scale;
|
|
|
|
double x_angle_step;
|
|
double y_angle_step;
|
|
double scale_step;
|
|
|
|
RendererApi::VirtualVoxelPainter::visible_pixel_coordinate_fast_t w, h;
|
|
|
|
public:
|
|
explicit _Lab3SpriteData_Provider(
|
|
double x_angle_step,
|
|
double y_angle_step,
|
|
double scale_step
|
|
) : x_angle{0}, y_angle{0}, scale{1}, x_angle_step{x_angle_step}, y_angle_step{y_angle_step}, scale_step{scale_step},
|
|
w{0}, h{0} {}
|
|
|
|
SpriteData get_sprite_data() override {
|
|
this->sync.lock();
|
|
double radius = (((this->w < this->h) ? this->w : this->h) * 7 / 16.0);
|
|
SpriteData cached{
|
|
.transform = Utilities::Matrix4d::shift(this->w / 2, this->h / 2, radius * 2) * Utilities::Matrix4d::rotate_x(this->x_angle) * Utilities::Matrix4d::rotate_y(this->y_angle) * Utilities::Matrix4d::scale(this->scale) * Utilities::Matrix4d::scale(radius)
|
|
};
|
|
this->sync.unlock();
|
|
return cached;
|
|
}
|
|
|
|
public slots:
|
|
|
|
void set_frame_size(RendererApi::VirtualVoxelPainter::visible_pixel_coordinate_fast_t ww, RendererApi::VirtualVoxelPainter::visible_pixel_coordinate_fast_t hh) {
|
|
this->sync.lock();
|
|
this->w = ww;
|
|
this->h = hh;
|
|
this->sync.unlock();
|
|
}
|
|
|
|
void inc_x_angle() {
|
|
this->sync.lock();
|
|
this->x_angle += this->x_angle_step;
|
|
this->sync.unlock();
|
|
}
|
|
|
|
void dec_x_angle() {
|
|
this->sync.lock();
|
|
this->x_angle -= this->x_angle_step;
|
|
this->sync.unlock();
|
|
}
|
|
|
|
void inc_y_angle() {
|
|
this->sync.lock();
|
|
this->y_angle += this->y_angle_step;
|
|
this->sync.unlock();
|
|
}
|
|
|
|
void dec_y_angle() {
|
|
this->sync.lock();
|
|
this->y_angle -= this->y_angle_step;
|
|
this->sync.unlock();
|
|
}
|
|
|
|
void inc_scale() {
|
|
this->sync.lock();
|
|
this->scale *= this->scale_step;
|
|
this->sync.unlock();
|
|
}
|
|
|
|
void dec_scale() {
|
|
this->sync.lock();
|
|
this->scale /= this->scale_step;
|
|
this->sync.unlock();
|
|
}
|
|
};
|
|
} |