Fixes
This commit is contained in:
parent
73132bbec5
commit
69e67e5802
@ -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_pixel_size(16);
|
||||||
sprites_data.set_sub_sprites(variant1.sprites, variant1.count);
|
sprites_data.set_sub_sprites(variant1.sprites, variant1.count);
|
||||||
|
|
||||||
|
@ -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{});
|
||||||
}
|
}
|
@ -31,7 +31,7 @@ namespace BGTU::ComputerGraphicsLabWork::QtUtilities {
|
|||||||
|
|
||||||
void receive_image(BGTU::ComputerGraphicsLabWork::QtUtilities::OwnedQImage *img) final {
|
void receive_image(BGTU::ComputerGraphicsLabWork::QtUtilities::OwnedQImage *img) final {
|
||||||
this->sync.lock();
|
this->sync.lock();
|
||||||
if (this->next_image != nullptr)
|
if (this->next_image != nullptr && this->next_image != img)
|
||||||
delete this->next_image;
|
delete this->next_image;
|
||||||
this->next_image = img;
|
this->next_image = img;
|
||||||
this->sync.unlock();
|
this->sync.unlock();
|
||||||
@ -40,15 +40,15 @@ namespace BGTU::ComputerGraphicsLabWork::QtUtilities {
|
|||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RendererWidget(_SeparateThreadedRenderer_Signals *renderer, QWidget *owner = nullptr) : _RendererWidget_SignalSlots{owner}, sync{}, next_image{}, current_image{}, renderer{renderer} {
|
explicit RendererWidget(_SeparateThreadedRenderer_Signals *renderer, QWidget *owner = nullptr) : _RendererWidget_SignalSlots{owner}, sync{}, next_image{nullptr}, current_image{nullptr}, renderer{renderer} {
|
||||||
connect(this->renderer, &_SeparateThreadedRenderer_Signals::frame_rendered, this, &_RendererWidget_SignalSlots::receive_image);
|
QObject::connect(this->renderer, &_SeparateThreadedRenderer_Signals::frame_rendered, this, &_RendererWidget_SignalSlots::receive_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) final {
|
void paintEvent(QPaintEvent *event) final {
|
||||||
this->sync.lock();
|
this->sync.lock();
|
||||||
if (this->next_image != nullptr) {
|
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;
|
delete this->current_image;
|
||||||
this->current_image = this->next_image;
|
this->current_image = this->next_image;
|
||||||
this->next_image = nullptr;
|
this->next_image = nullptr;
|
||||||
|
@ -175,10 +175,12 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
|
|||||||
auto cell = this->next_unallocated;
|
auto cell = this->next_unallocated;
|
||||||
if (cell != nullptr) {
|
if (cell != nullptr) {
|
||||||
this->next_unallocated = cell->empty.next_empty;
|
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) {
|
if (cell == nullptr) {
|
||||||
while ((cell = this->last_allocated_page->try_allocate()) == nullptr)
|
while ((cell = this->last_allocated_page->try_allocate()) == nullptr)
|
||||||
|
@ -7,7 +7,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
|
|||||||
class brezenham_line_iterable {
|
class brezenham_line_iterable {
|
||||||
private:
|
private:
|
||||||
RendererApi::PointI<2>::component_t start_arg, start_ret, end_arg;
|
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;
|
RendererApi::PointI<2>::component_t delta_error, error_threshold;
|
||||||
bool swap_flag;
|
bool swap_flag;
|
||||||
public:
|
public:
|
||||||
@ -36,6 +36,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
|
|||||||
this->delta_ret = (x2 > x1) ? 1 : -1;
|
this->delta_ret = (x2 > x1) ? 1 : -1;
|
||||||
this->swap_flag = true;
|
this->swap_flag = true;
|
||||||
}
|
}
|
||||||
|
this->delta_arg = (this->end_arg > this->start_arg) ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr brezenham_line_iterable(
|
constexpr brezenham_line_iterable(
|
||||||
@ -46,22 +47,24 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
|
|||||||
class iterator {
|
class iterator {
|
||||||
private:
|
private:
|
||||||
RendererApi::PointI<2>::component_t arg, ret, end_arg;
|
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;
|
RendererApi::PointI<2>::component_t error, delta_error, error_threshold;
|
||||||
bool swap_flag;
|
bool swap_flag;
|
||||||
|
|
||||||
constexpr iterator(
|
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 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,
|
RendererApi::PointI<2>::component_t delta_error, RendererApi::PointI<2>::component_t error_threshold,
|
||||||
bool swap_flag
|
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;
|
friend class brezenham_line_iterable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr iterator &operator++() noexcept {
|
constexpr iterator &operator++() noexcept {
|
||||||
this->arg++;
|
if (*this == nullptr)
|
||||||
|
return *this;
|
||||||
|
this->arg += this->delta_arg;
|
||||||
this->error += this->delta_error;
|
this->error += this->delta_error;
|
||||||
if (this->error >= this->error_threshold) {
|
if (this->error >= this->error_threshold) {
|
||||||
this->ret += this->delta_ret;
|
this->ret += this->delta_ret;
|
||||||
@ -84,18 +87,18 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator==(std::nullptr_t) const noexcept {
|
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 {
|
constexpr bool operator!=(std::nullptr_t) const noexcept {
|
||||||
return this->arg <= this->end_arg;
|
return !(*this == nullptr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] constexpr iterator begin() const noexcept {
|
[[nodiscard]] constexpr iterator begin() const noexcept {
|
||||||
return iterator{
|
return iterator{
|
||||||
this->start_arg, this->start_ret, this->end_arg,
|
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->delta_error, this->error_threshold,
|
||||||
this->swap_flag
|
this->swap_flag
|
||||||
};
|
};
|
||||||
|
@ -25,14 +25,14 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
|
|||||||
if (points[i - 1] == points[i])
|
if (points[i - 1] == points[i])
|
||||||
continue;
|
continue;
|
||||||
auto it = brezenham_line_iterable{points[i - 1], points[i]}.begin();
|
auto it = brezenham_line_iterable{points[i - 1], points[i]}.begin();
|
||||||
it++;
|
// it++;
|
||||||
for (; it != nullptr; it++) {
|
for (; it != nullptr; it++) {
|
||||||
receiver((*it).x, (*it).y);
|
receiver((*it).x, (*it).y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (points[0] != points[points_count - 1]) {
|
if (points[0] != points[points_count - 1]) {
|
||||||
auto it = brezenham_line_iterable{points[points_count - 1], points[0]}.begin();
|
auto it = brezenham_line_iterable{points[points_count - 1], points[0]}.begin();
|
||||||
it++;
|
// it++;
|
||||||
for (; it != nullptr; it++) {
|
for (; it != nullptr; it++) {
|
||||||
receiver((*it).x, (*it).y);
|
receiver((*it).x, (*it).y);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
|
|||||||
|
|
||||||
right--;
|
right--;
|
||||||
bottom--;
|
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;
|
RendererApi::PointI<2>::component_t x = left;
|
||||||
receiver(true, x, y);
|
receiver(true, x, y);
|
||||||
for (x++; x < right; x++) {
|
for (x++; x < right; x++) {
|
||||||
@ -116,7 +116,6 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities::Shapes {
|
|||||||
}
|
}
|
||||||
receiver(true, x, y);
|
receiver(true, x, y);
|
||||||
}
|
}
|
||||||
bottom++;
|
|
||||||
|
|
||||||
for (RendererApi::PointI<2>::component_t x = left; x <= right; x++) {
|
for (RendererApi::PointI<2>::component_t x = left; x <= right; x++) {
|
||||||
receiver(true, x, bottom);
|
receiver(true, x, bottom);
|
||||||
|
@ -48,7 +48,7 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
|
|||||||
this->pixel_size,
|
this->pixel_size,
|
||||||
this->pixel_size,
|
this->pixel_size,
|
||||||
z,
|
z,
|
||||||
c, c,
|
c, {0, 255, 255},
|
||||||
owner
|
owner
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -80,13 +80,13 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
|
|||||||
*union_ptr = left_ptr;
|
*union_ptr = left_ptr;
|
||||||
left_ptr = left_ptr->next;
|
left_ptr = left_ptr->next;
|
||||||
union_ptr = &((*union_ptr)->next);
|
union_ptr = &((*union_ptr)->next);
|
||||||
if (left_counter-- == 0)
|
if (--left_counter == 0)
|
||||||
goto RIGHT_TAIL;
|
goto RIGHT_TAIL;
|
||||||
} else {
|
} else {
|
||||||
*union_ptr = right_ptr;
|
*union_ptr = right_ptr;
|
||||||
right_ptr = right_ptr->next;
|
right_ptr = right_ptr->next;
|
||||||
union_ptr = &((*union_ptr)->next);
|
union_ptr = &((*union_ptr)->next);
|
||||||
if (right_counter-- == 0)
|
if (--right_counter == 0)
|
||||||
goto LEFT_TAIL;
|
goto LEFT_TAIL;
|
||||||
|
|
||||||
if (right_ptr == nullptr) {
|
if (right_ptr == nullptr) {
|
||||||
@ -96,12 +96,12 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
|
|||||||
}
|
}
|
||||||
if (right_counter == 0) {
|
if (right_counter == 0) {
|
||||||
LEFT_TAIL:
|
LEFT_TAIL:
|
||||||
while (right_counter-- > 1)
|
*union_ptr = left_ptr;
|
||||||
|
while (left_counter-- > 1)
|
||||||
left_ptr = left_ptr->next;
|
left_ptr = left_ptr->next;
|
||||||
left_ptr->next = right_ptr;
|
left_ptr->next = right_ptr;
|
||||||
before_left = &(left_ptr->next);
|
before_left = &(left_ptr->next);
|
||||||
}
|
} else if (left_counter == 0) {
|
||||||
if (left_counter == 0) {
|
|
||||||
RIGHT_TAIL:
|
RIGHT_TAIL:
|
||||||
*union_ptr = right_ptr;
|
*union_ptr = right_ptr;
|
||||||
while (right_counter-- > 1) {
|
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) {
|
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);
|
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) {
|
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 (x < 0 || this->_width <= x) return;
|
||||||
if (y < 0 || this->_height <= y) return;
|
if (y < 0 || this->_height <= y) return;
|
||||||
if (z < 0) return;
|
if (z < 0) return;
|
||||||
auto p = this->at(x, y);
|
auto p = this->at(x, y);
|
||||||
|
#if 0
|
||||||
|
|
||||||
if (z <= p->nearest_z) {
|
if (z <= p->nearest_z) {
|
||||||
p->nearest_z = z;
|
p->nearest_z = z;
|
||||||
#if 1
|
|
||||||
if (c.alpha == 255) {
|
if (c.alpha == 255) {
|
||||||
ZElement *e;
|
ZElement *e;
|
||||||
while (p->voxels != nullptr) {
|
while (p->voxels != nullptr) {
|
||||||
@ -154,8 +157,9 @@ namespace BGTU::ComputerGraphicsLabWork::Utilities {
|
|||||||
this->pixel_trace_elements_allocator->free_elem(e);
|
this->pixel_trace_elements_allocator->free_elem(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
p->voxels = this->pixel_trace_elements_allocator->alloc_elem(p->voxels, z, c, owner);
|
p->voxels = this->pixel_trace_elements_allocator->alloc_elem(p->voxels, z, c, owner);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user