added zoom modifier

master
Benjamin Kraft 3 years ago
parent 4d8b82eeee
commit 5a50a0cdfe
  1. 3
      headers/Mandelbrot.h
  2. 3
      src/Mandelbrot.cpp
  3. 8
      src/OutputWidget.cpp

@ -11,11 +11,12 @@ public:
void draw(GLuint, QOpenGLShaderProgram&); void draw(GLuint, QOpenGLShaderProgram&);
void setIterations(int); void setIterations(int);
void translateRelative(QVector2D); void translateRelative(QVector2D);
void zoomRelative(float, QVector2D); void zoomRelative(int, QVector2D);
private: private:
int iterations = 0; int iterations = 0;
QVector2D origin {-2, -1}; QVector2D origin {-2, -1};
QVector2D size {2, 2}; QVector2D size {2, 2};
float zoomModifier = 1.05;
void setShaderValues(QOpenGLShaderProgram&) const; void setShaderValues(QOpenGLShaderProgram&) const;
}; };

@ -19,7 +19,8 @@ void Mandelbrot::setShaderValues(QOpenGLShaderProgram &shader) const {
shader.setUniformValue("iterationCount", iterations); shader.setUniformValue("iterationCount", iterations);
} }
void Mandelbrot::zoomRelative(float delta, QVector2D posRelative) { void Mandelbrot::zoomRelative(int direction, QVector2D posRelative) {
float delta = direction < 0 ? zoomModifier : (1 / zoomModifier);
QVector2D newSize = size * delta; QVector2D newSize = size * delta;
QVector2D fixPos = origin + posRelative * size; QVector2D fixPos = origin + posRelative * size;
QVector2D newOrigin = fixPos - posRelative * newSize; QVector2D newOrigin = fixPos - posRelative * newSize;

@ -73,14 +73,10 @@ QVector2D relative(QPoint p, QSize s){
void OutputWidget::wheelEvent(QWheelEvent *e) { void OutputWidget::wheelEvent(QWheelEvent *e) {
QPoint pos = e->position().toPoint(); QPoint pos = e->position().toPoint();
float modifier = 1; int direction = e->angleDelta().y() > 0 ? 1 : -1;
if (e->angleDelta().y() > 0)
modifier /= 1.1;
else
modifier *= 1.1;
QVector2D relativePos = relative(pos, size()); QVector2D relativePos = relative(pos, size());
relativePos.setY(1 - relativePos.y()); relativePos.setY(1 - relativePos.y());
getMandelbrot()->zoomRelative(modifier, relativePos); getMandelbrot()->zoomRelative(direction, relativePos);
update(); update();
} }

Loading…
Cancel
Save