Wed, 17 Feb 2016 00:47:48 +0200
Renamed ldObjectMath.cpp/.h to mathfunctions.cpp/.h
CMakeLists.txt | file | annotate | diff | comparison | revisions | |
src/editmodes/circleMode.cpp | file | annotate | diff | comparison | revisions | |
src/ldObjectMath.cpp | file | annotate | diff | comparison | revisions | |
src/ldObjectMath.h | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions | |
src/mathfunctions.cpp | file | annotate | diff | comparison | revisions | |
src/mathfunctions.h | file | annotate | diff | comparison | revisions | |
src/toolsets/algorithmtoolset.cpp | file | annotate | diff | comparison | revisions | |
src/toolsets/movetoolset.cpp | file | annotate | diff | comparison | revisions |
--- a/CMakeLists.txt Wed Feb 17 00:43:17 2016 +0200 +++ b/CMakeLists.txt Wed Feb 17 00:47:48 2016 +0200 @@ -48,10 +48,10 @@ src/hierarchyelement.cpp src/ldDocument.cpp src/ldObject.cpp - src/ldObjectMath.cpp src/ldpaths.cpp src/main.cpp src/mainwindow.cpp + src/mathfunctions.cpp src/messageLog.cpp src/miscallenous.cpp src/partdownloader.cpp @@ -102,12 +102,12 @@ src/hierarchyelement.h src/ldDocument.h src/ldObject.h - src/ldObjectMath.h src/ldobjectiterator.h src/ldpaths.h src/macros.h src/main.h src/mainwindow.h + src/mathfunctions.h src/messageLog.h src/miscallenous.h src/partdownloader.h
--- a/src/editmodes/circleMode.cpp Wed Feb 17 00:43:17 2016 +0200 +++ b/src/editmodes/circleMode.cpp Wed Feb 17 00:47:48 2016 +0200 @@ -25,7 +25,7 @@ #include "../primitives.h" #include "../glRenderer.h" #include "../mainwindow.h" -#include "../ldObjectMath.h" +#include "../mathfunctions.h" #include "../grid.h" CircleMode::CircleMode (GLRenderer* renderer) :
--- a/src/ldObjectMath.cpp Wed Feb 17 00:43:17 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 - 2016 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "ldObjectMath.h" -#include "ldObject.h" -#include "miscallenous.h" - - -MathFunctions::MathFunctions(QObject* parent) : - HierarchyElement(parent) {} - - -void MathFunctions::rotateVertex(Vertex& vertex, const Vertex& rotationPoint, const Matrix& transformationMatrix) const -{ - vertex -= rotationPoint; - vertex.transform (transformationMatrix, Origin); - vertex += rotationPoint; -} - - -void MathFunctions::rotateObjects(int l, int m, int n, double angle, const LDObjectList& objects) const -{ - Vertex rotationPoint = getRotationPoint (objects); - double cosAngle = cos(angle); - double sinAngle = sin(angle); - - // ref: http://en.wikipedia.org/wiki/Transformation_matrix#Rotation_2 - Matrix transformationMatrix ( - { - (l * l * (1 - cosAngle)) + cosAngle, - (m * l * (1 - cosAngle)) - (n * sinAngle), - (n * l * (1 - cosAngle)) + (m * sinAngle), - - (l * m * (1 - cosAngle)) + (n * sinAngle), - (m * m * (1 - cosAngle)) + cosAngle, - (n * m * (1 - cosAngle)) - (l * sinAngle), - - (l * n * (1 - cosAngle)) - (m * sinAngle), - (m * n * (1 - cosAngle)) + (l * sinAngle), - (n * n * (1 - cosAngle)) + cosAngle - }); - - // Apply the above matrix to everything - for (LDObject* obj : objects) - { - if (obj->numVertices()) - { - for (int i = 0; i < obj->numVertices(); ++i) - { - Vertex v = obj->vertex (i); - rotateVertex(v, rotationPoint, transformationMatrix); - obj->setVertex (i, v); - } - } - else if (obj->hasMatrix()) - { - LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj); - - // Transform the position - Vertex v = mo->position(); - rotateVertex(v, rotationPoint, transformationMatrix); - mo->setPosition (v); - - // Transform the matrix - mo->setTransform(transformationMatrix * mo->transform()); - } - } -} - - -Vertex MathFunctions::getRotationPoint(const LDObjectList& objs) const -{ - switch (RotationPoint (m_config->rotationPointType())) - { - case RotationPoint::ObjectOrigin: - { - BoundingBox box; - - // Calculate center vertex - for (LDObject* obj : objs) - { - if (obj->hasMatrix()) - box << static_cast<LDMatrixObject*> (obj)->position(); - else - box << obj; - } - - return box.center(); - } - - case RotationPoint::WorldOrigin: - return Vertex(); - - case RotationPoint::CustomPoint: - return m_config->customRotationPoint(); - - case RotationPoint::NumValues: - break; - } - - return Vertex(); -} \ No newline at end of file
--- a/src/ldObjectMath.h Wed Feb 17 00:43:17 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 - 2016 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once -#include "main.h" - - -enum class RotationPoint -{ - ObjectOrigin, - WorldOrigin, - CustomPoint, - NumValues -}; - - -class MathFunctions : public HierarchyElement -{ -public: - MathFunctions(QObject* parent); - - void rotateObjects(int l, int m, int n, double angle, const LDObjectList& objects) const; - Vertex getRotationPoint(const LDObjectList& objs) const; - -private: - void rotateVertex(Vertex& vertex, const Vertex& rotationPoint, const Matrix& transformationMatrix) const; -}; -
--- a/src/mainwindow.cpp Wed Feb 17 00:43:17 2016 +0200 +++ b/src/mainwindow.cpp Wed Feb 17 00:47:48 2016 +0200 @@ -57,7 +57,7 @@ #include "documentmanager.h" #include "ldobjectiterator.h" #include "grid.h" -#include "ldObjectMath.h" +#include "mathfunctions.h" ConfigOption (bool ColorizeObjectsList = true) ConfigOption (QString QuickColorToolbar = "4:25:14:27:2:3:11:1:22:|:0:72:71:15")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mathfunctions.cpp Wed Feb 17 00:47:48 2016 +0200 @@ -0,0 +1,117 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2016 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "mathfunctions.h" +#include "ldObject.h" +#include "miscallenous.h" + + +MathFunctions::MathFunctions(QObject* parent) : + HierarchyElement(parent) {} + + +void MathFunctions::rotateVertex(Vertex& vertex, const Vertex& rotationPoint, const Matrix& transformationMatrix) const +{ + vertex -= rotationPoint; + vertex.transform (transformationMatrix, Origin); + vertex += rotationPoint; +} + + +void MathFunctions::rotateObjects(int l, int m, int n, double angle, const LDObjectList& objects) const +{ + Vertex rotationPoint = getRotationPoint (objects); + double cosAngle = cos(angle); + double sinAngle = sin(angle); + + // ref: http://en.wikipedia.org/wiki/Transformation_matrix#Rotation_2 + Matrix transformationMatrix ( + { + (l * l * (1 - cosAngle)) + cosAngle, + (m * l * (1 - cosAngle)) - (n * sinAngle), + (n * l * (1 - cosAngle)) + (m * sinAngle), + + (l * m * (1 - cosAngle)) + (n * sinAngle), + (m * m * (1 - cosAngle)) + cosAngle, + (n * m * (1 - cosAngle)) - (l * sinAngle), + + (l * n * (1 - cosAngle)) - (m * sinAngle), + (m * n * (1 - cosAngle)) + (l * sinAngle), + (n * n * (1 - cosAngle)) + cosAngle + }); + + // Apply the above matrix to everything + for (LDObject* obj : objects) + { + if (obj->numVertices()) + { + for (int i = 0; i < obj->numVertices(); ++i) + { + Vertex v = obj->vertex (i); + rotateVertex(v, rotationPoint, transformationMatrix); + obj->setVertex (i, v); + } + } + else if (obj->hasMatrix()) + { + LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj); + + // Transform the position + Vertex v = mo->position(); + rotateVertex(v, rotationPoint, transformationMatrix); + mo->setPosition (v); + + // Transform the matrix + mo->setTransform(transformationMatrix * mo->transform()); + } + } +} + + +Vertex MathFunctions::getRotationPoint(const LDObjectList& objs) const +{ + switch (RotationPoint (m_config->rotationPointType())) + { + case RotationPoint::ObjectOrigin: + { + BoundingBox box; + + // Calculate center vertex + for (LDObject* obj : objs) + { + if (obj->hasMatrix()) + box << static_cast<LDMatrixObject*> (obj)->position(); + else + box << obj; + } + + return box.center(); + } + + case RotationPoint::WorldOrigin: + return Vertex(); + + case RotationPoint::CustomPoint: + return m_config->customRotationPoint(); + + case RotationPoint::NumValues: + break; + } + + return Vertex(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mathfunctions.h Wed Feb 17 00:47:48 2016 +0200 @@ -0,0 +1,43 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2016 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include "main.h" + + +enum class RotationPoint +{ + ObjectOrigin, + WorldOrigin, + CustomPoint, + NumValues +}; + + +class MathFunctions : public HierarchyElement +{ +public: + MathFunctions(QObject* parent); + + void rotateObjects(int l, int m, int n, double angle, const LDObjectList& objects) const; + Vertex getRotationPoint(const LDObjectList& objs) const; + +private: + void rotateVertex(Vertex& vertex, const Vertex& rotationPoint, const Matrix& transformationMatrix) const; +}; +
--- a/src/toolsets/algorithmtoolset.cpp Wed Feb 17 00:43:17 2016 +0200 +++ b/src/toolsets/algorithmtoolset.cpp Wed Feb 17 00:47:48 2016 +0200 @@ -30,7 +30,7 @@ #include "../glRenderer.h" #include "../dialogs.h" #include "../colors.h" -#include "../ldObjectMath.h" +#include "../mathfunctions.h" #include "../ldobjectiterator.h" #include "../documentmanager.h" #include "ui_replcoords.h"
--- a/src/toolsets/movetoolset.cpp Wed Feb 17 00:43:17 2016 +0200 +++ b/src/toolsets/movetoolset.cpp Wed Feb 17 00:47:48 2016 +0200 @@ -17,7 +17,7 @@ */ #include "../ldDocument.h" -#include "../ldObjectMath.h" +#include "../mathfunctions.h" #include "../miscallenous.h" #include "../mainwindow.h" #include "movetoolset.h"