fix: Calculate shortest path for camera rotations
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -211,17 +211,37 @@ void Camera::animateToPlaneView(int plane)
|
|||||||
|
|
||||||
auto* animGroup = new QParallelAnimationGroup(this);
|
auto* animGroup = new QParallelAnimationGroup(this);
|
||||||
|
|
||||||
|
const float full_circle = 360.0f * 16.0f;
|
||||||
|
|
||||||
|
float currentXRot = xRotation();
|
||||||
|
float diffX = targetXRot - currentXRot;
|
||||||
|
diffX = fmod(diffX, full_circle);
|
||||||
|
if (diffX > full_circle / 2.0f) {
|
||||||
|
diffX -= full_circle;
|
||||||
|
} else if (diffX < -full_circle / 2.0f) {
|
||||||
|
diffX += full_circle;
|
||||||
|
}
|
||||||
|
|
||||||
auto* xRotAnim = new QPropertyAnimation(this, "xRotation");
|
auto* xRotAnim = new QPropertyAnimation(this, "xRotation");
|
||||||
xRotAnim->setDuration(300);
|
xRotAnim->setDuration(300);
|
||||||
xRotAnim->setStartValue(xRotation());
|
xRotAnim->setStartValue(currentXRot);
|
||||||
xRotAnim->setEndValue(targetXRot);
|
xRotAnim->setEndValue(currentXRot + diffX);
|
||||||
xRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
xRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||||
animGroup->addAnimation(xRotAnim);
|
animGroup->addAnimation(xRotAnim);
|
||||||
|
|
||||||
|
float currentYRot = yRotation();
|
||||||
|
float diffY = targetYRot - currentYRot;
|
||||||
|
diffY = fmod(diffY, full_circle);
|
||||||
|
if (diffY > full_circle / 2.0f) {
|
||||||
|
diffY -= full_circle;
|
||||||
|
} else if (diffY < -full_circle / 2.0f) {
|
||||||
|
diffY += full_circle;
|
||||||
|
}
|
||||||
|
|
||||||
auto* yRotAnim = new QPropertyAnimation(this, "yRotation");
|
auto* yRotAnim = new QPropertyAnimation(this, "yRotation");
|
||||||
yRotAnim->setDuration(300);
|
yRotAnim->setDuration(300);
|
||||||
yRotAnim->setStartValue(yRotation());
|
yRotAnim->setStartValue(currentYRot);
|
||||||
yRotAnim->setEndValue(targetYRot);
|
yRotAnim->setEndValue(currentYRot + diffY);
|
||||||
yRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
yRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||||
animGroup->addAnimation(yRotAnim);
|
animGroup->addAnimation(yRotAnim);
|
||||||
|
|
||||||
@@ -295,17 +315,39 @@ void Camera::animateRestoreState()
|
|||||||
{
|
{
|
||||||
auto* animGroup = new QParallelAnimationGroup(this);
|
auto* animGroup = new QParallelAnimationGroup(this);
|
||||||
|
|
||||||
|
const float full_circle = 360.0f * 16.0f;
|
||||||
|
|
||||||
|
float currentXRot = xRotation();
|
||||||
|
float targetXRot = savedXRot();
|
||||||
|
float diffX = targetXRot - currentXRot;
|
||||||
|
diffX = fmod(diffX, full_circle);
|
||||||
|
if (diffX > full_circle / 2.0f) {
|
||||||
|
diffX -= full_circle;
|
||||||
|
} else if (diffX < -full_circle / 2.0f) {
|
||||||
|
diffX += full_circle;
|
||||||
|
}
|
||||||
|
|
||||||
auto* xRotAnim = new QPropertyAnimation(this, "xRotation");
|
auto* xRotAnim = new QPropertyAnimation(this, "xRotation");
|
||||||
xRotAnim->setDuration(300);
|
xRotAnim->setDuration(300);
|
||||||
xRotAnim->setStartValue(xRotation());
|
xRotAnim->setStartValue(currentXRot);
|
||||||
xRotAnim->setEndValue(savedXRot());
|
xRotAnim->setEndValue(currentXRot + diffX);
|
||||||
xRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
xRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||||
animGroup->addAnimation(xRotAnim);
|
animGroup->addAnimation(xRotAnim);
|
||||||
|
|
||||||
|
float currentYRot = yRotation();
|
||||||
|
float targetYRot = savedYRot();
|
||||||
|
float diffY = targetYRot - currentYRot;
|
||||||
|
diffY = fmod(diffY, full_circle);
|
||||||
|
if (diffY > full_circle / 2.0f) {
|
||||||
|
diffY -= full_circle;
|
||||||
|
} else if (diffY < -full_circle / 2.0f) {
|
||||||
|
diffY += full_circle;
|
||||||
|
}
|
||||||
|
|
||||||
auto* yRotAnim = new QPropertyAnimation(this, "yRotation");
|
auto* yRotAnim = new QPropertyAnimation(this, "yRotation");
|
||||||
yRotAnim->setDuration(300);
|
yRotAnim->setDuration(300);
|
||||||
yRotAnim->setStartValue(yRotation());
|
yRotAnim->setStartValue(currentYRot);
|
||||||
yRotAnim->setEndValue(savedYRot());
|
yRotAnim->setEndValue(currentYRot + diffY);
|
||||||
yRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
yRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||||
animGroup->addAnimation(yRotAnim);
|
animGroup->addAnimation(yRotAnim);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user