Finished 3D-1
This commit is contained in:
parent
e9bfc632d6
commit
47e5eca456
@ -38,10 +38,15 @@ std::vector<float> matrixMul(std::vector<float> p, std::vector<float> m)
|
|||||||
std::vector<float> MyWindow::GetXY(Point p, std::vector<float> m)
|
std::vector<float> MyWindow::GetXY(Point p, std::vector<float> m)
|
||||||
{
|
{
|
||||||
std::vector<float> res(3);
|
std::vector<float> res(3);
|
||||||
res[0] = ((p.x + VIEW_SIZE / 2.0f) / VIEW_SIZE * szer );
|
float d = 5;
|
||||||
res[1] = ((p.y + VIEW_SIZE / 2.0f) / VIEW_SIZE * wys);
|
float x = (p.x * d) / (p.z + d);
|
||||||
|
float y = (p.y * d) / (p.z + d);
|
||||||
|
float z = 0;
|
||||||
|
|
||||||
return res;
|
x = ((x + VIEW_SIZE / 2.0f) / VIEW_SIZE * szer );
|
||||||
|
y = ((y + VIEW_SIZE / 2.0f) / VIEW_SIZE * wys);
|
||||||
|
|
||||||
|
return std::vector<float>{x, y, z};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> matrixMul3x3(std::vector<float> m1, std::vector<float> m2)
|
std::vector<float> matrixMul3x3(std::vector<float> m1, std::vector<float> m2)
|
||||||
@ -154,15 +159,15 @@ void MyWindow::on_exitButton_clicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::on_slider_tx_valueChanged(int val){
|
void MyWindow::on_slider_tx_valueChanged(int val){
|
||||||
translation_vec[0] = val / 100.0f - 1.0f;
|
translation_vec[0] = 4.0f * (val / 100.0f - 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::on_slider_ty_valueChanged(int val){
|
void MyWindow::on_slider_ty_valueChanged(int val){
|
||||||
translation_vec[1] = val / 100.0f - 1.0f;
|
translation_vec[1] = 4.0f * (val / 100.0f - 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::on_slider_tz_valueChanged(int val){
|
void MyWindow::on_slider_tz_valueChanged(int val){
|
||||||
translation_vec[2] = val / 100.0f - 1.0f;
|
translation_vec[2] = 4.0f * (val / 100.0f - 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::on_slider_rx_valueChanged(int val){
|
void MyWindow::on_slider_rx_valueChanged(int val){
|
||||||
@ -178,15 +183,15 @@ void MyWindow::on_slider_rz_valueChanged(int val){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::on_slider_sx_valueChanged(int val){
|
void MyWindow::on_slider_sx_valueChanged(int val){
|
||||||
scale_vec[0] = 1.0f / ( val / 100.0f );
|
scale_vec[0] = 1.0f + (4.0f * (( val / 100.0f ) - 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::on_slider_sy_valueChanged(int val){
|
void MyWindow::on_slider_sy_valueChanged(int val){
|
||||||
scale_vec[1] = 1.0f / ( val / 100.0f );
|
scale_vec[1] = 1.0f + (4.0f * (( val / 100.0f ) - 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::on_slider_sz_valueChanged(int val){
|
void MyWindow::on_slider_sz_valueChanged(int val){
|
||||||
scale_vec[2] = 1.0f / ( val / 100.0f );
|
scale_vec[2] = 1.0f + (4.0f * (( val / 100.0f ) - 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::on_slider_shx_valueChanged(int val){
|
void MyWindow::on_slider_shx_valueChanged(int val){
|
||||||
@ -256,17 +261,19 @@ void MyWindow::UpdateImage(){
|
|||||||
matrixMul4x4(
|
matrixMul4x4(
|
||||||
matrixMul4x4(
|
matrixMul4x4(
|
||||||
scale_mat,
|
scale_mat,
|
||||||
|
translate_mat),
|
||||||
rotation_mat_x),
|
rotation_mat_x),
|
||||||
rotation_mat_y),
|
rotation_mat_y),
|
||||||
rotation_mat_z),
|
rotation_mat_z),
|
||||||
sh_mat),
|
sh_mat);
|
||||||
translate_mat);
|
|
||||||
|
|
||||||
ClearImage(img);
|
ClearImage(img);
|
||||||
|
|
||||||
for(int i = 1; i < 8; i++){
|
int lines = (sizeof(indices)/sizeof(*indices)) / 2;
|
||||||
Point P1 = points[i-1];
|
|
||||||
Point P2 = points[i];
|
for(int i = 0; i < lines; i++){
|
||||||
|
Point P1 = vertices[indices[2*i]];
|
||||||
|
Point P2 = vertices[indices[2*i + 1]];
|
||||||
Point P1M = Point(matrixMul(P1.GetVector(), tansform_mat));
|
Point P1M = Point(matrixMul(P1.GetVector(), tansform_mat));
|
||||||
Point P2M = Point(matrixMul(P2.GetVector(), tansform_mat));
|
Point P2M = Point(matrixMul(P2.GetVector(), tansform_mat));
|
||||||
std::vector<float> p1_vec = GetXY(P1M, std::vector<float>{});
|
std::vector<float> p1_vec = GetXY(P1M, std::vector<float>{});
|
||||||
@ -367,7 +374,8 @@ void MyWindow::DrawLine(int x1, int y1, int x2, int y2, QImage *img){
|
|||||||
float diff = x2 - x1;
|
float diff = x2 - x1;
|
||||||
float a = diff != 0 ? (y2 - y1) / diff : FLT_MAX;
|
float a = diff != 0 ? (y2 - y1) / diff : FLT_MAX;
|
||||||
|
|
||||||
QColor color(255, 255, 255, 255);
|
// QColor color(255, 255, 255, 255);
|
||||||
|
QColor color(255, 0, 80, 255);
|
||||||
|
|
||||||
if(abs(a) < 1.0f){
|
if(abs(a) < 1.0f){
|
||||||
for(int x = x1; x <= x2; x++){
|
for(int x = x1; x <= x2; x++){
|
||||||
@ -409,9 +417,9 @@ void MyWindow::DrawPixel(QImage* img, int x, int y, QColor color){
|
|||||||
|
|
||||||
void MyWindow::ClearImage(QImage *img){
|
void MyWindow::ClearImage(QImage *img){
|
||||||
unsigned char* empty_val = (unsigned char*)malloc(4);
|
unsigned char* empty_val = (unsigned char*)malloc(4);
|
||||||
empty_val[0] = 0;
|
empty_val[0] = 15;
|
||||||
empty_val[1] = 0;
|
empty_val[1] = 15;
|
||||||
empty_val[2] = 0;
|
empty_val[2] = 15;
|
||||||
empty_val[3] = 255;
|
empty_val[3] = 255;
|
||||||
unsigned char* ptr = img->bits();
|
unsigned char* ptr = img->bits();
|
||||||
for(int i = 0; i < img->width(); i++){
|
for(int i = 0; i < img->width(); i++){
|
||||||
|
@ -125,15 +125,31 @@ private:
|
|||||||
int segment_count;
|
int segment_count;
|
||||||
|
|
||||||
float rotation_angle;
|
float rotation_angle;
|
||||||
Point points[8] = {
|
Point vertices[8] = {
|
||||||
Point(-1.0f, -1.0f, 0.0f),
|
Point(-1.0f, -1.0f, -1.0f),
|
||||||
Point(1.0f, -1.0f, 0.0f),
|
Point(1.0f, -1.0f, -1.0f),
|
||||||
Point(1.0f, 1.0f, 0.0f),
|
Point(1.0f, 1.0f, -1.0f),
|
||||||
Point(-1.0f, 1.0f, 0.0f),
|
Point(-1.0f, 1.0f, -1.0f),
|
||||||
Point(-1.0f, -1.0f, 0.0f),
|
Point(-1.0f, -1.0f, 1.0f),
|
||||||
Point(1.0f, -1.0f, 0.0f),
|
Point(1.0f, -1.0f, 1.0f),
|
||||||
Point(1.0f, 1.0f, 0.0f),
|
Point(1.0f, 1.0f, 1.0f),
|
||||||
Point(-1.0f, 1.0f, 0.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,
|
||||||
};
|
};
|
||||||
std::vector<float> scale_vec;
|
std::vector<float> scale_vec;
|
||||||
std::vector<float> translation_vec;
|
std::vector<float> translation_vec;
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>888</width>
|
<width>1084</width>
|
||||||
<height>868</height>
|
<height>820</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="mouseTracking">
|
<property name="mouseTracking">
|
||||||
@ -22,8 +22,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>10</x>
|
<x>10</x>
|
||||||
<y>10</y>
|
<y>10</y>
|
||||||
<width>600</width>
|
<width>800</width>
|
||||||
<height>600</height>
|
<height>800</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="mouseTracking">
|
<property name="mouseTracking">
|
||||||
@ -39,20 +39,20 @@
|
|||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>630</x>
|
<x>820</x>
|
||||||
<y>10</y>
|
<y>10</y>
|
||||||
<width>241</width>
|
<width>241</width>
|
||||||
<height>781</height>
|
<height>751</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Opcje</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QPushButton" name="exitButton">
|
<widget class="QPushButton" name="exitButton">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>90</x>
|
<x>90</x>
|
||||||
<y>30</y>
|
<y>10</y>
|
||||||
<width>75</width>
|
<width>75</width>
|
||||||
<height>23</height>
|
<height>23</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -65,7 +65,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>30</x>
|
<x>30</x>
|
||||||
<y>120</y>
|
<y>90</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -84,7 +84,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>110</x>
|
<x>110</x>
|
||||||
<y>120</y>
|
<y>90</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -103,7 +103,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>30</x>
|
<x>30</x>
|
||||||
<y>640</y>
|
<y>610</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -122,7 +122,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>30</x>
|
<x>30</x>
|
||||||
<y>290</y>
|
<y>260</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -141,7 +141,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>110</x>
|
<x>110</x>
|
||||||
<y>290</y>
|
<y>260</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -160,7 +160,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>110</x>
|
<x>110</x>
|
||||||
<y>640</y>
|
<y>610</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -179,7 +179,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>30</x>
|
<x>30</x>
|
||||||
<y>80</y>
|
<y>50</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -200,7 +200,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>110</x>
|
<x>110</x>
|
||||||
<y>80</y>
|
<y>50</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -221,7 +221,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>30</x>
|
<x>30</x>
|
||||||
<y>250</y>
|
<y>220</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -242,7 +242,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>110</x>
|
<x>110</x>
|
||||||
<y>250</y>
|
<y>220</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -263,7 +263,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>20</x>
|
<x>20</x>
|
||||||
<y>600</y>
|
<y>570</y>
|
||||||
<width>61</width>
|
<width>61</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -284,7 +284,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>100</x>
|
<x>100</x>
|
||||||
<y>600</y>
|
<y>570</y>
|
||||||
<width>61</width>
|
<width>61</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -305,7 +305,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>30</x>
|
<x>30</x>
|
||||||
<y>460</y>
|
<y>430</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -321,7 +321,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>110</x>
|
<x>110</x>
|
||||||
<y>460</y>
|
<y>430</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -337,7 +337,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>190</x>
|
<x>190</x>
|
||||||
<y>460</y>
|
<y>430</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -353,7 +353,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>30</x>
|
<x>30</x>
|
||||||
<y>420</y>
|
<y>390</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -374,7 +374,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>100</x>
|
<x>100</x>
|
||||||
<y>420</y>
|
<y>390</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -395,7 +395,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>180</x>
|
<x>180</x>
|
||||||
<y>420</y>
|
<y>390</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -416,7 +416,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>190</x>
|
<x>190</x>
|
||||||
<y>250</y>
|
<y>220</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -437,7 +437,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>190</x>
|
<x>190</x>
|
||||||
<y>290</y>
|
<y>260</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -456,7 +456,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>190</x>
|
<x>190</x>
|
||||||
<y>120</y>
|
<y>90</y>
|
||||||
<width>31</width>
|
<width>31</width>
|
||||||
<height>121</height>
|
<height>121</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -475,7 +475,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>190</x>
|
<x>190</x>
|
||||||
<y>79</y>
|
<y>49</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>31</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -499,19 +499,11 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>888</width>
|
<width>1084</width>
|
||||||
<height>22</height>
|
<height>22</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QToolBar" name="mainToolBar">
|
|
||||||
<attribute name="toolBarArea">
|
|
||||||
<enum>TopToolBarArea</enum>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="toolBarBreak">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
<widget class="QStatusBar" name="statusBar"/>
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user