From 051686899e00b3810399e8a247f04948b8f6e5db Mon Sep 17 00:00:00 2001
From: Wilrik de Loose <wilrik@wilrik.nl>
Date: Fri, 11 Jan 2008 00:56:41 +0000
Subject: 'leuke' 3d smoke history

---
 Smoke/Week 2.suo     | Bin 78336 -> 78848 bytes
 Smoke/flowvis.c      |  11 ++++++
 Smoke/flowvis.h      |   6 +++
 Smoke/gtk_colormap.c |   2 +-
 Smoke/gtk_flowvis.c  |  23 ++++++++++++
 Smoke/gtk_main.c     |   2 +-
 Smoke/renderer_gl.c  | 101 ++++++++++++++++++++++++++++++---------------------
 7 files changed, 101 insertions(+), 44 deletions(-)

diff --git a/Smoke/Week 2.suo b/Smoke/Week 2.suo
index 7c0de3f..d9d8c23 100644
Binary files a/Smoke/Week 2.suo and b/Smoke/Week 2.suo differ
diff --git a/Smoke/flowvis.c b/Smoke/flowvis.c
index 3c6d637..75a04dc 100644
--- a/Smoke/flowvis.c
+++ b/Smoke/flowvis.c
@@ -20,6 +20,7 @@ static int flowvis_num_colors = PALETTE_MAXCOLORS;
 static int flowvis_colormap = PALETTE_BLACKWHITE;
 
 static float flowvis_alpha = 1.0f;
+static float flowvis_sort = FLOWVIS_SORT_FRAME;
 
 static fftw_real *flowvis_frame;
 static fftw_real **flowvis_history;
@@ -89,6 +90,16 @@ fftw_real *flowvis_get_frame(void)
   return flowvis_frame;
 }
 
+void flowvis_set_sort(int sort)
+{
+  flowvis_sort = sort;
+}
+
+int flowvis_get_sort(void)
+{
+  return flowvis_sort;
+}
+
 void flowvis_set_history(fftw_real **history)
 {
   flowvis_history = history;
diff --git a/Smoke/flowvis.h b/Smoke/flowvis.h
index bf3b237..51751c6 100644
--- a/Smoke/flowvis.h
+++ b/Smoke/flowvis.h
@@ -1,6 +1,9 @@
 #ifndef _FLOWVIS_H
 #define _FLOWVIS_H
 
+#define FLOWVIS_SORT_FRAME  0
+#define FLOWVIS_SORT_3DPLOT 1
+
 void flowvis_set_render(int render_flowvi);
 int flowvis_get_render(void);
 
@@ -19,6 +22,9 @@ fftw_real *flowvis_get_frame(void);
 void flowvis_set_history(fftw_real **history);
 fftw_real *flowvis_get_history(int hisdex);
 
+void flowvis_set_sort(int sort);
+int flowvis_get_sort(void);
+
 void flowvis_set_hisdex(int arg);
 int  flowvis_get_hisdex(void);
 
diff --git a/Smoke/gtk_colormap.c b/Smoke/gtk_colormap.c
index 56ec810..0813917 100644
--- a/Smoke/gtk_colormap.c
+++ b/Smoke/gtk_colormap.c
@@ -286,7 +286,7 @@ GtkWidget *create_colormap_page(void)
     
     gtk_box_pack_start(GTK_BOX(page), frame, FALSE, TRUE, 0);
 
-            label = gtk_label_new("Smoke visualization");
+        label = gtk_label_new("Smoke visualization");
         gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0);
         gtk_widget_show(label);
 
diff --git a/Smoke/gtk_flowvis.c b/Smoke/gtk_flowvis.c
index 06f456c..a116e0f 100644
--- a/Smoke/gtk_flowvis.c
+++ b/Smoke/gtk_flowvis.c
@@ -40,6 +40,14 @@ static gboolean select_history(GtkRange *adjustment, gpointer data)
   return TRUE;
 }
 
