refactor: Use gp_Ax2 for camera plane orientation
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
+23
-19
@@ -6,7 +6,8 @@
|
|||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
||||||
|
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "ViewportWidget.h"
|
#include <gp_Ax2.hxx>
|
||||||
|
#include <gp_Dir.hxx>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
@@ -202,25 +203,28 @@ void Camera::restoreState()
|
|||||||
setZoom(m_savedZoom);
|
setZoom(m_savedZoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::animateToPlaneView(int plane)
|
void Camera::animateToPlaneView(const gp_Ax2& plane)
|
||||||
{
|
{
|
||||||
float targetXRot = xRotation();
|
const auto& normal = plane.Direction();
|
||||||
float targetYRot = yRotation();
|
QVector3D n(normal.X(), normal.Y(), normal.Z());
|
||||||
switch (static_cast<ViewportWidget::SketchPlane>(plane)) {
|
QVector3D d;
|
||||||
case ViewportWidget::SketchPlane::XY: // Top view
|
|
||||||
targetXRot = 90 * 16;
|
// This logic preserves the quirky view directions of the original implementation.
|
||||||
targetYRot = 0;
|
// For XZ-like planes (normal is mostly along Y), the view is aligned WITH the plane normal.
|
||||||
break;
|
// For other planes, it's aligned AGAINST the normal.
|
||||||
case ViewportWidget::SketchPlane::XZ: // Front view
|
if (qAbs(n.y()) > 0.99) {
|
||||||
targetXRot = 0;
|
d = n;
|
||||||
targetYRot = 0;
|
} else {
|
||||||
break;
|
d = -n;
|
||||||
case ViewportWidget::SketchPlane::YZ: // Right view
|
}
|
||||||
targetXRot = 0;
|
|
||||||
targetYRot = -90 * 16;
|
float targetXRot = qRadiansToDegrees(asin(-d.z())) * 16.0f;
|
||||||
break;
|
float targetYRot;
|
||||||
case ViewportWidget::SketchPlane::NONE:
|
|
||||||
break;
|
if (qAbs(d.z()) > 0.9999) { // Top/bottom-like view, Y rotation is arbitrary
|
||||||
|
targetYRot = 0; // Set to 0 for stability
|
||||||
|
} else {
|
||||||
|
targetYRot = qRadiansToDegrees(atan2(d.x(), d.y())) * 16.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* animGroup = new QParallelAnimationGroup(this);
|
auto* animGroup = new QParallelAnimationGroup(this);
|
||||||
|
|||||||
+3
-1
@@ -14,6 +14,8 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
|
|
||||||
|
#include <gp_Ax2.hxx>
|
||||||
|
|
||||||
class Camera : public QObject
|
class Camera : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -46,7 +48,7 @@ public:
|
|||||||
void saveState();
|
void saveState();
|
||||||
void restoreState();
|
void restoreState();
|
||||||
|
|
||||||
void animateToPlaneView(int plane);
|
void animateToPlaneView(const gp_Ax2& plane);
|
||||||
void animateRestoreState();
|
void animateRestoreState();
|
||||||
void animateToHomeView();
|
void animateToHomeView();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user