Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions custom3dinputhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@ void Custom3DInputHandler::mouseMoveEvent(QMouseEvent *event, const QPoint &mous
float xRotRad = qDegreesToRadians(camera->xRotation()); // Yaw (horizontal orbit)
float yRotRad = qDegreesToRadians(camera->yRotation()); // Pitch (vertical tilt)

float cosX = qCos(xRotRad);
float sinX = qSin(xRotRad);
float cosY = qCos(yRotRad);
float sinY = qSin(yRotRad);

// Invert Y delta (flipped back so dragging down moves the scene down)
float invertedDeltaY = -delta.y();
// Right vector: horizontal, unaffected by pitch
QVector3D right(qCos(xRotRad), 0.0f, -qSin(xRotRad));

float dx = (-delta.x() * cosX - invertedDeltaY * sinX * cosY) * panScale;
float dy = (invertedDeltaY * sinY) * panScale;
float dz = (delta.x() * sinX - invertedDeltaY * cosX * cosY) * panScale;
// Forward vector: direction the camera is looking
QVector3D forward(qSin(xRotRad) * qCos(yRotRad),
-qSin(yRotRad),
qCos(xRotRad) * qCos(yRotRad));

target.setX(target.x() + dx);
target.setY(target.y() + dy);
target.setZ(target.z() + dz);
// True camera-up = right × forward, always orthogonal to both
QVector3D up = QVector3D::crossProduct(forward, right).normalized();

float dxScreen = -delta.x() * panScale;
float dyScreen = delta.y() * panScale * 2;

target += right * dxScreen + up * dyScreen;
camera->setTarget(target);
}
event->accept();
Expand Down
Loading