Added sliders for every transformation

This commit is contained in:
Dawid Pietrykowski 2023-06-13 20:11:17 +02:00
parent d2e0f1da56
commit e9bfc632d6
3 changed files with 285 additions and 63 deletions

View File

@ -22,13 +22,13 @@ const int VIEW_SIZE = 4.0f;
std::vector<float> matrixMul(std::vector<float> p, std::vector<float> m)
{
std::vector<float> res(3);
for(int i = 0; i < 3; i++)
std::vector<float> res(4);
for(int i = 0; i < 4; i++)
{
res.push_back(0);
for(int j = 0; j < 3; j++)
for(int j = 0; j < 4; j++)
{
res[i] += m[i * 3 + j] * p[j];
res[i] += m[i * 4 + j] * p[j];
}
}
return res;
@ -107,6 +107,11 @@ MyWindow::MyWindow(QWidget *parent) :
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);
@ -119,6 +124,7 @@ MyWindow::MyWindow(QWidget *parent) :
// 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);
@ -155,8 +161,20 @@ void MyWindow::on_slider_ty_valueChanged(int val){
translation_vec[1] = val / 100.0f - 1.0f;
}
void MyWindow::on_slider_a_valueChanged(int val){
rotation_angle = val;
void MyWindow::on_slider_tz_valueChanged(int val){
translation_vec[2] = 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){
@ -167,6 +185,10 @@ void MyWindow::on_slider_sy_valueChanged(int val){
scale_vec[1] = 1.0f / ( val / 100.0f );
}
void MyWindow::on_slider_sz_valueChanged(int val){
scale_vec[2] = 1.0f / ( val / 100.0f );
}
void MyWindow::on_slider_shx_valueChanged(int val){
sh_vec[0] = val / 100.0f - 1.0f;
}
@ -176,23 +198,25 @@ void MyWindow::on_slider_shy_valueChanged(int val){
}
void MyWindow::UpdateImage(){
float sina = sin(rotation_angle * 0.01745329252f);
float cosa = cos(rotation_angle * 0.01745329252f);
float sina;
float cosa;
std::vector<float> translate_mat = {
1, 0, 0, translation_vec[0],
0, 1, 0, translation_vec[1],
0, 0, 1, 0,
0, 0, 1, translation_vec[2],
0, 0, 0, 1,
};
std::vector<float> scale_mat = {
scale_vec[0], 0, 0, 0,
0, scale_vec[1], 0, 0,
0, 0, scale_vec[1], 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<float> rotation_mat_x = {
1, 0, 0, 0,
0, cosa, -sina, 0,
@ -200,6 +224,8 @@ void MyWindow::UpdateImage(){
0, 0, 0, 1
};
sina = sin(rotation_vec[1] * 0.01745329252f);
cosa = cos(rotation_vec[1] * 0.01745329252f);
std::vector<float> rotation_mat_y = {
cosa, 0, sina, 0,
0, 1, 0, 0,
@ -207,6 +233,8 @@ void MyWindow::UpdateImage(){
0, 0, 0, 1
};
sina = sin(rotation_vec[2] * 0.01745329252f);
cosa = cos(rotation_vec[2] * 0.01745329252f);
std::vector<float> rotation_mat_z = {
cosa, -sina, 0, 0,
sina, cosa, 0, 0,
@ -234,11 +262,15 @@ void MyWindow::UpdateImage(){
sh_mat),
translate_mat);
ClearImage(img);
for(int i = 1; i < 8; i++){
Point P1 = points[i-1];
Point P2 = points[i];
std::vector<float> p1_vec = GetXY(P1, std::vector<float>{});
std::vector<float> p2_vec = GetXY(P2, std::vector<float>{});
Point P1M = Point(matrixMul(P1.GetVector(), tansform_mat));
Point P2M = Point(matrixMul(P2.GetVector(), tansform_mat));
std::vector<float> p1_vec = GetXY(P1M, std::vector<float>{});
std::vector<float> p2_vec = GetXY(P2M, std::vector<float>{});
DrawLine(p1_vec[0], p1_vec[1], p2_vec[0], p2_vec[1], img);
}

View File

@ -40,6 +40,16 @@ struct Point{
this->z=z;
}
Point(std::vector<float> vec){
this->x=vec[0];
this->y=vec[1];
this->z=vec[2];
}
std::vector<float> GetVector(){
return std::vector<float>{x, y, z, 1};
}
float length(){
float mag = std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2));
return mag;
@ -127,6 +137,7 @@ private:
};
std::vector<float> scale_vec;
std::vector<float> translation_vec;
std::vector<float> rotation_vec;
std::vector<float> sh_vec;
int tmp_point_id = 0;
@ -164,11 +175,15 @@ private slots:
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_a_valueChanged(int val);
void on_slider_rx_valueChanged(int val);
void on_slider_ry_valueChanged(int val);
void on_slider_rz_valueChanged(int val);
};
#endif // MYWINDOW_H

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>883</width>
<height>583</height>
<width>888</width>
<height>868</height>
</rect>
</property>
<property name="mouseTracking">
@ -42,7 +42,7 @@
<x>630</x>
<y>10</y>
<width>241</width>
<height>421</height>
<height>781</height>
</rect>
</property>
<property name="title">
@ -102,8 +102,8 @@
<widget class="QSlider" name="slider_shx">
<property name="geometry">
<rect>
<x>190</x>
<y>120</y>
<x>30</x>
<y>640</y>
<width>31</width>
<height>121</height>
</rect>
@ -159,8 +159,8 @@
<widget class="QSlider" name="slider_shy">
<property name="geometry">
<rect>
<x>190</x>
<y>290</y>
<x>110</x>
<y>640</y>
<width>31</width>
<height>121</height>
</rect>
@ -217,27 +217,6 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>190</x>
<y>80</y>
<width>41</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>25</pointsize>
</font>
</property>
<property name="text">
<string>SHX</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
@ -280,12 +259,33 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_6">
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>190</x>
<y>250</y>
<width>41</width>
<x>20</x>
<y>600</y>
<width>61</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>25</pointsize>
</font>
</property>
<property name="text">
<string>SHX</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>100</x>
<y>600</y>
<width>61</width>
<height>31</height>
</rect>
</property>
@ -301,22 +301,197 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
<widget class="QSlider" name="slider_a">
<property name="geometry">
<rect>
<x>660</x>
<y>450</y>
<width>191</width>
<height>31</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QSlider" name="slider_rx">
<property name="geometry">
<rect>
<x>30</x>
<y>460</y>
<width>31</width>
<height>121</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QSlider" name="slider_ry">
<property name="geometry">
<rect>
<x>110</x>
<y>460</y>
<width>31</width>
<height>121</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QSlider" name="slider_rz">
<property name="geometry">
<rect>
<x>190</x>
<y>460</y>
<width>31</width>
<height>121</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>30</x>
<y>420</y>
<width>41</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>25</pointsize>
</font>
</property>
<property name="text">
<string>RX</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_10">
<property name="geometry">
<rect>
<x>100</x>
<y>420</y>
<width>41</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>25</pointsize>
</font>
</property>
<property name="text">
<string>RY</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_11">
<property name="geometry">
<rect>
<x>180</x>
<y>420</y>
<width>41</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>25</pointsize>
</font>
</property>
<property name="text">
<string>RZ</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>190</x>
<y>250</y>
<width>41</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>25</pointsize>
</font>
</property>
<property name="text">
<string>SZ</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QSlider" name="slider_sz">
<property name="geometry">
<rect>
<x>190</x>
<y>290</y>
<width>31</width>
<height>121</height>
</rect>
</property>
<property name="maximum">
<number>200</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QSlider" name="slider_tz">
<property name="geometry">
<rect>
<x>190</x>
<y>120</y>
<width>31</width>
<height>121</height>
</rect>
</property>
<property name="maximum">
<number>200</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>190</x>
<y>79</y>
<width>41</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>25</pointsize>
</font>
</property>
<property name="text">
<string>TZ</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
@ -324,8 +499,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>883</width>
<height>24</height>
<width>888</width>
<height>22</height>
</rect>
</property>
</widget>