This commit is contained in:
Andrew Golovashevich 2024-12-11 13:07:53 +03:00
parent 73132bbec5
commit 69e67e5802
9 changed files with 68 additions and 41 deletions

View File

@ -34,7 +34,7 @@ namespace BGTU::ComputerGraphicsLabWork::Lab1 {
});
Lab1SpriteData::Provider sprites_data{1};
Lab1SpriteData::Provider sprites_data{0.1};
sprites_data.set_pixel_size(16);
sprites_data.set_sub_sprites(variant1.sprites, variant1.count);

View File

@ -4,7 +4,7 @@
#include "../variants.hpp"
#include "../sprite_data.hpp"
namespace BGTU::ComputerGraphicsLabWork::Lab1{
namespace BGTU::ComputerGraphicsLabWork::Lab1 {
namespace Variant1 {
class S1 : public RendererApi::Sprite<Lab1SpriteData::ShapeData, Utilities::ZoomedVoxelPainter<Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl>> {
public:
@ -21,9 +21,28 @@ namespace BGTU::ComputerGraphicsLabWork::Lab1{
}
};
class S2 : public RendererApi::Sprite<Lab1SpriteData::ShapeData, Utilities::ZoomedVoxelPainter<Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl>> {
public:
void draw(
BGTU::ComputerGraphicsLabWork::Utilities::ZoomedVoxelPainter<BGTU::ComputerGraphicsLabWork::Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl> *frame,
const BGTU::ComputerGraphicsLabWork::Lab1::Lab1SpriteData::ShapeData *data
) const final {
Utilities::Shapes::draw_polygon_edge(
frame,
{
{data->radius, 0},
{0, data->radius},
{-data->radius, 0},
{0, -data->radius}
},
2,
{0, 255, 255}
);
}
};
}
variant_sprites variant1 = variant_sprites::make(Variant1::S1{});
variant_sprites variant1 = variant_sprites::make(Variant1::S1{}, Variant1::S2{});
}

View File

@ -31,7 +31,7 @@ namespace BGTU::ComputerGraphicsLabWork::QtUtilities {
void receive_image(BGTU::ComputerGraphicsLabWork::QtUtilities::OwnedQImage *img) final {
this->sync.lock();
if (this->next_image != nullptr)
if (this->next_image != nullptr && this->next_image != img)
delete this->next_image;
this->next_image = img;
this->sync.unlock();
@ -40,15 +40,15 @@ namespace BGTU::ComputerGraphicsLabWork::QtUtilities {
public:
explicit RendererWidget(_SeparateThreadedRenderer_Signals *renderer, QWidget *owner = nullptr) : _RendererWidget_SignalSlots{owner}, sync{}, next_image{}, current_image{}, renderer{renderer} {
connect(this->renderer, &_SeparateThreadedRenderer_Signals::frame_rendered, this, &_RendererWidget_SignalSlots::receive_image);
explicit RendererWidget(_SeparateThreadedRenderer_Signals *renderer, QWidget *owner = nullptr) : _RendererWidget_SignalSlots{owner}, sync{}, next_image{nullptr}, current_image{nullptr}, renderer{renderer} {
QObject::connect(this->renderer, &_SeparateThreadedRenderer_Signals::frame_rendered, this, &_RendererWidget_SignalSlots::receive_image);
}
protected:
void paintEvent(QPaintEvent *event) final {
this->sync.lock();
if (this->next_image != nullptr) {
if (this->current_image != nullptr)
if (this->current_image != nullptr && this->next_image != this->current_image)
delete this->current_image;
this->current_image = this->next_image;
this->next_image = nullptr;

View File

@ -175,10 +175,12 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
auto cell = this->next_unallocated;
if (cell != nullptr) {
this->next_unallocated = cell->empty.next_empty;
return &(cell->allocated);
return new(&(cell->allocated)) ZElement{args...};
}
for (; this->next_unfinished_page != nullptr && (cell = this->next_unfinished_page->try_allocate()) == nullptr; this->next_unfinished_page = this->next_unfinished_page->next) {}
while (this->next_unfinished_page != nullptr && (cell = this->next_unfinished_page->try_allocate()) == nullptr) {
this->next_unfinished_page = this->next_unfinished_page->next;
}
if (cell == nullptr) {
while ((cell = this->last_allocated_page->try_allocate()) == nullptr)

View File

@ -7,7 +7,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
class brezenham_line_iterable {
private:
RendererApi::PointI<2>::component_t start_arg, start_ret, end_arg;
RendererApi::PointI<2>::component_t delta_ret;
RendererApi::PointI<2>::component_t delta_ret, delta_arg;
RendererApi::PointI<2>::component_t delta_error, error_threshold;
bool swap_flag;
public:
@ -36,6 +36,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
this->delta_ret = (x2 > x1) ? 1 : -1;
this->swap_flag = true;
}
this->delta_arg = (this->end_arg > this->start_arg) ? 1 : -1;
}
constexpr brezenham_line_iterable(
@ -46,22 +47,24 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
class iterator {
private:
RendererApi::PointI<2>::component_t arg, ret, end_arg;
RendererApi::PointI<2>::component_t delta_ret;
RendererApi::PointI<2>::component_t delta_ret, delta_arg;
RendererApi::PointI<2>::component_t error, delta_error, error_threshold;
bool swap_flag;
constexpr iterator(
RendererApi::PointI<2>::component_t arg, RendererApi::PointI<2>::component_t ret, RendererApi::PointI<2>::component_t end_arg,
RendererApi::PointI<2>::component_t delta_ret,
RendererApi::PointI<2>::component_t delta_ret, RendererApi::PointI<2>::component_t delta_arg,
RendererApi::PointI<2>::component_t delta_error, RendererApi::PointI<2>::component_t error_threshold,
bool swap_flag
) noexcept: arg{arg}, ret{ret}, end_arg{end_arg}, delta_ret{delta_ret}, error{0}, delta_error{delta_error}, swap_flag{swap_flag}, error_threshold{error_threshold} {}
) noexcept: arg{arg}, ret{ret}, end_arg{end_arg}, delta_ret{delta_ret}, delta_arg{delta_arg}, error{0}, delta_error{delta_error}, swap_flag{swap_flag}, error_threshold{error_threshold} {}
friend class brezenham_line_iterable;
public:
constexpr iterator &operator++() noexcept {
this->arg++;
if (*this == nullptr)
return *this;
this->arg += this->delta_arg;
this->error += this->delta_error;
if (this->error >= this->error_threshold) {
this->ret += this->delta_ret;
@ -84,18 +87,18 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
}
constexpr bool operator==(std::nullptr_t) const noexcept {
return this->arg > this->end_arg;
return (this->arg > this->end_arg) ^ (this->delta_arg < 0);
}
constexpr bool operator!=(std::nullptr_t) const noexcept {
return this->arg <= this->end_arg;
return !(*this == nullptr);
}
};
[[nodiscard]] constexpr iterator begin() const noexcept {
return iterator{
this->start_arg, this->start_ret, this->end_arg,
this->delta_ret,
this->delta_ret, this->delta_arg,
this->delta_error, this->error_threshold,
this->swap_flag
};

View File

@ -25,14 +25,14 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
if (points[i - 1] == points[i])
continue;
auto it = brezenham_line_iterable{points[i - 1], points[i]}.begin();
it++;
// it++;
for (; it != nullptr; it++) {
receiver((*it).x, (*it).y);
}
}
if (points[0] != points[points_count - 1]) {
auto it = brezenham_line_iterable{points[points_count - 1], points[0]}.begin();
it++;
// it++;
for (; it != nullptr; it++) {
receiver((*it).x, (*it).y);
}

View File

@ -108,7 +108,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
right--;
bottom--;
for (RendererApi::PointI<2>::component_t y = top; y < bottom; y++) {
for (RendererApi::PointI<2>::component_t y = top+1; y < bottom; y++) {
RendererApi::PointI<2>::component_t x = left;
receiver(true, x, y);
for (x++; x < right; x++) {
@ -116,7 +116,6 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
}
receiver(true, x, y);
}
bottom++;
for (RendererApi::PointI<2>::component_t x = left; x <= right; x++) {
receiver(true, x, bottom);

View File

@ -48,7 +48,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
this->pixel_size,
this->pixel_size,
z,
c, c,
c, {0, 255, 255},
owner
);
}

View File

@ -80,13 +80,13 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
*union_ptr = left_ptr;
left_ptr = left_ptr->next;
union_ptr = &((*union_ptr)->next);
if (left_counter-- == 0)
if (--left_counter == 0)
goto RIGHT_TAIL;
} else {
*union_ptr = right_ptr;
right_ptr = right_ptr->next;
union_ptr = &((*union_ptr)->next);
if (right_counter-- == 0)
if (--right_counter == 0)
goto LEFT_TAIL;
if (right_ptr == nullptr) {
@ -96,12 +96,12 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
}
if (right_counter == 0) {
LEFT_TAIL:
while (right_counter-- > 1)
*union_ptr = left_ptr;
while (left_counter-- > 1)
left_ptr = left_ptr->next;
left_ptr->next = right_ptr;
before_left = &(left_ptr->next);
}
if (left_counter == 0) {
} else if (left_counter == 0) {
RIGHT_TAIL:
*union_ptr = right_ptr;
while (right_counter-- > 1) {
@ -138,14 +138,17 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
void DefaultVoxelDrawerCache::VoxelPainterImpl::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::VoxelPainterImpl::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;
auto p = this->at(x, y);
#if 0
if (z <= p->nearest_z) {
p->nearest_z = z;
#if 1
if (c.alpha == 255) {
ZElement *e;
while (p->voxels != nullptr) {
@ -154,8 +157,9 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
this->pixel_trace_elements_allocator->free_elem(e);
}
}
#endif
}
#endif
p->voxels = this->pixel_trace_elements_allocator->alloc_elem(p->voxels, z, c, owner);
}
}