forked from qt-creator/qt-creator
QmlDesigner: Reset zoom when aligning view to camera
Resetting the zoom after aligning edit camera to scene camera avoids confusing behavior in some cases, primarily when the alignment is triggered from outside 3D view. Fixes: QDS-12348 Fixes: QDS-12350 Change-Id: Ic0c076ea3dff3f1be5f57e20c0dbbe6069867b51 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
@@ -138,7 +138,10 @@ Item {
|
|||||||
else
|
else
|
||||||
nodes = targetNodes
|
nodes = targetNodes
|
||||||
|
|
||||||
_lookAtPoint = _generalHelper.alignView(camera, nodes, _lookAtPoint);
|
var newLookAtAndZoom = _generalHelper.alignView(camera, nodes, _lookAtPoint,
|
||||||
|
_defaultCameraLookAtDistance);
|
||||||
|
_lookAtPoint = newLookAtAndZoom.toVector3d();
|
||||||
|
_zoomFactor = newLookAtAndZoom.w;
|
||||||
storeCameraState(0);
|
storeCameraState(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -494,12 +494,10 @@ void GeneralHelper::alignCameras(QQuick3DCamera *camera, const QVariant &nodes)
|
|||||||
// Aligns the camera to the first camera in nodes list.
|
// Aligns the camera to the first camera in nodes list.
|
||||||
// Aligning means taking the position and XY rotation from the source camera. Rest of the properties
|
// Aligning means taking the position and XY rotation from the source camera. Rest of the properties
|
||||||
// remain the same, as this is used to align edit cameras, which have fixed Z-rot, fov, and clips.
|
// remain the same, as this is used to align edit cameras, which have fixed Z-rot, fov, and clips.
|
||||||
// The new lookAt is set at same distance away as it was previously and scale isn't adjusted, so
|
// The camera zoom is reset to default.
|
||||||
// the zoom factor of the edit camera stays the same.
|
QVector4D GeneralHelper::alignView(QQuick3DCamera *camera, const QVariant &nodes,
|
||||||
QVector3D GeneralHelper::alignView(QQuick3DCamera *camera, const QVariant &nodes,
|
const QVector3D &lookAtPoint, float defaultLookAtDistance)
|
||||||
const QVector3D &lookAtPoint)
|
|
||||||
{
|
{
|
||||||
float lastDistance = (lookAtPoint - camera->position()).length();
|
|
||||||
const QVariantList varNodes = nodes.value<QVariantList>();
|
const QVariantList varNodes = nodes.value<QVariantList>();
|
||||||
QQuick3DCamera *cameraNode = nullptr;
|
QQuick3DCamera *cameraNode = nullptr;
|
||||||
for (const auto &varNode : varNodes) {
|
for (const auto &varNode : varNodes) {
|
||||||
@@ -509,15 +507,24 @@ QVector3D GeneralHelper::alignView(QQuick3DCamera *camera, const QVariant &nodes
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cameraNode) {
|
if (cameraNode) {
|
||||||
|
if (auto orthoCamera = qobject_cast<QQuick3DOrthographicCamera *>(camera)) {
|
||||||
|
orthoCamera->setHorizontalMagnification(1.f);
|
||||||
|
orthoCamera->setVerticalMagnification(1.f);
|
||||||
|
// Force update on transform just in case position and rotation didn't change
|
||||||
|
float x = orthoCamera->x();
|
||||||
|
orthoCamera->setX(x + 1.f);
|
||||||
|
orthoCamera->setX(x);
|
||||||
|
}
|
||||||
camera->setPosition(cameraNode->scenePosition());
|
camera->setPosition(cameraNode->scenePosition());
|
||||||
QVector3D newRotation = cameraNode->sceneRotation().toEulerAngles();
|
QVector3D newRotation = cameraNode->sceneRotation().toEulerAngles();
|
||||||
newRotation.setZ(0.f);
|
newRotation.setZ(0.f);
|
||||||
camera->setEulerRotation(newRotation);
|
camera->setEulerRotation(newRotation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector3D lookAt = camera->position() + camera->forward() * lastDistance;
|
QVector3D lookAt = camera->position() + camera->forward() * defaultLookAtDistance;
|
||||||
|
|
||||||
return lookAt;
|
return QVector4D(lookAt, 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneralHelper::fuzzyCompare(double a, double b)
|
bool GeneralHelper::fuzzyCompare(double a, double b)
|
||||||
|
@@ -74,8 +74,8 @@ public:
|
|||||||
QQuick3DViewport *viewPort,
|
QQuick3DViewport *viewPort,
|
||||||
float defaultLookAtDistance, bool closeUp);
|
float defaultLookAtDistance, bool closeUp);
|
||||||
Q_INVOKABLE void alignCameras(QQuick3DCamera *camera, const QVariant &nodes);
|
Q_INVOKABLE void alignCameras(QQuick3DCamera *camera, const QVariant &nodes);
|
||||||
Q_INVOKABLE QVector3D alignView(QQuick3DCamera *camera, const QVariant &nodes,
|
Q_INVOKABLE QVector4D alignView(QQuick3DCamera *camera, const QVariant &nodes,
|
||||||
const QVector3D &lookAtPoint);
|
const QVector3D &lookAtPoint, float defaultLookAtDistance);
|
||||||
Q_INVOKABLE bool fuzzyCompare(double a, double b);
|
Q_INVOKABLE bool fuzzyCompare(double a, double b);
|
||||||
Q_INVOKABLE void delayedPropertySet(QObject *obj, int delay, const QString &property,
|
Q_INVOKABLE void delayedPropertySet(QObject *obj, int delay, const QString &property,
|
||||||
const QVariant& value);
|
const QVariant& value);
|
||||||
|
Reference in New Issue
Block a user