+static gboolean select_sort(GtkComboBox *combo, gpointer data)
+{
+  flowvis_set_sort(gtk_combo_box_get_active(combo));
+
+  return TRUE;
+}
+
+
 
 GtkWidget *create_flowvis_page(void)
 {
@@ -128,6 +136,21 @@ GtkWidget *create_flowvis_page(void)
       
       gtk_box_pack_start(GTK_BOX(page), frame, FALSE, TRUE, 0);
 
+      label = gtk_label_new("History visualization");
+      gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0);
+      gtk_widget_show(label);
+      
+      combo = gtk_combo_box_new_text();
+
+        gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "Selected frame");
+        gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "Entire history (3D plot)");
+
+        gtk_combo_box_set_active(GTK_COMBO_BOX(combo), flowvis_get_sort());
+        g_signal_connect(combo, "changed", G_CALLBACK(select_sort), (gpointer)NULL);
+
+      gtk_box_pack_start(GTK_BOX(box), combo, FALSE, TRUE, 0);
+      gtk_widget_show(combo);
+
     gtk_widget_show(frame);
 
 
diff --git a/Smoke/gtk_main.c b/Smoke/gtk_main.c
index 80519e8..e09318d 100644
--- a/Smoke/gtk_main.c
+++ b/Smoke/gtk_main.c
@@ -184,7 +184,7 @@ GtkWidget *create_main_page(void)
           gtk_box_pack_start (GTK_BOX(box), button, TRUE, TRUE, 0);
           gtk_widget_show(button);
 
-          button = gtk_check_button_new_with_label("Draw flowvis");
+          button = gtk_check_button_new_with_label("Draw smoke history");
           gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), flowvis_get_render());
           g_signal_connect (G_OBJECT(button), "clicked", G_CALLBACK(select_render_flowvis), NULL);
           gtk_box_pack_start (GTK_BOX(box), button, TRUE, TRUE, 0);
diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c
index 57ed71f..eccf8b1 100644
--- a/Smoke/renderer_gl.c
+++ b/Smoke/renderer_gl.c
@@ -782,7 +782,7 @@ static void render_streamlines(void)
       frame_history = streamlines_get_history_scalars(j);
 
       cell_x = (fftw_real)winWidth  / (fftw_real)(DIM + 1); // Grid cell width
-	    cell_y = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell heigh
+	    cell_y = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell height
 
       idx_x = round(p.x / cell_x);
       idx_y = round(p.y / cell_y);
