From c8b3d756967748cf90335cc299529c80b6fe4858 Mon Sep 17 00:00:00 2001 From: Dawid Pietrykowski Date: Tue, 13 Jun 2023 22:55:29 +0200 Subject: [PATCH] Finished 3d-culling --- QT/3d-cube-culling/3d-cube-culling.pro | 20 + QT/3d-cube-culling/main.cpp | 33 ++ QT/3d-cube-culling/mywindow.cpp | 480 +++++++++++++++++++++ QT/3d-cube-culling/mywindow.h | 241 +++++++++++ QT/3d-cube-culling/mywindow.ui | 552 +++++++++++++++++++++++++ 5 files changed, 1326 insertions(+) create mode 100644 QT/3d-cube-culling/3d-cube-culling.pro create mode 100644 QT/3d-cube-culling/main.cpp create mode 100644 QT/3d-cube-culling/mywindow.cpp create mode 100644 QT/3d-cube-culling/mywindow.h create mode 100644 QT/3d-cube-culling/mywindow.ui diff --git a/QT/3d-cube-culling/3d-cube-culling.pro b/QT/3d-cube-culling/3d-cube-culling.pro new file mode 100644 index 0000000..abf8dd6 --- /dev/null +++ b/QT/3d-cube-culling/3d-cube-culling.pro @@ -0,0 +1,20 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2015-03-03T00:14:51 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = 3d-cube-culling +TEMPLATE = app + +OUTPUT += Console +SOURCES += main.cpp\ + mywindow.cpp + +HEADERS += mywindow.h + +FORMS += mywindow.ui diff --git a/QT/3d-cube-culling/main.cpp b/QT/3d-cube-culling/main.cpp new file mode 100644 index 0000000..2a67e1f --- /dev/null +++ b/QT/3d-cube-culling/main.cpp @@ -0,0 +1,33 @@ +// Glowny plik aplikacji, utworzony automatycznie przez QtCreator +// W wiekszosci przypadkow nie musimy tu nic zmieniac + +// Dolaczamy plik naglowkowy klasy QApplication +#include + +// Dolaczamy plik naglowkowy klasy glownego widgetu (okna) aplikacji +#include "mywindow.h" + +int main(int argc, char *argv[]) +{ + + // Tworzymy objekt QApplication. Zarzadza on zasobami calej aplikacji + // i jest niezbedny do stworzenia jakiejkolwiek aplikacji Qt posiadajacej GUI. + // Przekazujemy mu dwa argumenty argc i argv, poniewaz Qt moze rowniez + // przyjmowac argumenty z linii komend. + QApplication a(argc, argv); + + // Tworzymy obiekt klasy MyWindow - glownego okna naszej aplikacji. + // Jest to klasa zdefiniowana przez nas. + // Jej definicja znajduje sie w plikach mainwindow.h i mainwindow.cpp + MyWindow w; + +// w.setMouseTracking(true); + // Pokazujemy glowne okno aplikacji na ekranie. Domyslnie jest ono niewidoczne. + // Wszystkie widgety (elementy GUI) zawarte w glownym oknie beda rowniez widoczne. + w.show(); + + // Przekazujemy kontrole nad aplikacja do Qt. Program wchodzi w petle zdarzen + // tzn. zaczyna oczekiwac na akcje uzytkownika - klikniecia przycisku myszy, + // lub klawisza klawiatury itp. + return a.exec(); +} diff --git a/QT/3d-cube-culling/mywindow.cpp b/QT/3d-cube-culling/mywindow.cpp new file mode 100644 index 0000000..8a66ee7 --- /dev/null +++ b/QT/3d-cube-culling/mywindow.cpp @@ -0,0 +1,480 @@ +// Dolaczamy plik naglowkowy naszej klasy MyWindow +#include "mywindow.h" + +// Dolaczamy plik naglowkowy zawierajacy definicje GUI +// Plik ten jest generowany automatycznie +// z pliku XML "mywindow.ui" +#include "ui_mywindow.h" + +#include +#include +#include +#include +#include +#include // for float,double macros +#include +#include +#include + +#define PI 3.1415 + +const int VIEW_SIZE = 4.0f; + +const float CAMERA_Z = -5; + +std::vector matrixMul(std::vector p, std::vector m) +{ + std::vector res(4); + for(int i = 0; i < 4; i++) + { + res.push_back(0); + for(int j = 0; j < 4; j++) + { + res[i] += m[i * 4 + j] * p[j]; + } + } + return res; +} + + +std::vector MyWindow::GetXY(Point p) +{ + std::vector res(3); + + float d = -CAMERA_Z; + + float x = (p.x * d) / (p.z + d); + float y = (p.y * d) / (p.z + d); + float z = 0; + + x = ((x + VIEW_SIZE / 2.0f) / VIEW_SIZE * szer ); + y = ((y + VIEW_SIZE / 2.0f) / VIEW_SIZE * wys); + + return std::vector{x, y, z}; +} + +std::vector matrixMul3x3(std::vector m1, std::vector m2) +{ + std::vector res(9, 0); + for(int i = 0; i < 3; i++) + { + for(int j = 0; j < 3; j++) + { + for(int k = 0; k < 3; k++) + { + res[i * 3 + j] += m1[i * 3 + k] * m2[k * 3 + j]; + } + } + } + return res; +} + +std::vector matrixMul4x4(std::vector m1, std::vector m2) +{ + std::vector res(16, 0); + for(int i = 0; i < 4; i++) + { + for(int j = 0; j < 4; j++) + { + for(int k = 0; k < 4; k++) + { + res[i * 4 + j] += m1[i * 4 + k] * m2[k * 4 + j]; + } + } + } + return res; +} +// Definicja konstruktora, wywolujemy najpierw +// konstruktor klasy nadrzednej, nastepnie tworzymy +// obiekt klasy Ui_MyWindow reprezentujacy GUI +MyWindow::MyWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MyWindow) +{ + // Wywolujemy funkcje tworzaca elementy GUI + // Jej definicja znajduje sie w pliku "ui_mywindow.h" + ui->setupUi(this); + + // Pobieramy wymiary i wspolrzedne lewego gornego naroznika ramki + // i ustawiamy wartosci odpowiednich pol + // Uwaga: ramke "rysujFrame" wykorzystujemy tylko do + // wygodnego ustaiwenia tych wymiarow. Rysunek bedziemy wyswietlac + // bezposrednio w glownym oknie aplikacji. + szer = ui->rysujFrame->width(); + wys = ui->rysujFrame->height(); + poczX = ui->rysujFrame->x(); + poczY = ui->rysujFrame->y(); + + // Tworzymy obiekt klasy QImage, o odpowiedniej szerokosci + // i wysokosci. Ustawiamy format bitmapy na 32 bitowe RGB + // (0xffRRGGBB). + img = new QImage(szer,wys,QImage::Format_RGB32); + + loaded_img = new QImage("/Users/dawidpietrykowski/Desktop/projects/umk/GK/QT/2d-transformations/p.png"); + + rotation_angle = 0; + + translation_vec.push_back(0); + translation_vec.push_back(0); + translation_vec.push_back(0); + + rotation_vec.push_back(0); + rotation_vec.push_back(0); + rotation_vec.push_back(0); + +// points[0] = Point(-1.0f, -1.0f, 0.0f); +// points[1] = Point(1.0f, -1.0f, 0.0f); +// points[2] = Point(1.0f, 1.0f, 0.0f); +// points[3] = Point(-1.0f, 1.0f, 0.0f); + +// points[4] = Point(-1.0f, -1.0f, 0.0f); +// points[5] = Point(1.0f, -1.0f, 0.0f); +// points[6] = Point(1.0f, 1.0f, 0.0f); +// points[7] = Point(-1.0f, 1.0f, 0.0f); + + + scale_vec.push_back(1.0f); + scale_vec.push_back(1.0f); + scale_vec.push_back(1.0f); + + sh_vec.push_back(0.0f); + sh_vec.push_back(0.0f); + + UpdateImage(); +} + +// Definicja destruktora +MyWindow::~MyWindow() +{ + delete ui; +} + +// Funkcja (slot) wywolywana po nacisnieciu przycisku "Wyjscie" (exitButton) +// Uwaga: polaczenie tej funkcji z sygnalem "clicked" +// emitowanym przez przycisk jest realizowane +// za pomoca funkcji QMetaObject::connectSlotsByName(MyWindow) +// znajdujacej sie w automatycznie generowanym pliku "ui_mywindow.h" +// Nie musimy wiec sami wywolywac funkcji "connect" +void MyWindow::on_exitButton_clicked() +{ + // qApp to globalny wskaznik do obiektu reprezentujacego aplikacje + // quit() to funkcja (slot) powodujaca zakonczenie aplikacji z kodem 0 (brak bledu) + qApp->quit(); +} + +void MyWindow::on_slider_tx_valueChanged(int val){ + translation_vec[0] = 4.0f * (val / 100.0f - 1.0f); +} + +void MyWindow::on_slider_ty_valueChanged(int val){ + translation_vec[1] = 4.0f * (val / 100.0f - 1.0f); +} + +void MyWindow::on_slider_tz_valueChanged(int val){ + translation_vec[2] = 4.0f * (val / 100.0f - 1.0f); +} + +void MyWindow::on_slider_rx_valueChanged(int val){ + rotation_vec[0] = val; +} + +void MyWindow::on_slider_ry_valueChanged(int val){ + rotation_vec[1] = val; +} + +void MyWindow::on_slider_rz_valueChanged(int val){ + rotation_vec[2] = val; +} + +void MyWindow::on_slider_sx_valueChanged(int val){ + scale_vec[0] = 1.0f + (4.0f * (( val / 100.0f ) - 1.0f)); +} + +void MyWindow::on_slider_sy_valueChanged(int val){ + scale_vec[1] = 1.0f + (4.0f * (( val / 100.0f ) - 1.0f)); +} + +void MyWindow::on_slider_sz_valueChanged(int val){ + scale_vec[2] = 1.0f + (4.0f * (( val / 100.0f ) - 1.0f)); +} + +void MyWindow::on_slider_shx_valueChanged(int val){ + sh_vec[0] = val / 100.0f - 1.0f; +} + +void MyWindow::on_slider_shy_valueChanged(int val){ + sh_vec[1] = val / 100.0f - 1.0f; +} + +void MyWindow::on_slider_n_valueChanged(int val){ + draw_normals = val; +} + +Point cross(Point A, Point B){ + float mi = (A.y * B.z) - (A.z * B.y); + float mj = (A.z * B.x) - (A.x * B.z); + float mk = (A.x * B.y) - (A.y * B.x); + return Point(mi, mj, mk); +} + +float dot(Point A, Point B){ + return A.x * B.x + A.y * B.y + A.z * B.z; +} + +void MyWindow::UpdateImage(){ + float sina; + float cosa; + + std::vector translate_mat = { + 1, 0, 0, translation_vec[0], + 0, 1, 0, translation_vec[1], + 0, 0, 1, translation_vec[2], + 0, 0, 0, 1, + }; + + std::vector scale_mat = { + scale_vec[0], 0, 0, 0, + 0, scale_vec[1], 0, 0, + 0, 0, scale_vec[2], 0, + 0, 0, 0, 1, + }; + + sina = sin(rotation_vec[0] * 0.01745329252f); + cosa = cos(rotation_vec[0] * 0.01745329252f); + std::vector rotation_mat_x = { + 1, 0, 0, 0, + 0, cosa, -sina, 0, + 0, sina, cosa, 0, + 0, 0, 0, 1 + }; + + sina = sin(rotation_vec[1] * 0.01745329252f); + cosa = cos(rotation_vec[1] * 0.01745329252f); + std::vector rotation_mat_y = { + cosa, 0, sina, 0, + 0, 1, 0, 0, + -sina, 0, cosa, 0, + 0, 0, 0, 1 + }; + + sina = sin(rotation_vec[2] * 0.01745329252f); + cosa = cos(rotation_vec[2] * 0.01745329252f); + std::vector rotation_mat_z = { + cosa, -sina, 0, 0, + sina, cosa, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + + std::vector sh_mat = { + 1, 0, sh_vec[0], 0, + 0, 1, sh_vec[1], 0, + 0, 0, 1, 0, + 0, 0, 0, 1, + }; + + std::vector tansform_mat = + matrixMul4x4( + matrixMul4x4( + matrixMul4x4( + matrixMul4x4( + matrixMul4x4( + scale_mat, + translate_mat), + rotation_mat_x), + rotation_mat_y), + rotation_mat_z), + sh_mat); + + ClearImage(img); + + int tris = (sizeof(indices)/sizeof(*indices)) / 3; + + + for(int i = 0; i < tris; i++){ + Point P1 = vertices[indices[3*i]]; + Point P2 = vertices[indices[3*i + 1]]; + Point P3 = vertices[indices[3*i + 2]]; + + Point P1M = Point(matrixMul(P1.GetVector(), tansform_mat)); + Point P2M = Point(matrixMul(P2.GetVector(), tansform_mat)); + Point P3M = Point(matrixMul(P3.GetVector(), tansform_mat)); + + std::vector p1_vec = GetXY(P1M); + std::vector p2_vec = GetXY(P2M); + std::vector p3_vec = GetXY(P3M); + + Point A = P2M - P3M; + Point B = P2M - P1M; + + Point normal = cross(A, B).Normalize(); + + + Point camera_origin = Point(0, 0, CAMERA_Z); + + Point tris_center = (P1M + P2M + P3M) * 0.3333f; + Point normal_dest = tris_center + normal * 0.3f; + + Point camera_to_tris = (tris_center - camera_origin).Normalize(); + + float dot_p = dot(camera_to_tris, normal); + + if(dot_p < 0){ + std::vector no_vec = GetXY(tris_center); + std::vector nd_vec = GetXY(normal_dest); + if(draw_normals) + DrawLine(no_vec[0], no_vec[1], nd_vec[0], nd_vec[1], img, QColor(255, 255, 255, 255)); + + + DrawLine(p1_vec[0], p1_vec[1], p2_vec[0], p2_vec[1], img, QColor(255, 0, 80, 255)); + DrawLine(p2_vec[0], p2_vec[1], p3_vec[0], p3_vec[1], img, QColor(255, 0, 80, 255)); + DrawLine(p3_vec[0], p3_vec[1], p1_vec[0], p1_vec[1], img, QColor(255, 0, 80, 255)); + } + + } + + update(); +} + + + +QColor MyWindow::GetPixel(QImage* img, int x, int y){ + QColor res; + int width = img->width(); + int height = img->height(); + if(x >= width || y >= height || x < 0 || y < 0) + return res; + + unsigned char* ptr = img->bits(); + + res.setBlue(ptr[width*4*y + 4*x]); + res.setGreen(ptr[width*4*y + 4*x + 1]); + res.setRed(ptr[width*4*y + 4*x + 2]); + res.setAlpha(ptr[width*4*y + 4*x + 3]); + + return res; +} + +QColor mul(float v, QColor c){ + int red = (int)(c.red() * v); + if(red > 255) red = 255; + int green = (int)(c.green() * v); + if(green > 255) green = 255; + int blue = (int)(c.blue() * v); + if(blue > 255) blue = 255; + return QColor(red, green, blue); +} + +QColor add(QColor c1, QColor c2){ + int red = (int)(c1.red() + c2.red()); + if(red > 255) red = 255; + int green = (int)(c1.green() + c2.green()); + if(green > 255) green = 255; + int blue = (int)(c1.blue() + c2.blue()); + if(blue > 255) blue = 255; + return QColor(red, green, blue); +} + +QColor MyWindow::GetInterpolatedColor(float x, float y){ + float width = loaded_img->width(); + float height = loaded_img->height(); + float xw = (x * width); + float yw = (y * height); + int x_f = (int) (x * width); + int y_f = (int) (y * height); + int x_c = ceil(x * width); + int y_c = ceil(y * height); + float a = (xw - (float) x_f); + float b = ((yw) - (float) y_f); + + QColor P1 = GetPixel(loaded_img, x_f, y_c); + QColor P2 = GetPixel(loaded_img, x_c, y_c); + QColor P3 = GetPixel(loaded_img, x_c, y_f); + QColor P4 = GetPixel(loaded_img, x_f, y_f); + + QColor v1 = mul(1.0f - a, P1); + QColor v2 = mul(a, P2); + QColor v3 = mul(a, P3); + QColor v4 = mul(1.0f - a, P4); + QColor top = add(v1, v2); + QColor bottom = add(v3, v4); + QColor btop = mul(b, top); + QColor bbottom = mul(1.0f - b, bottom); + QColor res = add(btop, bbottom); + + return res; +} + +// Funkcja "odmalowujaca" komponent +void MyWindow::paintEvent(QPaintEvent*) +{ + // Obiekt klasy QPainter pozwala nam rysowac na komponentach + QPainter p(this); + + + UpdateImage(); + // Rysuje obrazek "img" w punkcie (poczX,poczY) + // (tu bedzie lewy gorny naroznik) + p.drawImage(poczX,poczY,*img); +} + +void MyWindow::DrawLine(int x1, int y1, int x2, int y2, QImage *img, QColor color){ + if(x1 > x2){ + std::swap(x1, x2); + std::swap(y1, y2); + } + float diff = x2 - x1; + float a = diff != 0 ? (y2 - y1) / diff : FLT_MAX; + + + if(abs(a) < 1.0f){ + for(int x = x1; x <= x2; x++){ + int x_form = x - x1; + int y = a * x_form + y1; + + DrawPixel(img, x, y, color); + } + } + else{ + if(y1 > y2){ + std::swap(x1, x2); + std::swap(y1, y2); + } + float diff = x2 - x1; + float a = diff != 0 ? (y2 - y1) / diff : FLT_MAX; + for(int y = y1; y <= y2; y++){ + int y_form = y - y1; + int x = ((float)(y_form) / a) + x1; + + DrawPixel(img, x, y, color); + } + } +} + + +void MyWindow::DrawPixel(QImage* img, int x, int y, QColor color){ + if(x >= szer || y >= wys || x < 0 || y < 0) + return; + + unsigned char* ptr = img->bits(); + + ptr[szer*4*y + 4*x] = color.blue(); + ptr[szer*4*y + 4*x + 1] = color.green(); + ptr[szer*4*y + 4*x + 2] = color.red(); + ptr[szer*4*y + 4*x + 3] = color.alpha(); +} + + +void MyWindow::ClearImage(QImage *img){ + unsigned char* empty_val = (unsigned char*)malloc(4); + empty_val[0] = 15; + empty_val[1] = 15; + empty_val[2] = 15; + empty_val[3] = 255; + unsigned char* ptr = img->bits(); + for(int i = 0; i < img->width(); i++){ + for(int j = 0; j < img->height(); j++){ + memcpy(ptr + 4 * (i + j * img->width()), empty_val, 4); + } + } +} diff --git a/QT/3d-cube-culling/mywindow.h b/QT/3d-cube-culling/mywindow.h new file mode 100644 index 0000000..cc40c88 --- /dev/null +++ b/QT/3d-cube-culling/mywindow.h @@ -0,0 +1,241 @@ +// Plik naglowkowy klasy MyWindow +// Obiekt tej klasy to glowne okno naszej aplikacji +// Szkielet tego pliku jest tworzony przez QtCreator +// Mozemy do niego dodac deklaracje wlasnych pol i metod + +#ifndef MYWINDOW_H +#define MYWINDOW_H + +// Dolaczamy plik naglowkowy klasy QMainWindow, +// Klasa QMainWindow posiada swoj wlasny layout. +// latwo mozna do niej dodac pasek menu, widzety dokujace, +// pasek narzedzi i pasek statusu. Na srodku okna +// wyswietlanego przez QMainWindow znajduje sie obszar, +// ktory mozna wypelnic roznymi widgetami. +#include + +// QPainter to klasa umozliwiajaca niskopoziomowe rysowanie +// na elementach GUI +#include + +// QImage to klasa pozwalajaca na niezalezna od sprzetu reprezentacje obrazu. +// Pozwala na bezposredni dostep do poszczegolnych pikseli, +// Bedziemy jej uzywali do tworzenia i przechowywania +// naszych rysunkow +#include + +// QMouseEvent to klasa obslugujaca zdarzenia zwiazane z myszka +// klikniecia, ruch myszka itp. +#include + +#include +#include // for float,double macros + +struct Point{ + float x, y, z; + + Point(float x, float y, float z){ + this->x=x; + this->y=y; + this->z=z; + } + + Point(std::vector vec){ + this->x=vec[0]; + this->y=vec[1]; + this->z=vec[2]; + } + + std::vector GetVector(){ + return std::vector{x, y, z, 1}; + } + + float length(){ + float mag = std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2)); + return mag; + } + + Point Normalize(){ + return *this * (1.0f / this->length()); + } + + + Point operator-(const Point& other){ + return Point(this->x - other.x, this->y - other.y, this->z - other.z); + } + + Point operator*(const float mul){ + return Point(this->x * mul, this->y * mul, this->z * mul); + } + + Point operator+(const Point& other){ + return Point(this->x + other.x, this->y + other.y, this->z + other.z); + } +}; + +enum Mode {Line, Circle, Fill}; + +namespace Ui { + class MyWindow; +} + + +// MyWindow jest podklasa klasy QMainWindow. +class MyWindow : public QMainWindow +{ + // Q_OBJECT jest to makro, ktore musi sie znajdowac + // we wszystkich klasach definiujacych wlasne sygnaly i sloty + // W naszej klasie nie jest ono potrzebne, + // ale QtCreator dodaje je automatycznie do kazdej klasy. + Q_OBJECT + +public: + // Typowa deklaracja konstruktora w Qt. + // Parametr "parent" okresla rodzica komponenetu. + // W przypadku naszej klasy parametr ten wskazuje na null + // co oznacza, ze komponenet nie ma rodzica, jest to + // komponenet najwyzszego poziomu + explicit MyWindow(QWidget *parent = 0); + + // Deklaracja destruktora + ~MyWindow(); + +private: + // QtCreator pozwala na tworzenie GUI za pomoca graficznego kreatora. + // Skladniki interfejsu i ich wlasciwosci zapisane sa wowczas + // w pliku XML "nazwa_klasy.ui" + // Do poszczegolnych elementow GUI odwolujemy sie za pomoca zmiennej "ui" + Ui::MyWindow *ui; + + Mode mode; + + // Pole przechowujace obrazek + QImage *img; + + QImage *loaded_img; + + // Pole przechowujace obrazek + QImage *img_tmp; + + QImage *active_img; + + // Pola przechowujace szerokosc i wysokosc rysunku + // oraz wspolrzedne jego lewego gornego naroznika + int szer; + int wys; + int poczX; + int poczY; + int startX, startY; + bool draw_finished; + int segment_count; + + float rotation_angle; + Point vertices[8] = { + Point(-1.0f, 1.0f, -1.0f), + Point(1.0f, 1.0f, -1.0f), + Point(1.0f, -1.0f, -1.0f), + Point(-1.0f, -1.0f, -1.0f), + Point(-1.0f, 1.0f, 1.0f), + Point(1.0f, 1.0f, 1.0f), + Point(1.0f, -1.0f, 1.0f), + Point(-1.0f, -1.0f, 1.0f), + }; +// int indices[24] = { +// 0, 1, +// 1, 2, +// 2, 3, +// 3, 0, + +// 4, 5, +// 5, 6, +// 6, 7, +// 7, 4, + +// 0, 4, +// 1, 5, +// 2, 6, +// 3, 7, +// }; + int indices[36] = { + 0, 1, 2, + 2, 3, 0, + + 6, 5, 4, + 4, 7, 6, + + 7, 0, 3, + 0, 7, 4, + + 1, 5, 2, + 5, 6, 2, + + 3, 2, 6, + 6, 7, 3, + + 0, 4, 1, + 1, 4, 5 +// 4, 5, +// 5, 6, +// 6, 7, +// 7, 4, + +// 0, 4, +// 1, 5, +// 2, 6, +// 3, 7, + }; + std::vector scale_vec; + std::vector translation_vec; + std::vector rotation_vec; + std::vector sh_vec; + + bool draw_normals; + + int tmp_point_id = 0; + int tmp_shape_id = 0; + + // Deklaracje funkcji + void czysc(); + void rysuj1(); + void rysuj2(); + + + void UpdateTempImage(); + void ApplyTempImage(); + + void ClearImage(QImage *img); + void DrawB(int b); + void DrawR(int r); + void DrawG(int g); + void DrawH(float h); + void DrawS(float s); + void DrawV(float v); + + void DrawLine(int x1, int y1, int x2, int y2, QImage *img, QColor color); + QColor GetPixel(QImage* img, int x, int y); + void DrawPixel(QImage* img, int x, int y, QColor color); + QColor GetInterpolatedColor(float x, float y); + void UpdateImage(); + std::vector GetXY(Point p); + + // Deklaracje slotow, czyli funkcji wywolywanych + // po wystapieniu zdarzen zwiazanych z GUI + // np. klikniecie na przycisk, ruch myszka +private slots: + void on_exitButton_clicked(); + void paintEvent(QPaintEvent*); + void on_slider_tx_valueChanged(int val); + void on_slider_ty_valueChanged(int val); + void on_slider_tz_valueChanged(int val); + void on_slider_sx_valueChanged(int val); + void on_slider_sy_valueChanged(int val); + void on_slider_sz_valueChanged(int val); + void on_slider_shx_valueChanged(int val); + void on_slider_shy_valueChanged(int val); + void on_slider_rx_valueChanged(int val); + void on_slider_ry_valueChanged(int val); + void on_slider_rz_valueChanged(int val); + void on_slider_n_valueChanged(int val); +}; + +#endif // MYWINDOW_H diff --git a/QT/3d-cube-culling/mywindow.ui b/QT/3d-cube-culling/mywindow.ui new file mode 100644 index 0000000..95de99c --- /dev/null +++ b/QT/3d-cube-culling/mywindow.ui @@ -0,0 +1,552 @@ + + + MyWindow + + + + 0 + 0 + 1084 + 820 + + + + true + + + MyWindow + + + + + + 10 + 10 + 800 + 800 + + + + true + + + QFrame::NoFrame + + + QFrame::Raised + + + + + + 820 + 10 + 241 + 751 + + + + + + + + + 90 + 10 + 75 + 23 + + + + Wyjście + + + + + + 30 + 90 + 31 + 121 + + + + 200 + + + 100 + + + Qt::Vertical + + + + + + 110 + 90 + 31 + 121 + + + + 200 + + + 100 + + + Qt::Vertical + + + + + + 30 + 610 + 31 + 121 + + + + 200 + + + 100 + + + Qt::Vertical + + + + + + 30 + 260 + 31 + 121 + + + + 200 + + + 100 + + + Qt::Vertical + + + + + + 110 + 260 + 31 + 121 + + + + 200 + + + 100 + + + Qt::Vertical + + + + + + 110 + 610 + 31 + 121 + + + + 200 + + + 100 + + + Qt::Vertical + + + + + + 30 + 50 + 41 + 31 + + + + + 25 + + + + TX + + + Qt::AlignCenter + + + + + + 110 + 50 + 41 + 31 + + + + + 25 + + + + TY + + + Qt::AlignCenter + + + + + + 30 + 220 + 41 + 31 + + + + + 25 + + + + SX + + + Qt::AlignCenter + + + + + + 110 + 220 + 41 + 31 + + + + + 25 + + + + SY + + + Qt::AlignCenter + + + + + + 20 + 570 + 61 + 31 + + + + + 25 + + + + SHX + + + Qt::AlignCenter + + + + + + 100 + 570 + 61 + 31 + + + + + 25 + + + + SHY + + + Qt::AlignCenter + + + + + + 30 + 430 + 31 + 121 + + + + 100 + + + Qt::Vertical + + + + + + 110 + 430 + 31 + 121 + + + + 100 + + + Qt::Vertical + + + + + + 190 + 430 + 31 + 121 + + + + 100 + + + Qt::Vertical + + + + + + 30 + 390 + 41 + 31 + + + + + 25 + + + + RX + + + Qt::AlignCenter + + + + + + 100 + 390 + 41 + 31 + + + + + 25 + + + + RY + + + Qt::AlignCenter + + + + + + 180 + 390 + 41 + 31 + + + + + 25 + + + + RZ + + + Qt::AlignCenter + + + + + + 190 + 220 + 41 + 31 + + + + + 25 + + + + SZ + + + Qt::AlignCenter + + + + + + 190 + 260 + 31 + 121 + + + + 200 + + + 100 + + + Qt::Vertical + + + + + + 190 + 90 + 31 + 121 + + + + 200 + + + 100 + + + Qt::Vertical + + + + + + 190 + 49 + 41 + 31 + + + + + 25 + + + + TZ + + + Qt::AlignCenter + + + + + + 170 + 570 + 71 + 31 + + + + + 13 + + + + Normals + + + Qt::AlignCenter + + + + + + 180 + 610 + 31 + 121 + + + + 1 + + + 1 + + + Qt::Vertical + + + + + + + + 0 + 0 + 1084 + 22 + + + + + + + + +