mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-23 17:47:17 +01:00
Rewrote render_paint_node now it works without leaving pixels out, but it is an extermely inefficient implementation. It will be reworked soon.
This commit is contained in:
parent
5aa98e8955
commit
240bfa8ed5
@ -1,6 +1,7 @@
|
|||||||
#include "paint_node.h"
|
#include "paint_node.h"
|
||||||
|
|
||||||
#include "../paint_utilities.h"
|
#include "../paint_utilities.h"
|
||||||
|
#include "core/math/geometry.h"
|
||||||
#include "paint_project.h"
|
#include "paint_project.h"
|
||||||
|
|
||||||
Vector2i PaintNode::get_size() {
|
Vector2i PaintNode::get_size() {
|
||||||
@ -106,24 +107,60 @@ void PaintNode::render_paint_node(PaintNode *node, Transform2D transform, Ref<Im
|
|||||||
Vector2i save_image_size = save_image->get_size();
|
Vector2i save_image_size = save_image->get_size();
|
||||||
Vector2i image_size = image->get_size();
|
Vector2i image_size = image->get_size();
|
||||||
|
|
||||||
|
// NOTE: this is EXTREMELY inefficient, and slow, however it does work for now.
|
||||||
|
// It will be rewritten soon.
|
||||||
|
|
||||||
|
Vector2 p0 = transform.xform(Vector2(0, 0));
|
||||||
|
Vector2 p1 = transform.xform(Vector2(0, save_image_size.y));
|
||||||
|
Vector2 p2 = transform.xform(Vector2(save_image_size.x, 0));
|
||||||
|
Vector2 p3 = transform.xform(Vector2(save_image_size.x, save_image_size.y));
|
||||||
|
|
||||||
|
Vector<Point2i> queued_points = Geometry::brenzenham_line(p0.x, p1.x, p0.y, p1.y);
|
||||||
|
queued_points.append_array(Geometry::brenzenham_line(p1.x, p3.x, p1.y, p3.y));
|
||||||
|
queued_points.append_array(Geometry::brenzenham_line(p2.x, p3.x, p2.y, p3.y));
|
||||||
|
queued_points.append_array(Geometry::brenzenham_line(p0.x, p2.x, p0.y, p2.y));
|
||||||
|
|
||||||
|
Vector<Point2i> points_to_check;
|
||||||
|
|
||||||
|
for (int i = 0; i < queued_points.size(); ++i) {
|
||||||
|
Point2i p = queued_points[i];
|
||||||
|
|
||||||
|
Vector<Point2i> points = Geometry::brenzenham_line(p0.x, p.x, p0.y, p.y);
|
||||||
|
points.append_array(Geometry::brenzenham_line(p3.x, p.x, p3.y, p.y));
|
||||||
|
points.append_array(Geometry::brenzenham_line(p2.x, p.x, p2.y, p.y));
|
||||||
|
points.append_array(Geometry::brenzenham_line(p1.x, p.x, p1.y, p.y));
|
||||||
|
|
||||||
|
for (int j = 0; j < points.size(); ++j) {
|
||||||
|
Point2i pc = points[j];
|
||||||
|
|
||||||
|
if (points_to_check.find(pc) == -1) {
|
||||||
|
points_to_check.push_back(pc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Transform2D inverse = transform.affine_inverse();
|
||||||
|
|
||||||
save_image->lock();
|
save_image->lock();
|
||||||
image->lock();
|
image->lock();
|
||||||
|
|
||||||
//should return early eventually via a simple overlap check here
|
for (int i = 0; i < points_to_check.size(); ++i) {
|
||||||
|
Point2i p = points_to_check[i];
|
||||||
|
|
||||||
for (int x = 0; x < save_image_size.x; ++x) {
|
if (p.x < 0 || p.y < 0 || p.x >= image_size.x || p.y >= image_size.y) {
|
||||||
for (int y = 0; y < save_image_size.y; ++y) {
|
continue;
|
||||||
Vector2i npos = transform.xform(Vector2(x, y));
|
|
||||||
|
|
||||||
if (npos.x < 0 || npos.y < 0 || npos.x >= image_size.x || npos.y >= image_size.y) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color sic = save_image->get_pixel(x, y);
|
|
||||||
Color oic = image->get_pixel(npos.x, npos.y);
|
|
||||||
|
|
||||||
image->set_pixel(npos.x, npos.y, oic.blend(sic));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2 npos = inverse.xform(Vector2(p.x, p.y));
|
||||||
|
|
||||||
|
if (npos.x < 0 || npos.y < 0 || npos.x >= save_image_size.x || npos.y >= save_image_size.y) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color sic = save_image->get_pixel(npos.x, npos.y);
|
||||||
|
Color oic = image->get_pixel(p.x, p.y);
|
||||||
|
|
||||||
|
image->set_pixel(p.x, p.y, oic.blend(sic));
|
||||||
}
|
}
|
||||||
|
|
||||||
image->unlock();
|
image->unlock();
|
||||||
|
Loading…
Reference in New Issue
Block a user