diff --git a/include/tools/TRS.h b/include/tools/TRS.h index 2979c47..22bfaba 100644 --- a/include/tools/TRS.h +++ b/include/tools/TRS.h @@ -2,6 +2,7 @@ #define TRS_H #define T_SENSITIVITY 0.001 +#define R_SENSITIVITY 1 #include "Model.h" @@ -24,4 +25,12 @@ class Transform : public TRS virtual void process(GLuint64 selectedID, GLuint etc, const glm::vec4& dpos); // Взаимодействие с инструментом }; +// Инструмент поворота +class Rotate : public TRS +{ + public: + Rotate(); + virtual void process(GLuint64 selectedID, GLuint etc, const glm::vec4& dpos); // Взаимодействие с инструментом +}; + #endif // TRS_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0070cc6..cef032c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -403,6 +403,8 @@ int main(void) // Инструменты Transform transform; + Rotate rotate; + TRS& currentTool = rotate; // Пока не произойдет событие запроса закрытия окна while(!glfwWindowShouldClose(window)) @@ -430,7 +432,7 @@ int main(void) // Используем шейдер для инструментов toolsShader.use(); // Рендерим инструменты для выбранного объекта - transform.render(selected.value, toolsShader, material_data); + currentTool.render(selected.value, toolsShader, material_data); // Выбор объекта if (mouse.left == 0100000) @@ -567,7 +569,7 @@ int main(void) // Взаимодействие с инструментом при зажатой левой кнопке if (mouse.left > 0100000) if (selected.etc) - transform.process(selected.value, selected.etc, glm::transpose(camera.getVP()) * glm::vec4(mouse.x - mouse.prev_x, mouse.prev_y - mouse.y, 0, 1)); + currentTool.process(selected.value, selected.etc, glm::transpose(camera.getVP()) * glm::vec4(mouse.x - mouse.prev_x, mouse.prev_y - mouse.y, 0, 1)); } // Отключение атрибутов diff --git a/src/tools/TRS.cpp b/src/tools/TRS.cpp index 3a63ffd..8de09f0 100644 --- a/src/tools/TRS.cpp +++ b/src/tools/TRS.cpp @@ -60,4 +60,41 @@ void Transform::process(GLuint64 selectedID, GLuint etc, const glm::vec4& dpos) if (etc > 0) selectedObject->dPosition(dVec); } +} + +Rotate::Rotate() +{ + tool = loadOBJtoGroupted("../resources/models/tools/rotate.obj", "../resources/models/tools/", "../resources/textures/"); + + // Масштабирование + tool.scale = glm::vec3(0.3); + tool.rotation.y = 180; + + // Инициализация дополнительной информации + tool.parts[0].id.etc = 1; + tool.parts[1].id.etc = 2; + tool.parts[2].id.etc = 4; +} + +// Взаимодействие с инструментом +void Rotate::process(GLuint64 selectedID, GLuint etc, const glm::vec4& dpos) +{ + // Если есть выбранная модель - рендерим инструмент для неё + if (selectedID) + { + // Указатель на объект + Movable* selectedObject = (Movable*) selectedID; + + glm::vec3 dVec(0); + + if (etc & 01) + dVec.x = dpos.x * R_SENSITIVITY; + if (etc & 02) + dVec.z = dpos.z * R_SENSITIVITY; + if (etc & 04) + dVec.y = dpos.y * R_SENSITIVITY; + + if (etc > 0) + selectedObject->dRotation(dVec); + } } \ No newline at end of file