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
|
||||
|
||||
#include "Camera.h"
|
||||
#include "ViewportWidget.h"
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
#include <QApplication>
|
||||
#include <QWheelEvent>
|
||||
#include <QPropertyAnimation>
|
||||
@@ -202,25 +203,28 @@ void Camera::restoreState()
|
||||
setZoom(m_savedZoom);
|
||||
}
|
||||
|
||||
void Camera::animateToPlaneView(int plane)
|
||||
void Camera::animateToPlaneView(const gp_Ax2& plane)
|
||||
{
|
||||
float targetXRot = xRotation();
|
||||
float targetYRot = yRotation();
|
||||
switch (static_cast<ViewportWidget::SketchPlane>(plane)) {
|
||||
case ViewportWidget::SketchPlane::XY: // Top view
|
||||
targetXRot = 90 * 16;
|
||||
targetYRot = 0;
|
||||
break;
|
||||
case ViewportWidget::SketchPlane::XZ: // Front view
|
||||
targetXRot = 0;
|
||||
targetYRot = 0;
|
||||
break;
|
||||
case ViewportWidget::SketchPlane::YZ: // Right view
|
||||
targetXRot = 0;
|
||||
targetYRot = -90 * 16;
|
||||
break;
|
||||
case ViewportWidget::SketchPlane::NONE:
|
||||
break;
|
||||
const auto& normal = plane.Direction();
|
||||
QVector3D n(normal.X(), normal.Y(), normal.Z());
|
||||
QVector3D d;
|
||||
|
||||
// This logic preserves the quirky view directions of the original implementation.
|
||||
// For XZ-like planes (normal is mostly along Y), the view is aligned WITH the plane normal.
|
||||
// For other planes, it's aligned AGAINST the normal.
|
||||
if (qAbs(n.y()) > 0.99) {
|
||||
d = n;
|
||||
} else {
|
||||
d = -n;
|
||||
}
|
||||
|
||||
float targetXRot = qRadiansToDegrees(asin(-d.z())) * 16.0f;
|
||||
float targetYRot;
|
||||
|
||||
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);
|
||||
|
||||
+3
-1
@@ -14,6 +14,8 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include <gp_Ax2.hxx>
|
||||
|
||||
class Camera : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -46,7 +48,7 @@ public:
|
||||
void saveState();
|
||||
void restoreState();
|
||||
|
||||
void animateToPlaneView(int plane);
|
||||
void animateToPlaneView(const gp_Ax2& plane);
|
||||
void animateRestoreState();
|
||||
void animateToHomeView();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user