feat: Implement middle-mouse rotation around grid intersection with visual pivot
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -88,8 +88,15 @@ QMatrix4x4 Camera::modelViewMatrix() const
|
||||
{
|
||||
QMatrix4x4 model;
|
||||
model.translate(m_panX, m_panY, m_zoom);
|
||||
|
||||
if (m_isRotating) {
|
||||
model.translate(m_rotationPivot);
|
||||
}
|
||||
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);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -217,6 +224,44 @@ void Camera::animateToPlaneView(int plane)
|
||||
animGroup->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void Camera::startRotation(const QVector3D& pivot)
|
||||
{
|
||||
m_rotationPivot = pivot;
|
||||
|
||||
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;
|
||||
|
||||
setPanX(m_panX + p_diff.x());
|
||||
setPanY(m_panY + p_diff.y());
|
||||
setZoom(m_zoom + p_diff.z());
|
||||
|
||||
m_isRotating = true;
|
||||
}
|
||||
|
||||
void Camera::stopRotation()
|
||||
{
|
||||
if (!m_isRotating) {
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
setPanX(m_panX - p_diff.x());
|
||||
setPanY(m_panY - p_diff.y());
|
||||
setZoom(m_zoom - p_diff.z());
|
||||
|
||||
m_isRotating = false;
|
||||
}
|
||||
|
||||
void Camera::animateRestoreState()
|
||||
{
|
||||
auto* animGroup = new QParallelAnimationGroup(this);
|
||||
|
||||
Reference in New Issue
Block a user