Fri, 22 Jun 2018 15:03:50 +0300
removed a duplicate member
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | #include "matrixeditor.h" |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | #include "ui_matrixeditor.h" |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
4 | MatrixEditor::MatrixEditor(const QMatrix4x4& matrix, QWidget *parent) : |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | QWidget {parent}, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | ui {*new Ui_MatrixEditor} |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | this->ui.setupUi(this); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | this->setMatrix(matrix); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | for (int i : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | for (int j : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | connect( |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | matrixCell(i, j), |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | qOverload<double>(&QDoubleSpinBox::valueChanged), |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | this, |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
18 | &MatrixEditor::matrix3x3Changed |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | ); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | for (QDoubleSpinBox* spinbox : {this->ui.scalingX, this->ui.scalingY, this->ui.scalingZ}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | connect( |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | spinbox, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | qOverload<double>(&QDoubleSpinBox::valueChanged), |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | this, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | &MatrixEditor::scalingChanged |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | ); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | } |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
31 | |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
32 | for (QDoubleSpinBox* spinbox : {ui.positionX, ui.positionY, ui.positionZ}) |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
33 | { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
34 | connect( |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
35 | spinbox, |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
36 | qOverload<double>(&QDoubleSpinBox::valueChanged), |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
37 | [&](){ emit matrixChanged(this->matrix()); } |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
38 | ); |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
39 | } |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | MatrixEditor::MatrixEditor(QWidget* parent) : |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
43 | MatrixEditor {{}, parent} {} |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
45 | MatrixEditor::~MatrixEditor() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | delete &this->ui; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | /* |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | * Returns a spinbox from the matrix grid at position (row, column). |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | * Row and column must be within [0, 2]. |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | */ |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | QDoubleSpinBox* MatrixEditor::matrixCell(int row, int column) const |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | if (qBound(0, row, 2) != row or qBound(0, column, 2) != column) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | throw std::out_of_range {"bad row and column values"}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | else |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(row, column); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | return item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
67 | /* |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | * Returns a spinbox for the vector element at the given position |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | * Index must be within [0, 2] |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
70 | */ |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | QDoubleSpinBox* MatrixEditor::vectorElement(int index) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | switch (index) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
74 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | case 0: |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | return this->ui.scalingX; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | case 1: |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | return this->ui.scalingY; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
80 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | case 2: |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
82 | return this->ui.scalingZ; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | default: |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
85 | throw std::out_of_range {"bad index"}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
86 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
87 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
88 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | double MatrixEditor::matrixScaling(int column) const |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
90 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
91 | return sqrt( |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
92 | pow(this->matrixCell(0, column)->value(), 2) + |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
93 | pow(this->matrixCell(1, column)->value(), 2) + |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
94 | pow(this->matrixCell(2, column)->value(), 2) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
95 | ); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
96 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
97 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
98 | /* |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
99 | * Updates the appropriate matrix column when a scaling vector element is changed. |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
100 | */ |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
101 | void MatrixEditor::scalingChanged() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
102 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
103 | for (int column : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
104 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
105 | if (this->sender() == this->vectorElement(column)) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
106 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
107 | double oldScaling = this->matrixScaling(column); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
108 | double newScaling = static_cast<QDoubleSpinBox*>(this->sender())->value(); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
109 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
110 | if (not qFuzzyCompare(newScaling, 0.0)) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
111 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
112 | for (int row : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
113 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
114 | double cellValue = this->matrixCell(row, column)->value(); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
115 | cellValue *= newScaling / oldScaling; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
116 | QDoubleSpinBox* cellWidget = this->matrixCell(row, column); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
117 | withSignalsBlocked(cellWidget, [&]() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
118 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
119 | cellWidget->setValue(cellValue); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
120 | }); |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
121 | emit matrixChanged(this->matrix()); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
122 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
123 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
124 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
125 | break; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
126 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
127 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
128 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
129 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
130 | /* |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
131 | * Finds the position for the given cell widget. |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
132 | */ |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
133 | QPair<int, int> MatrixEditor::cellPosition(QDoubleSpinBox* cellWidget) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
134 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
135 | for (int row : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
136 | for (int column : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
137 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
138 | if (this->matrixCell(row, column) == cellWidget) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
139 | return {row, column}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
140 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
141 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
142 | throw std::out_of_range {"widget is not in the matrix"}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
143 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
144 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
145 | /* |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
146 | * Updates the appropriate scaling vector element when a matrix cell is changed. |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
147 | */ |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
148 | void MatrixEditor::matrix3x3Changed() |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
149 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
150 | QDoubleSpinBox* cellWidget = static_cast<QDoubleSpinBox*>(this->sender()); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
151 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
152 | try |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
153 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
154 | int column = this->cellPosition(cellWidget).second; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
155 | QDoubleSpinBox* spinbox = this->vectorElement(column); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
156 | withSignalsBlocked(spinbox, [&]() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
157 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
158 | spinbox->setValue(this->matrixScaling(column)); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
159 | }); |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
160 | emit matrixChanged(this->matrix()); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
161 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
162 | catch (const std::out_of_range&) {} |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
163 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
164 | |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
165 | QMatrix4x4 MatrixEditor::matrix() const |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
166 | { |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
167 | QMatrix4x4 transformationMatrix; |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
168 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
169 | for (int i : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
170 | for (int j : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
171 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
172 | transformationMatrix(i, j) = this->matrixCell(i, j)->value(); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
173 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
174 | |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
175 | QVector4D translation { |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
176 | (float) ui.positionX->value(), |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
177 | (float) ui.positionY->value(), |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
178 | (float) ui.positionZ->value(), |
1408
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1406
diff
changeset
|
179 | 1.0f |
1406
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
180 | }; |
37fffb682d2f
Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents:
1403
diff
changeset
|
181 | transformationMatrix.setColumn(3, translation); |
1408
0d6162662040
fixed bugs regarding primitives, added chord substitution
Teemu Piippo <teemu@hecknology.net>
parents:
1406
diff
changeset
|
182 | transformationMatrix.optimize(); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
183 | return transformationMatrix; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
184 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
185 | |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
186 | void MatrixEditor::setMatrix(const QMatrix4x4& matrix) |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
187 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
188 | for (int i : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
189 | for (int j : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
190 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
191 | QDoubleSpinBox* spinbox = matrixCell(i, j); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
192 | withSignalsBlocked(spinbox, [&](){ spinbox->setValue(matrix(i, j)); }); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
193 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
194 | |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
195 | ui.positionX->setValue(matrix(0, 3)); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
196 | ui.positionY->setValue(matrix(1, 3)); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
197 | ui.positionZ->setValue(matrix(2, 3)); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
198 | |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
199 | // Fill in the initial scaling values |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
200 | for (int column : {0, 1, 2}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
201 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
202 | QDoubleSpinBox* spinbox = this->vectorElement(column); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
203 | withSignalsBlocked(spinbox, [&]() |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
204 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
205 | spinbox->setValue(this->matrixScaling(column)); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
206 | }); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
207 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
208 | } |