diff options
Diffstat (limited to 'ToolRotate.cpp')
-rw-r--r-- | ToolRotate.cpp | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/ToolRotate.cpp b/ToolRotate.cpp index 6cd7626..65bf334 100644 --- a/ToolRotate.cpp +++ b/ToolRotate.cpp @@ -1,6 +1,8 @@ #include "ToolRotate.h" +#include <GL/gl.h> -ToolRotate::ToolRotate(EditManager *editManager) : sidebar(editManager) { + +ToolRotate::ToolRotate(EditManager *editManager) : Renderer(editManager), sidebar(editManager) { this->editManager = editManager; pressed = false; @@ -24,8 +26,8 @@ bool ToolRotate::buttonPress(unsigned int button) { return false; pressed = true; - Vertex v = *editManager->getHoveredVertex() - editManager->getHoveredObject()->getCenter(); - angle = atan2(v.getY(), v.getX()); + valid = false; + v0 = v = *editManager->getHoveredVertex(); editManager->setSelectedObject(editManager->getHoveredObject()); @@ -58,13 +60,40 @@ bool ToolRotate::motion() { if(!editManager->getHoveredVertex()) return false; - Vertex v = *editManager->getHoveredVertex() - editManager->getSelectedObject()->getCenter(); + v = *editManager->getHoveredVertex(); - float a = atan2(v.getY(), v.getX()); + float a = atan2((v-v0).getY(), (v-v0).getX()); - editManager->getSelectedObject()->rotate(a-angle); + if(v0.distanceSq(v) > 0.04f) { + if(valid) + editManager->getSelectedObject()->rotate(v0, a-angle); + + else + valid = true; + } + else + valid = false; angle = a; return false; } + +void ToolRotate::render(const Level &level, const Rectangle &rect, float scale) { + Renderer::render(level, rect, scale); + + if(pressed && valid) { + glLineWidth(1.0f); + glColor4f(1.0f, 1.0f, 1.0f, 0.7f); + drawCircleDotted(v0, v0.distance(v), 64, 16, angle); + + glLineWidth(2.0f); + + glBegin(GL_LINES); + + glVertex2f(v0.getX(), v0.getY()); + glVertex2f(v.getX(), v.getY()); + + glEnd(); + } +} |