Extending VoxelDrawer api to support wrapper sprites
This commit is contained in:
parent
e4442e595a
commit
b171ea84c2
@ -29,8 +29,8 @@ namespace BGTU::ComputerGraphicsLabWork::Lab1 {
|
||||
for (long long x = start_x; x < w; x += data->pixel_size, x_flag = !x_flag) {
|
||||
auto c = x_flag ? this->bg : this->fg;
|
||||
|
||||
for (long long yy = y + data->pixel_size - 1; yy-- > y;) {
|
||||
for (long long xx = x + data->pixel_size - 1; xx-- > x;) {
|
||||
for (long long yy = y + data->pixel_size; yy-- > y;) {
|
||||
for (long long xx = x + data->pixel_size; xx-- > x;) {
|
||||
frame->add_voxel(xx, yy, std::numeric_limits<double>::max(), c);
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,11 @@
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <numbers>
|
||||
#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>
|
||||
|
||||
@ -14,9 +17,16 @@ namespace BGTU::ComputerGraphicsLabWork::Lab1 {
|
||||
|
||||
struct Lab1SpriteData {
|
||||
public:
|
||||
Utilities::Matrix3d transform;
|
||||
struct ShapeData {
|
||||
double rotation_radians;
|
||||
};
|
||||
|
||||
RendererApi::PointI<2> central_pixel_tl;
|
||||
std::size_t pixel_size;
|
||||
bool show_grid;
|
||||
ShapeData shape_data;
|
||||
RendererApi::Sprite<ShapeData> **sub_sprites;
|
||||
std::size_t sub_sprites_count;
|
||||
|
||||
using Provider = _Lab1SpriteData_Provider;
|
||||
};
|
||||
@ -31,17 +41,23 @@ namespace BGTU::ComputerGraphicsLabWork::Lab1 {
|
||||
double radians_per_second;
|
||||
RendererApi::VoxelDrawer::visible_pixel_coordinate_fast_t w, h;
|
||||
bool show_grid;
|
||||
RendererApi::Sprite<Lab1SpriteData::ShapeData> **sub_sprites;
|
||||
std::size_t sub_sprites_count;
|
||||
|
||||
public:
|
||||
explicit _Lab1SpriteData_Provider(double radians_per_second) : sync{}, time{}, pixel_size{1}, radians_per_second{radians_per_second}, show_grid{false} {}
|
||||
|
||||
Lab1SpriteData get_sprite_data() override {
|
||||
this->sync.lock();
|
||||
Lab1SpriteData cached{
|
||||
.transform = Utilities::Matrix3d::shift(this->pixel_size / -2.0, this->pixel_size / 2.0) *
|
||||
Utilities::Matrix3d::shift(this->w / 2.0, this->h / 2.0) *
|
||||
Utilities::Matrix3d::rotate(this->time.elapsed() / 1000.0 * this->radians_per_second),
|
||||
.central_pixel_tl = static_cast<RendererApi::PointI<2>>(RendererApi::PointF<2>(this->w, this->h) / 2.0 - RendererApi::PointF<2>(this->pixel_size, this->pixel_size) / 2.0),
|
||||
.pixel_size = this->pixel_size,
|
||||
.show_grid = this->show_grid
|
||||
.show_grid = this->show_grid,
|
||||
.shape_data = {
|
||||
.rotation_radians = std::fmod(this->time.elapsed() / 1000.0 * radians_per_second, std::numbers::pi)
|
||||
},
|
||||
.sub_sprites = nullptr,
|
||||
.sub_sprites_count = 0
|
||||
};
|
||||
this->sync.unlock();
|
||||
return cached;
|
||||
|
@ -86,7 +86,7 @@ namespace BGTU::ComputerGraphicsLabWork::QtUtilities {
|
||||
return this->owners[y * this->width() + x];
|
||||
}
|
||||
|
||||
void set_pixel(RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, RendererApi::Color c, RendererApi::SpriteMetadata const *owner) final {
|
||||
void set_pixel(RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, RendererApi::Color c, RendererApi::SpriteMetadata *owner) final {
|
||||
this->setPixelColor(x, y, QColor{c.red, c.green, c.blue});
|
||||
this->setPixelOwner(x, y, owner);
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ namespace BGTU::ComputerGraphicsLabWork::QtUtilities {
|
||||
pixels_argb{new std::uint_least8_t[w * h * 4]},
|
||||
owners{new RendererApi::SpriteMetadata const *[w * h]} {}
|
||||
|
||||
void set_pixel(long long x, long long y, BGTU::ComputerGraphicsLabWork::RendererApi::Color c, const BGTU::ComputerGraphicsLabWork::RendererApi::SpriteMetadata *owner) final {
|
||||
void set_pixel(long long x, long long y, BGTU::ComputerGraphicsLabWork::RendererApi::Color c, BGTU::ComputerGraphicsLabWork::RendererApi::SpriteMetadata *owner) final {
|
||||
if (x < 0 || this->w <= x) return;
|
||||
if (y < 0 || this->h <= y) return;
|
||||
this->pixels_argb[(y * this->w + x) * 4] = c.red;
|
||||
@ -220,6 +220,6 @@ namespace BGTU::ComputerGraphicsLabWork::QtUtilities {
|
||||
private:
|
||||
Utilities::DefaultVoxelDrawerCache context;
|
||||
public:
|
||||
explicit SeparateThreadedDefaultRendererLinear(QObject *owner = nullptr) : SeparateThreadedRenderer<sprite_data_t, Utilities::DefaultVoxelDrawerCache, &Utilities::DefaultVoxelDrawerCache::render<sprite_data_t>>{&this->context, owner} {};
|
||||
explicit SeparateThreadedDefaultRendererLinear(QObject *owner = nullptr) : SeparateThreadedRenderer<sprite_data_t, Utilities::DefaultVoxelDrawerCache, &Utilities::DefaultVoxelDrawerCache::render<sprite_data_t>>{&this->context, owner}, context{} {};
|
||||
};
|
||||
}
|
@ -22,6 +22,22 @@ namespace BGTU::ComputerGraphicsLabWork::RendererApi {
|
||||
explicit operator Point<2, new_component_t>() const {
|
||||
return Point<2, new_component_t>{converter(this->x), converter(this->y)};
|
||||
}
|
||||
|
||||
Point<2, _component_t> operator+(Point<2, _component_t> const &other) const {
|
||||
return Point<2, _component_t>{this->x + other.x, this->y + other.y};
|
||||
}
|
||||
|
||||
Point<2, _component_t> operator-(Point<2, _component_t> const &other) const {
|
||||
return Point<2, _component_t>{this->x - other.x, this->y - other.y};
|
||||
}
|
||||
|
||||
Point<2, _component_t> operator*(_component_t const &other) const {
|
||||
return Point<2, _component_t>{this->x * other, this->y * other};
|
||||
}
|
||||
|
||||
Point<2, _component_t> operator/(_component_t const &other) const {
|
||||
return Point<2, _component_t>{this->x / other, this->y / other};
|
||||
}
|
||||
};
|
||||
|
||||
template<class _component_t>
|
||||
@ -40,6 +56,23 @@ namespace BGTU::ComputerGraphicsLabWork::RendererApi {
|
||||
explicit operator Point<3, new_component_t>() const {
|
||||
return Point<3, new_component_t>{new_component_t{this->x}, new_component_t{this->y}, new_component_t{this->z}};
|
||||
}
|
||||
|
||||
|
||||
Point<3, _component_t> operator+(Point<2, _component_t> const &other) const {
|
||||
return Point<3, _component_t>{this->x + other.x, this->y + other.y, this->z + other.z};
|
||||
}
|
||||
|
||||
Point<3, _component_t> operator-(Point<2, _component_t> const &other) const {
|
||||
return Point<3, _component_t>{this->x - other.x, this->y - other.y, this->z - other.z};
|
||||
}
|
||||
|
||||
Point<3, _component_t> operator*(_component_t const &other) const {
|
||||
return Point<3, _component_t>{this->x * other, this->y * other, this->z * other};
|
||||
}
|
||||
|
||||
Point<3, _component_t> operator/(_component_t const &other) const {
|
||||
return Point<3, _component_t>{this->x / other, this->y / other, this->z / other};
|
||||
}
|
||||
};
|
||||
|
||||
template<unsigned DIMENSIONS>
|
||||
|
@ -26,13 +26,19 @@ namespace BGTU::ComputerGraphicsLabWork::RendererApi {
|
||||
|
||||
virtual void add_voxel(PointI<2>::component_t x, PointI<2>::component_t y, double z, Color::Transparent c) = 0;
|
||||
|
||||
virtual void add_voxel(PointI<2>::component_t x, PointI<2>::component_t y, double z, Color::Transparent c, SpriteMetadata *owner) = 0;
|
||||
|
||||
inline void add_voxel(PointI<2> p, double z, Color::Transparent c) {
|
||||
return this->add_voxel(p.x, p.y, z, c);
|
||||
}
|
||||
|
||||
inline void add_voxel(PointI<2> p, double z, Color::Transparent c, SpriteMetadata *owner) {
|
||||
return this->add_voxel(p.x, p.y, z, c, owner);
|
||||
}
|
||||
|
||||
class Exporter {
|
||||
public:
|
||||
virtual void set_pixel(PointI<2>::component_t x, PointI<2>::component_t y, Color c, SpriteMetadata const* owner) = 0;
|
||||
virtual void set_pixel(PointI<2>::component_t x, PointI<2>::component_t y, Color c, SpriteMetadata *owner) = 0;
|
||||
};
|
||||
};
|
||||
}
|
@ -131,6 +131,8 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
|
||||
}
|
||||
|
||||
void add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c) final;
|
||||
|
||||
void add_voxel(long long x, long long y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner) final;
|
||||
};
|
||||
|
||||
|
||||
|
@ -136,6 +136,9 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
|
||||
|
||||
|
||||
void DefaultVoxelDrawerCache::VoxelDrawerImpl::add_voxel(RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, double z, RendererApi::Color::Transparent c) {
|
||||
return this->add_voxel(x, y, z, c, this->current_artist);
|
||||
}
|
||||
void DefaultVoxelDrawerCache::VoxelDrawerImpl::add_voxel(RendererApi::PointI<2>::component_t x, RendererApi::PointI<2>::component_t y, double z, RendererApi::Color::Transparent c, RendererApi::SpriteMetadata *owner) {
|
||||
if (x < 0 || this->_width <= x) return;
|
||||
if (y < 0 || this->_height <= y) return;
|
||||
if (z < 0) return;
|
||||
@ -153,6 +156,6 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
p->voxels = this->pixel_trace_elements_allocator->alloc_elem(p->voxels, z, c, this->current_artist);
|
||||
p->voxels = this->pixel_trace_elements_allocator->alloc_elem(p->voxels, z, c, owner);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user