fixed view ratio

master
Benjamin Kraft 3 years ago
parent 788171e862
commit 6ed75b5c88
  1. 9
      headers/Mandelbrot.h
  2. 13
      src/Mandelbrot.cpp
  3. 1
      src/OutputWidget.cpp

@ -15,17 +15,20 @@ public:
void zoomRelative(int, QVector2D); void zoomRelative(int, QVector2D);
void resizeRelative(QVector2D); void resizeRelative(QVector2D);
bool initShader(); bool initShader();
void initView(QSize);
public slots: public slots:
void toggleAnimation(); void toggleAnimation();
void toggleNormalize(); void toggleNormalize();
private: private:
const QVector2D startCenter {-0.66, 0};
const float startMaxSize = 3;
int maxIterations = 0; int maxIterations = 0;
float hueAdd = 0; float hueAdd = 0;
QVector2D origin {-2, -1}; QVector2D origin;
QVector2D size {2, 2}; QVector2D size;
float zoomModifier = 1.05; float zoomModifier = 1.05;
bool normalize = true; bool normalize = true;
bool animating = true; bool animating = true;
GLuint vao; GLuint vao;

@ -70,6 +70,19 @@ void Mandelbrot::toggleNormalize() {
normalize = !normalize; normalize = !normalize;
} }
void Mandelbrot::initView(QSize startSize) {
int viewW = startSize.width();
int viewH = startSize.height();
float ratio = float(viewW) / float(viewH);
if (ratio > 1){
size = {startMaxSize, startMaxSize / ratio};
} else {
size = {startMaxSize * ratio, startMaxSize};
}
origin = startCenter - size / 2;
}

@ -82,6 +82,7 @@ void OutputWidget::resizeGL(int w, int h) {
QSize newSize = QSize(w, h); QSize newSize = QSize(w, h);
if (oldSize == QSize(0, 0)){ if (oldSize == QSize(0, 0)){
oldSize = newSize; oldSize = newSize;
getMandelbrot().initView(newSize);
return; return;
} }
QSize diff = oldSize - newSize; QSize diff = oldSize - newSize;

Loading…
Cancel
Save