Add group rotation
parent
8773ddd7ef
commit
8c37bc06dc
|
@ -1,11 +1,12 @@
|
||||||
#include "modelwidget.h"
|
|
||||||
#include "ds3file.h"
|
|
||||||
#include "skeletongraphicswidget.h"
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include "modelwidget.h"
|
||||||
|
#include "ds3file.h"
|
||||||
|
#include "skeletongraphicswidget.h"
|
||||||
|
#include "modelwidget.h"
|
||||||
|
|
||||||
// Modifed from http://doc.qt.io/qt-5/qtopengl-hellogl2-glwidget-cpp.html
|
// Modifed from http://doc.qt.io/qt-5/qtopengl-hellogl2-glwidget-cpp.html
|
||||||
|
|
||||||
|
@ -63,14 +64,6 @@ ModelWidget::~ModelWidget()
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qNormalizeAngle(int &angle)
|
|
||||||
{
|
|
||||||
while (angle < 0)
|
|
||||||
angle += 360 * 16;
|
|
||||||
while (angle > 360 * 16)
|
|
||||||
angle -= 360 * 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelWidget::setXRotation(int angle)
|
void ModelWidget::setXRotation(int angle)
|
||||||
{
|
{
|
||||||
qNormalizeAngle(angle);
|
qNormalizeAngle(angle);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QMatrix4x4>
|
||||||
#include "skeletongraphicswidget.h"
|
#include "skeletongraphicswidget.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -29,7 +30,8 @@ SkeletonGraphicsWidget::SkeletonGraphicsWidget(const SkeletonDocument *document)
|
||||||
m_lastAddedZ(0),
|
m_lastAddedZ(0),
|
||||||
m_selectionItem(nullptr),
|
m_selectionItem(nullptr),
|
||||||
m_rangeSelectionStarted(false),
|
m_rangeSelectionStarted(false),
|
||||||
m_mouseEventFromSelf(false)
|
m_mouseEventFromSelf(false),
|
||||||
|
m_lastRot(0)
|
||||||
{
|
{
|
||||||
setRenderHint(QPainter::Antialiasing, false);
|
setRenderHint(QPainter::Antialiasing, false);
|
||||||
setBackgroundBrush(QBrush(QWidget::palette().color(QWidget::backgroundRole()), Qt::SolidPattern));
|
setBackgroundBrush(QBrush(QWidget::palette().color(QWidget::backgroundRole()), Qt::SolidPattern));
|
||||||
|
@ -485,12 +487,36 @@ bool SkeletonGraphicsWidget::mouseMove(QMouseEvent *event)
|
||||||
float byY = sceneRadiusToUnified(mouseScenePos.y() - m_lastScenePos.y());
|
float byY = sceneRadiusToUnified(mouseScenePos.y() - m_lastScenePos.y());
|
||||||
std::set<SkeletonGraphicsNodeItem *> nodeItems;
|
std::set<SkeletonGraphicsNodeItem *> nodeItems;
|
||||||
readMergedSkeletonNodeSetFromRangeSelection(&nodeItems);
|
readMergedSkeletonNodeSetFromRangeSelection(&nodeItems);
|
||||||
for (const auto &it: nodeItems) {
|
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
|
||||||
SkeletonGraphicsNodeItem *nodeItem = it;
|
QVector2D center = centerOfNodeItemSet(nodeItems);
|
||||||
if (SkeletonProfile::Main == nodeItem->profile()) {
|
int degreeX = (mouseScenePos.x() - m_lastScenePos.x());
|
||||||
emit moveNodeBy(nodeItem->id(), byX, byY, 0);
|
qNormalizeAngle(degreeX);
|
||||||
} else {
|
for (const auto &it: nodeItems) {
|
||||||
emit moveNodeBy(nodeItem->id(), 0, byY, byX);
|
SkeletonGraphicsNodeItem *nodeItem = it;
|
||||||
|
QMatrix4x4 mat;
|
||||||
|
QVector3D centerPoint(center.x(), center.y(), 0);
|
||||||
|
QPointF nodeOrigin = nodeItem->origin();
|
||||||
|
QVector3D nodeOriginPoint(nodeOrigin.x(), nodeOrigin.y(), 0);
|
||||||
|
QVector3D p = nodeOriginPoint - centerPoint;
|
||||||
|
mat.rotate(degreeX, 0, 0, 1);
|
||||||
|
p = mat * p;
|
||||||
|
QVector3D finalPoint = p + centerPoint;
|
||||||
|
byX = sceneRadiusToUnified(finalPoint.x() - nodeOrigin.x());
|
||||||
|
byY = sceneRadiusToUnified(finalPoint.y() - nodeOrigin.y());
|
||||||
|
if (SkeletonProfile::Main == nodeItem->profile()) {
|
||||||
|
emit moveNodeBy(nodeItem->id(), byX, byY, 0);
|
||||||
|
} else {
|
||||||
|
emit moveNodeBy(nodeItem->id(), 0, byY, byX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const auto &it: nodeItems) {
|
||||||
|
SkeletonGraphicsNodeItem *nodeItem = it;
|
||||||
|
if (SkeletonProfile::Main == nodeItem->profile()) {
|
||||||
|
emit moveNodeBy(nodeItem->id(), byX, byY, 0);
|
||||||
|
} else {
|
||||||
|
emit moveNodeBy(nodeItem->id(), 0, byY, byX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_lastScenePos = mouseScenePos;
|
m_lastScenePos = mouseScenePos;
|
||||||
|
@ -609,6 +635,7 @@ bool SkeletonGraphicsWidget::mouseRelease(QMouseEvent *event)
|
||||||
}
|
}
|
||||||
if (m_moveStarted) {
|
if (m_moveStarted) {
|
||||||
m_moveStarted = false;
|
m_moveStarted = false;
|
||||||
|
m_lastRot = 0;
|
||||||
if (m_moveHappened)
|
if (m_moveHappened)
|
||||||
emit groupOperationAdded();
|
emit groupOperationAdded();
|
||||||
}
|
}
|
||||||
|
|
|
@ -363,6 +363,7 @@ private:
|
||||||
std::set<QGraphicsItem *> m_rangeSelectionSet;
|
std::set<QGraphicsItem *> m_rangeSelectionSet;
|
||||||
bool m_mouseEventFromSelf;
|
bool m_mouseEventFromSelf;
|
||||||
bool m_moveHappened;
|
bool m_moveHappened;
|
||||||
|
int m_lastRot;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SkeletonGraphicsContainerWidget : public QWidget
|
class SkeletonGraphicsContainerWidget : public QWidget
|
||||||
|
|
|
@ -18,3 +18,12 @@ bool isFloatEqual(float a, float b)
|
||||||
{
|
{
|
||||||
return fabs(a - b) <= 0.000001;
|
return fabs(a - b) <= 0.000001;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void qNormalizeAngle(int &angle)
|
||||||
|
{
|
||||||
|
while (angle < 0)
|
||||||
|
angle += 360 * 16;
|
||||||
|
while (angle > 360 * 16)
|
||||||
|
angle -= 360 * 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,5 +11,6 @@
|
||||||
QString valueOfKeyInMapOrEmpty(const std::map<QString, QString> &map, const QString &key);
|
QString valueOfKeyInMapOrEmpty(const std::map<QString, QString> &map, const QString &key);
|
||||||
bool isTrueValueString(const QString &str);
|
bool isTrueValueString(const QString &str);
|
||||||
bool isFloatEqual(float a, float b);
|
bool isFloatEqual(float a, float b);
|
||||||
|
void qNormalizeAngle(int &angle);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue