#pragma once #include #include #include #include #include #include #include #include #include #include #include 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::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(); } }; }