Nicolas Winkler %!s(int64=4) %!d(string=hai) anos
pai
achega
82994d0681
Modificáronse 8 ficheiros con 54 adicións e 9 borrados
  1. 15 3
      EscapeTimeVisualWidget.cpp
  2. 1 1
      EscapeTimeVisualWidget.h
  3. 4 1
      FractalWidget.cpp
  4. 9 3
      GradientMenu.cpp
  5. 2 0
      GradientMenu.h
  6. 12 1
      GradientMenu.ui
  7. 10 0
      GradientWidget.cpp
  8. 1 0
      GradientWidget.h

+ 15 - 3
EscapeTimeVisualWidget.cpp

@@ -230,6 +230,7 @@ void EscapeTimeVisualWidget::initializeGL(void)
     "varying highp vec2 texc;\n"
     "uniform highp float juliaX;\n"
     "uniform highp float juliaY;\n"
+    "uniform int smooth;\n"
     "const highp float left = -1.5;\n"
     "const highp float right = 1.5;\n"
     "const highp float top = -1.5;\n"
@@ -250,7 +251,11 @@ void EscapeTimeVisualWidget::initializeGL(void)
     "        if (aa + bb >= 16.0) break;\n"
     "        k = k + 1;\n"
     "    }\n"
-    "    return float(k) + 1.0 - log2(log(a * a + b * b) * 0.5);\n"
+//    "    if (smooth != 0) {\n"
+    "        return float(k) + 1.0 - log2(log(a * a + b * b) * 0.5);\n"
+//    "    } else {\n"
+//    "        return float(k);\n"
+//    "    }\n"
     "}\n"
     "void main(void)\n"
     "{\n"
@@ -263,7 +268,7 @@ void EscapeTimeVisualWidget::initializeGL(void)
     "        highp float vnorm = v * gradientScaler;\n"
     "        gl_FragColor = texture2D(gradient, vec2(vnorm, 0.0));\n"
     "    }\n"
-    //"    gl_FragColor = vec4(vnorm, 0.0, 0.0, 0.0);\n"
+    "    gl_FragColor.g = 0.3;\n"
     "}");
     juliaPreviewer->link();
 
@@ -435,7 +440,7 @@ void EscapeTimeVisualWidget::paintGL(void)
 }
 
 
-void EscapeTimeVisualWidget::drawJulia(float jx, float jy, QRectF area)
+void EscapeTimeVisualWidget::drawJulia(float jx, float jy, QRectF area, bool drawSmooth)
 {
     juliaPreviewer->bind();
     int gradLoc = juliaPreviewer->uniformLocation("gradient");
@@ -445,6 +450,12 @@ void EscapeTimeVisualWidget::drawJulia(float jx, float jy, QRectF area)
     int vertexLoc = juliaPreviewer->attributeLocation("vertex");
     int texCoordsLoc = juliaPreviewer->attributeLocation("texCoord");
     int maxIterLoc = juliaPreviewer->attributeLocation("maxIterations");
+    int smooth = juliaPreviewer->uniformLocation("smooth");
+    int matrixLocation = juliaPreviewer->uniformLocation("matrix");
+
+    QMatrix4x4 pmvMatrix;
+    pmvMatrix.ortho(QRect{ 0, 0, getResolutionX(), getResolutionY() });
+    juliaPreviewer->setUniformValue(matrixLocation, pmvMatrix);
 
     const float x = area.x();
     const float y = area.y();
@@ -475,6 +486,7 @@ void EscapeTimeVisualWidget::drawJulia(float jx, float jy, QRectF area)
     juliaPreviewer->setUniformValue(maxIterLoc, float(250));
     juliaPreviewer->setUniformValue(juliaX, float(jx));
     juliaPreviewer->setUniformValue(juliaY, float(jy));
+    juliaPreviewer->setUniformValue(smooth, int(drawSmooth ? 1 : 0));
 
     gl.glUniform1i(gradLoc, 0);
 

+ 1 - 1
EscapeTimeVisualWidget.h

@@ -56,7 +56,7 @@ public:
     virtual void initializeGL(void) override;
     virtual void resizeGL(int w, int h) override;
     virtual void paintGL(void) override;
-    void drawJulia(float jx, float jy, QRectF area);
+    void drawJulia(float jx, float jy, QRectF area, bool drawSmooth);
 
     void setMaxIterationCutoff(float maxIter);
 

+ 4 - 1
FractalWidget.cpp

@@ -206,12 +206,15 @@ void FractalWidget::paintGL(void)
         float minRes = getResolutionX();
         if (getResolutionY() < minRes)
             minRes = getResolutionY();
+        float offset = minRes * 0.1;
+        if (offset < 30)
+            offset = 30;
         QRectF area{
             60, 60,
             minRes * 0.3, minRes * 0.3
         };
 
-        EscapeTimeVisualWidget::drawJulia(jx, jy, area);
+        EscapeTimeVisualWidget::drawJulia(jx, jy, area, mandelInfo.smooth);
 
         QPainter framePainter{ this };
         QPen pen{ QColor{ 255, 255, 255 } };

+ 9 - 3
GradientMenu.cpp

@@ -6,12 +6,13 @@ GradientMenu::GradientMenu(QWidget *parent) :
     ui(new Ui::GradientMenu)
 {
     ui->setupUi(this);
-    ui->gradientWidget->setGradient(
+    ui->gradientWidget->setGradient({
         std::vector<std::pair<RGBColor, float>> {
             { RGBColor{ 10, 200, 20 }, 0.1 },
             { RGBColor{ 100, 20, 120 }, 0.7 }
-        }
-    );
+        },
+        1.0f
+    });
     connect(ui->gradientWidget, &GradientWidget::gradientChanged, this, &GradientMenu::gradientChanged);
 }
 
@@ -39,3 +40,8 @@ void GradientMenu::setGradient(Gradient grad)
     before = grad;
     ui->gradientWidget->setGradient(std::move(grad));
 }
+
+void GradientMenu::on_removeBtn_clicked()
+{
+    ui->gradientWidget->removeSelectedHandle();
+}

+ 2 - 0
GradientMenu.h

@@ -27,6 +27,8 @@ public:
 
 signals:
     void gradientChanged(void);
+private slots:
+    void on_removeBtn_clicked();
 };
 
 #endif // GRADIENTMENU_H

+ 12 - 1
GradientMenu.ui

@@ -13,7 +13,7 @@
   <property name="windowTitle">
    <string>Select Gradient</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
+  <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
    <property name="leftMargin">
     <number>0</number>
    </property>
@@ -43,6 +43,17 @@
    <item>
     <widget class="GradientWidget" name="gradientWidget" native="true"/>
    </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QPushButton" name="removeBtn">
+       <property name="text">
+        <string>Remove</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
   </layout>
  </widget>
  <customwidgets>

+ 10 - 0
GradientWidget.cpp

@@ -368,6 +368,16 @@ void GradientWidget::selectedColorChanged(const QColor& newColor)
 }
 
 
+void GradientWidget::removeSelectedHandle(void)
+{
+    if (selectedHandle >= 0 && selectedHandle < points.size()) {
+        points.erase(points.begin() + selectedHandle);
+        selectedHandle = -1;
+        updateGradient();
+    }
+}
+
+
 QRect GradientWidget::getGradientRect(void) const
 {
     QMargins cm = contentsMargins();

+ 1 - 0
GradientWidget.h

@@ -67,6 +67,7 @@ public:
 
 public slots:
     void selectedColorChanged(const QColor& newColor);
+    void removeSelectedHandle(void);
 
 protected:
     /// \brief the area in which the gradient is displayed