mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-05-29 05:10:20 +02:00
add wheel support for zoom
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
dbeb987978
commit
c0525ebf4e
@ -57,9 +57,14 @@ void SkinOpenGLWidget::mouseMoveEvent(QMouseEvent* event)
|
|||||||
int dx = event->x() - m_mousePosition.x();
|
int dx = event->x() - m_mousePosition.x();
|
||||||
int dy = event->y() - m_mousePosition.y();
|
int dy = event->y() - m_mousePosition.y();
|
||||||
|
|
||||||
// Update rotation angles based on mouse movement
|
m_yaw += dx * 0.5f;
|
||||||
m_rotationX += dy;
|
m_pitch += dy * 0.5f;
|
||||||
m_rotationY += dx;
|
|
||||||
|
// Normalize yaw to keep it manageable
|
||||||
|
if (m_yaw > 360.0f)
|
||||||
|
m_yaw -= 360.0f;
|
||||||
|
else if (m_yaw < 0.0f)
|
||||||
|
m_yaw += 360.0f;
|
||||||
|
|
||||||
m_mousePosition = QVector2D(event->pos());
|
m_mousePosition = QVector2D(event->pos());
|
||||||
update(); // Trigger a repaint
|
update(); // Trigger a repaint
|
||||||
@ -149,9 +154,13 @@ void SkinOpenGLWidget::paintGL()
|
|||||||
renderBackground();
|
renderBackground();
|
||||||
// Calculate model view transformation
|
// Calculate model view transformation
|
||||||
QMatrix4x4 matrix;
|
QMatrix4x4 matrix;
|
||||||
matrix.translate(0.0, 6.0, -50.);
|
float yawRad = qDegreesToRadians(m_yaw);
|
||||||
matrix.rotate(m_rotationX, 1.0f, 0.0f, 0.0f);
|
float pitchRad = qDegreesToRadians(m_pitch);
|
||||||
matrix.rotate(m_rotationY, 0.0f, 1.0f, 0.0f);
|
matrix.lookAt(QVector3D( //
|
||||||
|
m_distance * cos(pitchRad) * cos(yawRad), //
|
||||||
|
m_distance * sin(pitchRad) - 8, //
|
||||||
|
m_distance * cos(pitchRad) * sin(yawRad)),
|
||||||
|
QVector3D(0, -8, 0), QVector3D(0, 1, 0));
|
||||||
|
|
||||||
// Set modelview-projection matrix
|
// Set modelview-projection matrix
|
||||||
m_program->setUniformValue("mvp_matrix", m_projection * matrix);
|
m_program->setUniformValue("mvp_matrix", m_projection * matrix);
|
||||||
@ -210,3 +219,12 @@ void SkinOpenGLWidget::renderBackground()
|
|||||||
m_backgroundTexture->release();
|
m_backgroundTexture->release();
|
||||||
glDepthMask(GL_TRUE); // Re-enable depth buffer writing
|
glDepthMask(GL_TRUE); // Re-enable depth buffer writing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SkinOpenGLWidget::wheelEvent(QWheelEvent* event)
|
||||||
|
{
|
||||||
|
// Adjust distance based on scroll
|
||||||
|
int delta = event->angleDelta().y(); // Positive for scroll up, negative for scroll down
|
||||||
|
m_distance -= delta * 0.01f; // Adjust sensitivity factor
|
||||||
|
m_distance = qMax(16., m_distance); // Clamp distance
|
||||||
|
update(); // Trigger a repaint
|
||||||
|
}
|
||||||
|
@ -42,6 +42,7 @@ class SkinOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions {
|
|||||||
void mousePressEvent(QMouseEvent* e) override;
|
void mousePressEvent(QMouseEvent* e) override;
|
||||||
void mouseReleaseEvent(QMouseEvent* e) override;
|
void mouseReleaseEvent(QMouseEvent* e) override;
|
||||||
void mouseMoveEvent(QMouseEvent* event) override;
|
void mouseMoveEvent(QMouseEvent* event) override;
|
||||||
|
void wheelEvent(QWheelEvent* event) override;
|
||||||
|
|
||||||
void initializeGL() override;
|
void initializeGL() override;
|
||||||
void resizeGL(int w, int h) override;
|
void resizeGL(int w, int h) override;
|
||||||
@ -61,7 +62,9 @@ class SkinOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions {
|
|||||||
QVector2D m_mousePosition;
|
QVector2D m_mousePosition;
|
||||||
|
|
||||||
bool m_isMousePressed = false;
|
bool m_isMousePressed = false;
|
||||||
int m_rotationX = 0, m_rotationY = 0;
|
float m_distance = 48;
|
||||||
|
float m_yaw = 90; // Horizontal rotation angle
|
||||||
|
float m_pitch = 0; // Vertical rotation angle
|
||||||
|
|
||||||
opengl::BoxGeometry* m_background = nullptr;
|
opengl::BoxGeometry* m_background = nullptr;
|
||||||
QOpenGLTexture* m_backgroundTexture = nullptr;
|
QOpenGLTexture* m_backgroundTexture = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user