@@ -804,75 +804,92 @@ static void render_streamlines(void)
 
 static void render_flowvis(void)
 {
-	int        i, j, idx, DIM;
+	int i, j, k, idx, DIM, max_frame;
   double px,py;
 	fftw_real  wn, hn;
   struct color4f color;
   fftw_real *history;
 
-  
   DIM = fluids_get_dim();
   wn = (fftw_real)winWidth / (fftw_real)(DIM + 1);   // Grid cell width
 	hn = (fftw_real)winHeight / (fftw_real)(DIM + 1);  // Grid cell height
 
-  history = flowvis_get_history(flowvis_get_hisdex());
+  glPushMatrix();
 
-  if (flowvis_get_alpha() < 1.0f)
+  if (flowvis_get_sort() == FLOWVIS_SORT_FRAME)
   {
-    glEnable(GL_BLEND);
+    max_frame = 1;
   }
-  else
+  else // FLOWVIS_SORT_3DPLOT
   {
-    glDisable(GL_BLEND);
+    max_frame = HISTORY_SIZE;
   }
 
-  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-  for (j = 0; j < DIM - 1; j++)			//draw smoke
+  for (k = 0; k < max_frame; k+=2)
   {
-	  glBegin(GL_TRIANGLE_STRIP);
 
-	  i = 0;
-	  px = wn + (fftw_real)i * wn;
-	  py = hn + (fftw_real)j * hn;
-	  idx = (j * DIM) + i;
-		
-    color = flowvis_get_color((float)history[idx]);
-    glColor4f(color.r, color.g, color.b, color.a);
-	  glVertex2f((GLfloat)px, (GLfloat)py); // vertex 1
-						
-	  for (i = 0; i < DIM - 1; i++) 
-	  {
-		  px = wn + (fftw_real)i * wn;
-		  py = hn + (fftw_real)(j + 1) * hn;
-		  idx = ((j + 1) * DIM) + i;
+    if (max_frame <= 1)
+    {
+      history = flowvis_get_history(flowvis_get_hisdex());
+      if (flowvis_get_alpha() < 1.0f) { glEnable(GL_BLEND); }
+      else { glDisable(GL_BLEND); }
+    }
+    else
+    {
+      history = flowvis_get_history(k);
+      glTranslatef(0.0f, 0.0f, wn * 2);
+      glEnable(GL_BLEND);
+    }
+
+    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+    for (j = 0; j < DIM - 1; j++)			//draw smoke
+    {
+      glBegin(GL_TRIANGLE_STRIP);
+
+      i = 0;
+      px = wn + (fftw_real)i * wn;
+      py = hn + (fftw_real)j * hn;
+      idx = (j * DIM) + i;
+    	
       color = flowvis_get_color((float)history[idx]);
       glColor4f(color.r, color.g, color.b, color.a);
-      glVertex2f((GLfloat)px, (GLfloat)py); // vertex 2
+      glVertex2f((GLfloat)px, (GLfloat)py); // vertex 1
+    					
+      for (i = 0; i < DIM - 1; i++) 
+      {
+	      px = wn + (fftw_real)i * wn;
+	      py = hn + (fftw_real)(j + 1) * hn;
+	      idx = ((j + 1) * DIM) + i;
+        color = flowvis_get_color((float)history[idx]);
+        glColor4f(color.r, color.g, color.b, color.a);
+        glVertex2f((GLfloat)px, (GLfloat)py); // vertex 2
 
-		  px = wn + (fftw_real)(i + 1) * wn;
-		  py = hn + (fftw_real)j * hn;
-		  idx = (j * DIM) + (i + 1);
-		  color = flowvis_get_color((float)history[idx]);
-      glColor4f(color.r, color.g, color.b, color.a);
-		  glVertex2f((GLfloat)px, (GLfloat)py); // vertex 3
-	  }
+	      px = wn + (fftw_real)(i + 1) * wn;
+	      py = hn + (fftw_real)j * hn;
+	      idx = (j * DIM) + (i + 1);
+	      color = flowvis_get_color((float)history[idx]);
+        glColor4f(color.r, color.g, color.b, color.a);
+	      glVertex2f((GLfloat)px, (GLfloat)py); // vertex 3
+      }
 
-	  px = wn + (fftw_real)(DIM - 1) * wn;
-	  py = hn + (fftw_real)(j + 1) * hn;
-	  idx = ((j + 1) * DIM) + (DIM - 1);
-	  color = flowvis_get_color((float)history[idx]);
-    glColor4f(color.r, color.g, color.b, color.a);
-	  glVertex2f((GLfloat)px, (GLfloat)py); // vertex 4
+      px = wn + (fftw_real)(DIM - 1) * wn;
+      py = hn + (fftw_real)(j + 1) * hn;
+      idx = ((j + 1) * DIM) + (DIM - 1);
+      color = flowvis_get_color((float)history[idx]);
+      glColor4f(color.r, color.g, color.b, color.a);
+      glVertex2f((GLfloat)px, (GLfloat)py); // vertex 4
 
-	  glEnd();
+      glEnd();
+    }
   }
+  glPopMatrix();
 }
 
 
 
 void renderer_init_gl(void)
 {
-  float LightAmbient[]  = { 0.10f, 0.10f, 0.10f, 1.0f }; // Ambient light values
+  float LightAmbient[]  = { 0.20f, 0.20f, 0.20f, 1.0f }; // Ambient light values
   float LightDiffuse[]  = { 0.80f, 0.80f, 0.80f, 1.0f }; // Diffuse light values
   float LightPosition[] = { x_pos, y_pos, -500, 1.0f }; // Position of the light source
 
@@ -895,7 +912,7 @@ void renderer_init_gl(void)
   glEnable(GL_LIGHT0);
   glEnable(GL_COLOR_MATERIAL);
 
-  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 9.8f);
+  glMaterialf(GL_FRONT, GL_SHININESS, 9.8f);
 
   glLightfv(GL_LIGHT0, GL_AMBIENT,  LightAmbient);
   glLightfv(GL_LIGHT0, GL_DIFFUSE,  LightDiffuse);
-- 
cgit v0.12

