From 7465e08a4821e348626c6adade6e05664169bfd4 Mon Sep 17 00:00:00 2001 From: "R.E. Kovalev" Date: Tue, 4 Apr 2023 17:04:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=20=D0=BC=D0=B0=D1=81=D1=88=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/TRS.h | 9 +++++++++ src/TRS.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 3 ++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/include/TRS.h b/include/TRS.h index 6399f3c..864f617 100644 --- a/include/TRS.h +++ b/include/TRS.h @@ -3,6 +3,7 @@ #define T_SENSITIVITY 0.001f #define R_SENSITIVITY 0.01f +#define S_SENSITIVITY 0.00001f #include "Scene.h" @@ -33,4 +34,12 @@ class Rotate : public TRS virtual void process(GLuint64 selectedID, GLuint etc, const glm::vec4& drot); // Взаимодействие с инструментом }; +// Инструмент масштабирования +class Scale : public TRS +{ + public: + Scale(); + virtual void process(GLuint64 selectedID, GLuint etc, const glm::vec4& dscale); // Взаимодействие с инструментом +}; + #endif // TRS_H \ No newline at end of file diff --git a/src/TRS.cpp b/src/TRS.cpp index c140612..0f0ca44 100644 --- a/src/TRS.cpp +++ b/src/TRS.cpp @@ -132,3 +132,56 @@ void Rotate::process(GLuint64 selectedID, GLuint etc, const glm::vec4& drot) selectedRot = glm::angleAxis(drot.z * R_SENSITIVITY, parentRotation * glm::vec3(0.0f, 0.0f, 1.0f)) * selectedRot; } } + +Scale::Scale() +{ + tool = loadOBJtoScene("../resources/models/tools/scale.obj", "../resources/models/tools/", "../resources/textures/"); + + // Масштабирование + tool.root.e_scale() = glm::vec3(0.3); + + // Инициализация дополнительной информации + init_etc(); +} + +// Взаимодействие с инструментом +void Scale::process(GLuint64 selectedID, GLuint etc, const glm::vec4& dscale) +{ + // Если взаимодействие с осями инструмента + if (etc > 0) + // Если есть выбранная модель - рендерим инструмент для неё + if (selectedID) + { + // Указатель на объект + Node* selectedObject = (Node*) selectedID; + + // Для хранения результата + glm::vec3 dVec(0); + + // Масштабирование с учетом чувствительности для соответствующих осей + if (etc & 01) + dVec.x = dscale.x * S_SENSITIVITY; + if (etc & 02) + dVec.y = dscale.y * S_SENSITIVITY; + if (etc & 04) + dVec.z = dscale.z * S_SENSITIVITY; + + // Если есть родитель - требуется учесть его поворот + Node* parent = selectedObject->getParent(); + if (parent) + { + // Извлекаем 3x3 подматрицу, отвечающую за вращение и масштаб + glm::mat3 rotationMatrix = glm::mat3(parent->getTransformMatrix()); + + // Нормализуем столбцы подматрицы, чтобы исключить масштабирование + for (int i = 0; i < 3; i++) + rotationMatrix[i] = glm::normalize(rotationMatrix[i]); + + // Применим поворот родителя к вектору сдвига + dVec = glm::inverse(rotationMatrix) * dVec; + } + + // Прибавим вектор масштабирования к объекту + selectedObject->e_scale() += dVec; + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index f66a14f..ee121fd 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -445,7 +445,8 @@ int main(void) // Инструменты Transform transform; Rotate rotate; - TRS& currentTool = rotate; + Scale scale; + TRS& currentTool = scale; // Пока не произойдет событие запроса закрытия окна while(!glfwWindowShouldClose(window))