Fix rotation values flipping between +/- angles

This commit is contained in:
manongjohn 2021-11-19 09:28:38 -05:00
parent 2b2f15ccca
commit 84b984c4e6

View file

@ -1019,11 +1019,18 @@ void PerspectiveTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
double dox = rotationPos.x - centerPoint.x;
double doy = rotationPos.y - centerPoint.y;
double oangle = std::atan2(doy, dox) / (3.14159 / 180);
if (oangle < 0) oangle += 360;
double dnx = newRotationPos.x - centerPoint.x;
double dny = newRotationPos.y - centerPoint.y;
double nangle = std::atan2(dny, dnx) / (3.14159 / 180);
if (nangle < 0) nangle += 360;
if ((oangle >= 270 && oangle <= 360 && nangle >= 0 && nangle <= 90))
dAngle = (360 - oangle) + nangle;
else if ((oangle >= 0 && oangle <= 90 && nangle >= 270 && nangle <= 360))
dAngle = (oangle + (360 - nangle)) * -1;
else
dAngle = nangle - oangle;
} else if (m_isSpacing) {
TPointD newSpacingPos = spacingPos + dPos;
@ -1066,6 +1073,7 @@ void PerspectiveTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
TPointD rightHandlePos = mainObj->getRightHandlePos();
if (m_isLeftMoving) {
TPointD oldCenterPoint = centerPoint;
TPointD newPos = leftHandlePos + dPos;
mainObj->setLeftHandlePos(newPos);
@ -1094,12 +1102,26 @@ void PerspectiveTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
updateMeasuredValueToolOptions();
} else {
// Recalculate Angle
double dx = rotationPos.x - newCenterPoint.x;
double dy = rotationPos.y - newCenterPoint.y;
double newAngle = std::atan2(dy, dx) / (3.14159 / 180);
if (mainObj->getType() == PerspectiveType::VanishingPoint)
newAngle += 90;
mainObj->setRotation(newAngle);
double dox = rotationPos.x - oldCenterPoint.x;
double doy = rotationPos.y - oldCenterPoint.y;
double oangle = std::atan2(doy, dox) / (3.14159 / 180);
if (oangle < 0) oangle += 360;
double dnx = rotationPos.x - newCenterPoint.x;
double dny = rotationPos.y - newCenterPoint.y;
double nangle = std::atan2(dny, dnx) / (3.14159 / 180);
if (nangle < 0) nangle += 360;
double dAngle;
if ((oangle >= 270 && oangle <= 360 && nangle >= 0 && nangle <= 90))
dAngle = (360 - oangle) + nangle;
else if ((oangle >= 0 && oangle <= 90 && nangle >= 270 &&
nangle <= 360))
dAngle = (oangle + (360 - nangle)) * -1;
else
dAngle = nangle - oangle;
mainObj->setRotation(mainObj->getRotation() + dAngle);
// Recalculate Spacing
double newSpacing =
@ -1116,6 +1138,7 @@ void PerspectiveTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
applyToSelection = false;
} else if (m_isRightMoving) {
TPointD oldCenterPoint = centerPoint;
TPointD newPos = rightHandlePos + dPos;
mainObj->setRightHandlePos(newPos);
@ -1143,12 +1166,26 @@ void PerspectiveTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
updateMeasuredValueToolOptions();
} else {
// Recalculate Angle
double dx = rotationPos.x - newCenterPoint.x;
double dy = rotationPos.y - newCenterPoint.y;
double newAngle = std::atan2(dy, dx) / (3.14159 / 180);
if (mainObj->getType() == PerspectiveType::VanishingPoint)
newAngle += 90;
mainObj->setRotation(newAngle);
double dox = rotationPos.x - oldCenterPoint.x;
double doy = rotationPos.y - oldCenterPoint.y;
double oangle = std::atan2(doy, dox) / (3.14159 / 180);
if (oangle < 0) oangle += 360;
double dnx = rotationPos.x - newCenterPoint.x;
double dny = rotationPos.y - newCenterPoint.y;
double nangle = std::atan2(dny, dnx) / (3.14159 / 180);
if (nangle < 0) nangle += 360;
double dAngle;
if ((oangle >= 270 && oangle <= 360 && nangle >= 0 && nangle <= 90))
dAngle = (360 - oangle) + nangle;
else if ((oangle >= 0 && oangle <= 90 && nangle >= 270 &&
nangle <= 360))
dAngle = (oangle + (360 - nangle)) * -1;
else
dAngle = nangle - oangle;
mainObj->setRotation(mainObj->getRotation() + dAngle);
// Recalculate Spacing
double newSpacing =
@ -1216,11 +1253,26 @@ void PerspectiveTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
obj->setCenterPoint(newCenterPoint);
// Recalculate Angle
double dx = rotationPos.x - newCenterPoint.x;
double dy = rotationPos.y - newCenterPoint.y;
double newAngle = std::atan2(dy, dx) / (3.14159 / 180);
if (obj->getType() == PerspectiveType::VanishingPoint) newAngle += 90;
obj->setRotation(newAngle);
double dox = rotationPos.x - objCenterPoint.x;
double doy = rotationPos.y - objCenterPoint.y;
double oangle = std::atan2(doy, dox) / (3.14159 / 180);
if (oangle < 0) oangle += 360;
double dnx = rotationPos.x - newCenterPoint.x;
double dny = rotationPos.y - newCenterPoint.y;
double nangle = std::atan2(dny, dnx) / (3.14159 / 180);
if (nangle < 0) nangle += 360;
double dAngle;
if ((oangle >= 270 && oangle <= 360 && nangle >= 0 && nangle <= 90))
dAngle = (360 - oangle) + nangle;
else if ((oangle >= 0 && oangle <= 90 && nangle >= 270 &&
nangle <= 360))
dAngle = (oangle + (360 - nangle)) * -1;
else
dAngle = nangle - oangle;
obj->setRotation(obj->getRotation() + dAngle);
// Recalculate Spacing
double newSpacing =