Fix: Apply consistent Z-up to Y-up transformations for camera
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -67,6 +67,7 @@ void Camera::wheelEvent(QWheelEvent* event, const QVector3D& worldPos)
|
||||
QMatrix4x4 rotation;
|
||||
rotation.rotate(m_xRot / 16.0f, 1, 0, 0);
|
||||
rotation.rotate(m_yRot / 16.0f, 0, 1, 0);
|
||||
rotation.rotate(-90.0f, 1, 0, 0);
|
||||
QVector3D p_camera = rotation.map(worldPos);
|
||||
|
||||
if (std::abs(p_camera.z() + oldZoom) < 1e-6) {
|
||||
@@ -90,13 +91,17 @@ QMatrix4x4 Camera::modelViewMatrix() const
|
||||
QMatrix4x4 model;
|
||||
model.translate(m_panX, m_panY, m_zoom);
|
||||
|
||||
QMatrix4x4 zup_rotation;
|
||||
zup_rotation.rotate(-90.0f, 1, 0, 0);
|
||||
QVector3D pivot_yup = zup_rotation.map(m_rotationPivot);
|
||||
|
||||
if (m_isRotating) {
|
||||
model.translate(m_rotationPivot);
|
||||
model.translate(pivot_yup);
|
||||
}
|
||||
model.rotate(m_xRot / 16.0f, 1, 0, 0);
|
||||
model.rotate(m_yRot / 16.0f, 0, 1, 0);
|
||||
if (m_isRotating) {
|
||||
model.translate(-m_rotationPivot);
|
||||
model.translate(-pivot_yup);
|
||||
}
|
||||
|
||||
model.rotate(-90.0f, 1, 0, 0); // For Z-up system
|
||||
@@ -343,12 +348,16 @@ void Camera::startRotation(const QVector3D& pivot)
|
||||
}
|
||||
m_stableZoom = m_zoom;
|
||||
|
||||
QMatrix4x4 zup_rotation;
|
||||
zup_rotation.rotate(-90.0f, 1, 0, 0);
|
||||
QVector3D pivot_yup = zup_rotation.map(m_rotationPivot);
|
||||
|
||||
QMatrix4x4 rotation;
|
||||
rotation.rotate(m_xRot / 16.0f, 1, 0, 0);
|
||||
rotation.rotate(m_yRot / 16.0f, 0, 1, 0);
|
||||
|
||||
QVector3D p_rotated = rotation.map(m_rotationPivot);
|
||||
QVector3D p_diff = p_rotated - m_rotationPivot;
|
||||
QVector3D p_rotated = rotation.map(pivot_yup);
|
||||
QVector3D p_diff = p_rotated - pivot_yup;
|
||||
|
||||
setPanX(m_panX + p_diff.x());
|
||||
setPanY(m_panY + p_diff.y());
|
||||
@@ -363,12 +372,16 @@ void Camera::stopRotation()
|
||||
return;
|
||||
}
|
||||
|
||||
QMatrix4x4 zup_rotation;
|
||||
zup_rotation.rotate(-90.0f, 1, 0, 0);
|
||||
QVector3D pivot_yup = zup_rotation.map(m_rotationPivot);
|
||||
|
||||
QMatrix4x4 rotation;
|
||||
rotation.rotate(m_xRot / 16.0f, 1, 0, 0);
|
||||
rotation.rotate(m_yRot / 16.0f, 0, 1, 0);
|
||||
|
||||
QVector3D p_rotated = rotation.map(m_rotationPivot);
|
||||
QVector3D p_diff = p_rotated - m_rotationPivot;
|
||||
QVector3D p_rotated = rotation.map(pivot_yup);
|
||||
QVector3D p_diff = p_rotated - pivot_yup;
|
||||
|
||||
setPanX(m_panX - p_diff.x());
|
||||
setPanY(m_panY - p_diff.y());
|
||||
|
||||
Reference in New Issue
Block a user