summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilrik de Loose <wilrik@wilrik.nl>2008-01-10 20:59:50 (GMT)
committerWilrik de Loose <wilrik@wilrik.nl>2008-01-10 20:59:50 (GMT)
commitdcab21f30e9c451bfc2b7e65d90323b5e11a8612 (patch)
tree07ead18381e62c1ef7295252126410d73ac8164a
parenta003a02f8ae4f5bc14cbed9249b0fbfefdd2fd07 (diff)
download2iv35-dcab21f30e9c451bfc2b7e65d90323b5e11a8612.zip
2iv35-dcab21f30e9c451bfc2b7e65d90323b5e11a8612.tar.gz
2iv35-dcab21f30e9c451bfc2b7e65d90323b5e11a8612.tar.bz2
normal vectors correct
-rw-r--r--Smoke/Week 2.suobin78336 -> 78336 bytes
-rw-r--r--Smoke/fluids.c32
-rw-r--r--Smoke/gtk.c2
-rw-r--r--Smoke/gtk_flowvis.c23
-rw-r--r--Smoke/gtk_streamlines.c23
-rw-r--r--Smoke/renderer_gl.c25
-rw-r--r--Smoke/renderer_gl.h2
-rw-r--r--Smoke/streamlines.c27
-rw-r--r--Smoke/streamlines.h2
9 files changed, 77 insertions, 59 deletions
diff --git a/Smoke/Week 2.suo b/Smoke/Week 2.suo
index d77119f..9f89abb 100644
--- a/Smoke/Week 2.suo
+++ b/Smoke/Week 2.suo
Binary files differ
diff --git a/Smoke/fluids.c b/Smoke/fluids.c
index 01ca443..a6c0a03 100644
--- a/Smoke/fluids.c
+++ b/Smoke/fluids.c
@@ -247,6 +247,11 @@ struct point vector_normal(struct point vert1, struct point vert2, struct point
return_value.y /= length;
return_value.z /= length;
+ if (return_value.x == return_value.y == return_value.z == 0.0f)
+ {
+ return_value.z = 1.0f;
+ }
+
return return_value;
}
@@ -263,7 +268,7 @@ void calculate_normal_vectors(void)
for (j = 0; j < DIM; j++)
{
for (i = 0; i < DIM; i++)
- {
+ {
idx = (j * DIM) + i;
px = wn + (fftw_real)i * wn;
py = hn + (fftw_real)(j + 1) * hn;
@@ -281,33 +286,39 @@ void calculate_normal_vectors(void)
p3.z = height_array[idx + 1];
normal_array[idx] = vector_normal(p2, p1, p3);
+ normal_array[idx + 1] = vector_normal(p2, p1, p3);
}
}
}
struct point calculate_normal_vector(fftw_real *height, int index, int i, int j)
{
- struct point p1, p2, p3;
+ int idx;
+ float px, py;
+ struct point p1, p2, p3, rv;
fftw_real wn = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width
fftw_real hn = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell height
- float px = wn + (fftw_real)i * wn;
- float py = hn + (fftw_real)(j + 1) * hn;
+
+ px = wn + (fftw_real)i * wn;
+ py = hn + (fftw_real)(j + 1) * hn;
p1.x = px;
- p1.y = py + hn;
- p1.z = height[index + DIM];
+ p1.y = py;
+ p1.z = height[index];
p2.x = px;
- p2.y = py;
- p2.z = height[index];
+ p2.y = py + hn;
+ p2.z = height[index + DIM];
p3.x = px + wn;
p3.y = py;
p3.z = height[index + 1];
+ normal_array[index] = vector_normal(p2, p1, p3);
+ rv = vector_normal(p2, p1, p3);
- return vector_normal(p1, p2, p3);
+ return rv;
}
void calculate_height_plots(void)
@@ -486,7 +497,8 @@ void fluids_calculate_one_simulation_step(struct vis_data_arrays *vis_data)
int dataset;
fftw_real *frame;
- if (fluids_calculate) {
+ if (fluids_calculate)
+ {
set_forces();
solve(DIM, vx, vy, vx0, vy0, visc, dt);
diffuse_matter(DIM, vx, vy, rho, rho0, dt);
diff --git a/Smoke/gtk.c b/Smoke/gtk.c
index e696d8d..09b0c53 100644
--- a/Smoke/gtk.c
+++ b/Smoke/gtk.c
@@ -800,7 +800,7 @@ create_window (GdkGLConfig *glconfig, struct vis_data_arrays *vis_data)
gtk_notebook_append_page(GTK_NOTEBOOK(settings_notebook), notebook_page, notebook_page_label);
- notebook_page_label = gtk_label_new("Flow vis");
+ notebook_page_label = gtk_label_new("Smoke history");
gtk_widget_show(notebook_page_label);
notebook_page = create_flowvis_page();
diff --git a/Smoke/gtk_flowvis.c b/Smoke/gtk_flowvis.c
index 5db3b62..d161bb4 100644
--- a/Smoke/gtk_flowvis.c
+++ b/Smoke/gtk_flowvis.c
@@ -33,6 +33,13 @@ static gboolean select_alpha(GtkRange *adjustment, gpointer data)
return TRUE;
}
+static gboolean select_history(GtkRange *adjustment, gpointer data)
+{
+ streamlines_set_hisdex((int)gtk_range_get_value(adjustment) - 1);
+
+ return TRUE;
+}
+
GtkWidget *create_flowvis_page(void)
{
@@ -83,13 +90,14 @@ GtkWidget *create_flowvis_page(void)
gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0);
gtk_widget_show(label);
-
adjustment = GTK_ADJUSTMENT(gtk_adjustment_new(
flowvis_get_num_colors(), 1, PALETTE_MAXCOLORS, 0.5, 5, 0.1));
scale = gtk_hscale_new(adjustment);
gtk_scale_set_digits(GTK_SCALE(scale), 0);
g_signal_connect(GTK_RANGE(scale), "value-changed", G_CALLBACK(select_num_colors), NULL);
+ gtk_box_pack_start(GTK_BOX(box), scale, FALSE, TRUE, 0);
+ gtk_widget_show(scale);
label = gtk_label_new("Alpha");
@@ -105,7 +113,18 @@ GtkWidget *create_flowvis_page(void)
gtk_widget_show(scale);
gtk_container_add(GTK_CONTAINER(frame), box);
- gtk_widget_show(box);
+ gtk_widget_show(box);label = gtk_label_new("Select smoke history frame");
+
+ gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0);
+ gtk_widget_show(label);
+
+ adjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 1, HISTORY_SIZE, 5, 5, 0));
+ scale = gtk_hscale_new(adjustment);
+ gtk_scale_set_digits(GTK_SCALE(scale), 0);
+ g_signal_connect(GTK_RANGE(scale), "value-changed", G_CALLBACK(select_history), NULL);
+
+ gtk_box_pack_start(GTK_BOX(box), scale, FALSE, TRUE, 0);
+ gtk_widget_show(scale);
gtk_box_pack_start(GTK_BOX(page), frame, FALSE, TRUE, 0);
diff --git a/Smoke/gtk_streamlines.c b/Smoke/gtk_streamlines.c
index 187df55..b90d26c 100644
--- a/Smoke/gtk_streamlines.c
+++ b/Smoke/gtk_streamlines.c
@@ -3,16 +3,11 @@
#include <rfftw.h>
#include "fluids.h"
-
#include "palette.h"
#include "streamlines.h"
-
#include "renderer_gl.h"
-
#include "gtk_streamlines.h"
-
-
static gboolean select_colormap(GtkComboBox *combo, gpointer data)
{
streamlines_set_colormap(gtk_combo_box_get_active(combo));
@@ -35,13 +30,6 @@ static gboolean select_alpha(GtkRange *adjustment, gpointer data)
return TRUE;
}
-static gboolean select_history(GtkRange *adjustment, gpointer data)
-{
- set_hisdex((int)gtk_range_get_value(adjustment));
-
- return TRUE;
-}
-
GtkWidget *create_streamlines_page(void)
@@ -118,17 +106,6 @@ GtkWidget *create_streamlines_page(void)
gtk_box_pack_start(GTK_BOX(box), scale, FALSE, TRUE, 0);
gtk_widget_show(scale);
-
- adjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, HISTORY_SIZE -1, 5, 5, 0));
- scale = gtk_hscale_new(adjustment);
- gtk_scale_set_digits(GTK_SCALE(scale), 0);
- g_signal_connect(GTK_RANGE(scale), "value-changed", G_CALLBACK(select_history), NULL);
-
- gtk_box_pack_start(GTK_BOX(box), scale, FALSE, TRUE, 0);
- gtk_widget_show(scale);
-
-
-
gtk_container_add(GTK_CONTAINER(frame), box);
gtk_widget_show(box);
diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c
index 8cc2095..ac10bf7 100644
--- a/Smoke/renderer_gl.c
+++ b/Smoke/renderer_gl.c
@@ -296,12 +296,12 @@ static void render_normals(void)
idx = (j * DIM) + i;
px = wn + (fftw_real)i * wn;
py = hn + (fftw_real)(j + 1) * hn;
- pz = height[idx] *height_multiplier;
+ pz = height[idx] * 16;
glVertex3f(px, py, pz);
- glVertex3f(px +(normal[idx].x *NORMAL_SCALE),
- py +(normal[idx].y *NORMAL_SCALE),
- pz +(normal[idx].z *NORMAL_SCALE));
+ glVertex3f(px +(normal[idx].x * NORMAL_SCALE),
+ py +(normal[idx].y * NORMAL_SCALE),
+ pz +(normal[idx].z * NORMAL_SCALE));
}
}
glEnable(GL_LIGHTING);
@@ -796,12 +796,6 @@ static void render_streamlines(void)
}
}
-static int hisdex = 0;
-
-void set_hisdex(int arg) {
- hisdex = arg;
-}
-
static void render_flowvis(void)
{
int i, j, idx, DIM;
@@ -815,7 +809,16 @@ static void render_flowvis(void)
wn = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width
hn = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell height
- history = streamlines_get_history(hisdex);
+ history = streamlines_get_history(streamlines_get_hisdex());
+
+ if (flowvis_get_alpha() < 1.0f)
+ {
+ glEnable(GL_BLEND);
+ }
+ else
+ {
+ glDisable(GL_BLEND);
+ }
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
for (j = 0; j < DIM - 1; j++) //draw smoke
diff --git a/Smoke/renderer_gl.h b/Smoke/renderer_gl.h
index 7238037..d5afd16 100644
--- a/Smoke/renderer_gl.h
+++ b/Smoke/renderer_gl.h
@@ -5,8 +5,6 @@ void renderer_init_gl(void);
void visualize(struct vis_data_arrays *vis_data);
-void set_hisdex(int arg);
-
void renderer_set_zoomspeed(int zoomspeed);
int renderer_get_zoomspeed(void);
diff --git a/Smoke/streamlines.c b/Smoke/streamlines.c
index 3b54a36..6bae373 100644
--- a/Smoke/streamlines.c
+++ b/Smoke/streamlines.c
@@ -12,22 +12,29 @@
#include "streamlines.h"
-
-
-static int streamlines_render = FALSE;
-
+static int streamlines_render = FALSE;
static int streamlines_num_colors = PALETTE_MAXCOLORS;
-
-static int streamlines_colormap = PALETTE_BLACKWHITE;
-
-static int streamlines_dataset = DATASET_RHO;
-
-static float streamlines_alpha = 1.0f;
+static int streamlines_colormap = PALETTE_BLACKWHITE;
+static int streamlines_dataset = DATASET_RHO;
+static float streamlines_alpha = 1.0f;
static fftw_real *streamlines_frame;
static fftw_real **streamlines_history;
struct fftw_real_xy *streamlines_history_scalars;
+static int hisdex = 0;
+
+void streamlines_set_hisdex(int arg)
+{
+ int idx = (fluids_get_hisdex() + 1) % HISTORY_SIZE;
+
+ hisdex = (arg + idx) % HISTORY_SIZE;
+}
+
+int streamlines_get_hisdex(void)
+{
+ return hisdex;
+}
void streamlines_set_render(int render_streamlines)
{
diff --git a/Smoke/streamlines.h b/Smoke/streamlines.h
index 14736e3..54c31ea 100644
--- a/Smoke/streamlines.h
+++ b/Smoke/streamlines.h
@@ -25,6 +25,8 @@ struct fftw_real_xy *streamlines_get_history_scalars(void);
void streamlines_set_history(fftw_real **history);
fftw_real *streamlines_get_history(int hisdex);
+void streamlines_set_hisdex(int arg);
+int streamlines_get_hisdex(void);
struct color4f streamlines_get_color(float value);