summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Schinagl <oliver@schinagl.nl>2007-12-20 01:34:35 (GMT)
committerOliver Schinagl <oliver@schinagl.nl>2007-12-20 01:34:35 (GMT)
commit4aabbced4987d0321827e4ae8bbd2e928205c9ba (patch)
treebad531cdacb7b4ce76e19f467e0c90677654c548
parentc087310ffc1618cac7d0100b5492794f5d03db20 (diff)
download2iv35-4aabbced4987d0321827e4ae8bbd2e928205c9ba.zip
2iv35-4aabbced4987d0321827e4ae8bbd2e928205c9ba.tar.gz
2iv35-4aabbced4987d0321827e4ae8bbd2e928205c9ba.tar.bz2
moved alpha value constant to each of their own classes;
flowvis now draws copy of frame
-rw-r--r--Smoke/colormap.c1
-rw-r--r--Smoke/divergence.c1
-rw-r--r--Smoke/flowvis.c1
-rw-r--r--Smoke/fluids.c17
-rw-r--r--Smoke/fluids.h6
-rw-r--r--Smoke/glyphs.c1
-rw-r--r--Smoke/gtk.c16
-rw-r--r--Smoke/heightplots.c1
-rw-r--r--Smoke/isolines.c1
-rw-r--r--Smoke/renderer_gl.c38
-rw-r--r--Smoke/renderer_gl.h2
-rwxr-xr-xSmoke/smoke.binbin619671 -> 619698 bytes
-rw-r--r--Smoke/streamlines.c1
13 files changed, 50 insertions, 36 deletions
diff --git a/Smoke/colormap.c b/Smoke/colormap.c
index d9ede0f..bd3f3a9 100644
--- a/Smoke/colormap.c
+++ b/Smoke/colormap.c
@@ -143,6 +143,7 @@ struct color4f colormap_get_color(float value)
value = colormap_scaling ? remap(value) : value;
return_value = set_palette(colormap_colormap, value, colormap_num_colors);
+ return_value.a = 1.0f;
return return_value;
}
diff --git a/Smoke/divergence.c b/Smoke/divergence.c
index 29f9c26..05fe29e 100644
--- a/Smoke/divergence.c
+++ b/Smoke/divergence.c
@@ -53,6 +53,7 @@ struct color4f divergence_get_color(float value)
struct color4f return_value;
return_value = set_palette(divergence_colormap, value, divergence_num_colors);
+ return_value.a = 1.0f;
return return_value;
}
diff --git a/Smoke/flowvis.c b/Smoke/flowvis.c
index 5adaf99..ed95732 100644
--- a/Smoke/flowvis.c
+++ b/Smoke/flowvis.c
@@ -53,6 +53,7 @@ struct color4f flowvis_get_color(float value)
struct color4f return_value;
return_value = set_palette(flowvis_colormap, value, flowvis_num_colors);
+ return_value.a = 1.0f;
return return_value;
}
diff --git a/Smoke/fluids.c b/Smoke/fluids.c
index fb7d65d..8e8620a 100644
--- a/Smoke/fluids.c
+++ b/Smoke/fluids.c
@@ -9,6 +9,7 @@
#include <math.h>
#include <stdio.h>
+#include <string.h>
#include <rfftw.h>
#include <GL/gl.h>
@@ -58,11 +59,13 @@ float z_rot = 0.0f;
//init_simulation: Initialize simulation data structures as a function of the grid size 'n'.
// Although the simulation takes place on a 2D grid, we allocate all data structures as 1D arrays,
// for compatibility with the FFTW numerical library.
-void init_simulation(int n)
+fftw_real *init_simulation(int n)
{
int i; size_t dim;
+ fftw_real *return_value;
dim = n * 2*(n/2+1)*sizeof(fftw_real); //Allocate data structures
+ return_value = (fftw_real *)malloc(dim);
vx = (fftw_real*) malloc(dim);
vy = (fftw_real*) malloc(dim);
vx0 = (fftw_real*) malloc(dim);
@@ -85,6 +88,8 @@ void init_simulation(int n)
for (i = 0; i < n * n; i++) //Initialize data structures to 0
{ vx[i] = vy[i] = vx0[i] = vy0[i] = fx[i] = fy[i] = rho[i] = rho0[i] = height_array[i] = 0.0f; }
+
+ return return_value;
}
int rescale_to_winwidth(float value)
@@ -230,8 +235,10 @@ void calculate_hight_plot(void)
}
}
-void copy_frame(void)
+void copy_frame(fftw_real *field)
{
+ memcpy(field, rho, DIM * 2 * (DIM / 2 + 1) * sizeof(fftw_real));
+#if 0
switch (vis_dataset)
{
case DATASET_FORCE:
@@ -247,7 +254,7 @@ void copy_frame(void)
case DATASET_DIVF:
break;
}
- frame_index = (frame_index + 1) % DIM;
+#endif
}
//do_one_simulation_step: Do one complete cycle of the simulation:
@@ -257,13 +264,13 @@ void copy_frame(void)
// - gluPostRedisplay: draw a new visualization frame
-void calculate_one_simulation_step(void)
+void calculate_one_simulation_step(fftw_real *field)
{
set_forces();
solve(DIM, vx, vy, vx0, vy0, visc, dt);
diffuse_matter(DIM, vx, vy, rho, rho0, dt);
calculate_hight_plot();
- copy_frame();
+ copy_frame(field);
}
//------ VISUALIZATION CODE STARTS HERE -----------------------------------------------------------------
diff --git a/Smoke/fluids.h b/Smoke/fluids.h
index 47bb31f..f1de92e 100644
--- a/Smoke/fluids.h
+++ b/Smoke/fluids.h
@@ -51,9 +51,7 @@ extern float xPos;
extern float yPos;
extern float zPos;
-void init_simulation(int n);
-
-void visualize(void);
+fftw_real *init_simulation(int n);
int rescale_to_winwidth(float value);
@@ -63,7 +61,7 @@ void click(int button, int state, int mx, int my);
void keyboard(unsigned char key, int x, int y);
-void calculate_one_simulation_step(void);
+void calculate_one_simulation_step(fftw_real *field);
float get_dataset(int index);
void set_autoscaling(void);
diff --git a/Smoke/glyphs.c b/Smoke/glyphs.c
index c2b9840..0917dc0 100644
--- a/Smoke/glyphs.c
+++ b/Smoke/glyphs.c
@@ -53,6 +53,7 @@ struct color4f glyphs_get_color(float value)
struct color4f return_value;
return_value = set_palette(glyphs_colormap, value, glyphs_num_colors);
+ return_value.a = 0.5f;
return return_value;
}
diff --git a/Smoke/gtk.c b/Smoke/gtk.c
index df9a6ee..d17d4ad 100644
--- a/Smoke/gtk.c
+++ b/Smoke/gtk.c
@@ -96,7 +96,7 @@ static void toggle_animation (GtkWidget *widget);
static GdkGLConfig *configure_gl (void);
static GtkWidget *create_popup_menu (GtkWidget *drawing_area);
-static GtkWidget *create_window (GdkGLConfig *glconfig);
+static GtkWidget *create_window (GdkGLConfig *glconfig, fftw_real *field);
/**************************************************************************
@@ -179,6 +179,7 @@ expose_event (GtkWidget *widget,
GdkEventExpose *event,
gpointer data)
{
+ fftw_real *field = (gpointer)data;
GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);
@@ -194,8 +195,8 @@ expose_event (GtkWidget *widget,
// fluids
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- calculate_one_simulation_step();
- visualize();
+ calculate_one_simulation_step(field);
+ visualize(field);
// endf
/* Swap buffers */
@@ -604,7 +605,7 @@ create_popup_menu (GtkWidget *drawing_area)
*** drawing area that has an OpenGL-capable visual.
***/
static GtkWidget *
-create_window (GdkGLConfig *glconfig)
+create_window (GdkGLConfig *glconfig, fftw_real *field)
{
GtkWidget *window;
GtkWidget *hbox;
@@ -661,7 +662,7 @@ create_window (GdkGLConfig *glconfig)
g_signal_connect (G_OBJECT (drawing_area), "configure_event",
G_CALLBACK (configure_event), NULL);
g_signal_connect (G_OBJECT (drawing_area), "expose_event",
- G_CALLBACK (expose_event), NULL);
+ G_CALLBACK (expose_event), (gpointer)field);
g_signal_connect (G_OBJECT (drawing_area), "unrealize",
G_CALLBACK (unrealize), NULL);
@@ -841,9 +842,10 @@ main (int argc,
int i;
struct color4f colormap;
float value;
+ fftw_real *field;
/* Initialize the simulation */
- init_simulation(DIM);
+ field = init_simulation(DIM);
/* Initialize GTK. */
gtk_init (&argc, &argv);
@@ -855,7 +857,7 @@ main (int argc,
glconfig = configure_gl ();
/* Create and show the application window. */
- window = create_window (glconfig);
+ window = create_window (glconfig, field);
gtk_widget_show (window);
init_gl();
diff --git a/Smoke/heightplots.c b/Smoke/heightplots.c
index 57d9054..fa12a78 100644
--- a/Smoke/heightplots.c
+++ b/Smoke/heightplots.c
@@ -53,6 +53,7 @@ struct color4f heightplots_get_color(float value)
struct color4f return_value;
return_value = set_palette(heightplots_colormap, value, heightplots_num_colors);
+ return_value.a = 1.0f;
return return_value;
}
diff --git a/Smoke/isolines.c b/Smoke/isolines.c
index 5355b83..cff0201 100644
--- a/Smoke/isolines.c
+++ b/Smoke/isolines.c
@@ -53,6 +53,7 @@ struct color4f isolines_get_color(float value)
struct color4f return_value;
return_value = set_palette(isolines_colormap, value, isolines_num_colors);
+ return_value.a = 1.0f;
return return_value;
}
diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c
index e60e35a..497a341 100644
--- a/Smoke/renderer_gl.c
+++ b/Smoke/renderer_gl.c
@@ -138,13 +138,13 @@ static void render_smoke(void)
py = hn + (fftw_real)(j + 1) * hn;
idx = ((j + 1) * DIM) + i;
color = colormap_get_color(get_dataset(idx));
- glColor4f(color.r, color.g, color.b, 1.0f);
+ glColor4f(color.r, color.g, color.b, color.a);
glVertex3f(px, py, height_array[idx]);
px = wn + (fftw_real)(i + 1) * wn;
py = hn + (fftw_real)j * hn;
idx = (j * DIM) + (i + 1);
color = colormap_get_color(get_dataset(idx));
- glColor4f(color.r, color.g, color.b, 1.0f);
+ glColor4f(color.r, color.g, color.b, color.a);
glVertex3f(px, py, height_array[idx]);
}
@@ -152,7 +152,7 @@ static void render_smoke(void)
py = hn + (fftw_real)(j + 1) * hn;
idx = ((j + 1) * DIM) + (DIM - 1);
color = colormap_get_color(get_dataset(idx));
- glColor4f(color.r, color.g, color.b, 1.0f);
+ glColor4f(color.r, color.g, color.b, color.a);
glVertex3f(px, py, height_array[idx]);
glEnd();
}
@@ -291,7 +291,7 @@ static void render_glyphs(void)
}
color = glyphs_get_color(value);
- glColor4f(color.r, color.b, color.g, 0.5f);
+ glColor4f(color.r, color.b, color.g, color.a);
switch (glyph_vector)
{
default:
@@ -351,7 +351,7 @@ static void render_isolines(void)
state = 0;
idx = (j * DIM) + i;
color = isolines_get_color(get_dataset(idx));
- glColor4f(color.r, color.g, color.b, 1.0f);
+ glColor4f(color.r, color.g, color.b, color.a);
v0 = get_dataset(idx + DIM);
v1 = get_dataset(idx + 1 + DIM);
@@ -475,7 +475,7 @@ static void render_streamlines(void)
}
-void render_flowvis(void)
+void render_flowvis(fftw_real *field)
{
int i, j, idx; double px,py;
fftw_real wn = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width
@@ -493,31 +493,31 @@ void render_flowvis(void)
py = hn + (fftw_real)j * hn;
idx = (j * DIM) + i;
- glColor3f(rho[idx],rho[idx],rho[idx]);
- glVertex3f(px,py, height_array[idx]);
+ glColor3f(field[idx],field[idx],field[idx]);
+ glVertex2f(px,py);
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(get_dataset(idx));
- glColor4f(color.r, color.g, color.b, 1.0f);
- glVertex3f(px, py, height_array[idx]);
+ color = flowvis_get_color(field[idx]);
+ glColor4f(color.r, color.g, color.b, color.a);
+ glVertex2f(px, py);
px = wn + (fftw_real)(i + 1) * wn;
py = hn + (fftw_real)j * hn;
idx = (j * DIM) + (i + 1);
- color = flowvis_get_color(get_dataset(idx));
- glColor4f(color.r, color.g, color.b, 1.0f);
- glVertex3f(px, py, height_array[idx]);
+ color = flowvis_get_color(field[idx]);
+ glColor4f(color.r, color.g, color.b, color.a);
+ glVertex2f(px, py);
}
px = wn + (fftw_real)(DIM - 1) * wn;
py = hn + (fftw_real)(j + 1) * hn;
idx = ((j + 1) * DIM) + (DIM - 1);
- color = flowvis_get_color(get_dataset(idx));
- glColor4f(color.r, color.g, color.b, 1.0f);
- glVertex3f(px, py, height_array[idx]);
+ color = flowvis_get_color(field[idx]);
+ glColor4f(color.r, color.g, color.b, color.a);
+ glVertex2f(px, py);
glEnd();
}
}
@@ -562,7 +562,7 @@ void zoom_out(int zoom)
//visualize: This is the main visualization function
-void visualize(void)
+void visualize(fftw_real *field)
{
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
@@ -600,6 +600,6 @@ void visualize(void)
}
if (flowvis_get_render()) {
- render_flowvis();
+ render_flowvis(field);
}
}
diff --git a/Smoke/renderer_gl.h b/Smoke/renderer_gl.h
index 000ecb1..ea3d258 100644
--- a/Smoke/renderer_gl.h
+++ b/Smoke/renderer_gl.h
@@ -3,7 +3,7 @@
void init_gl(void);
-void visualize(void);
+void visualize(fftw_real *field);
void zoom_in(int zoom);
void zoom_out(int zoom);
diff --git a/Smoke/smoke.bin b/Smoke/smoke.bin
index 4673fea..47f88cc 100755
--- a/Smoke/smoke.bin
+++ b/Smoke/smoke.bin
Binary files differ
diff --git a/Smoke/streamlines.c b/Smoke/streamlines.c
index acfc016..2903b49 100644
--- a/Smoke/streamlines.c
+++ b/Smoke/streamlines.c
@@ -53,6 +53,7 @@ struct color4f streamlines_get_color(float value)
struct color4f return_value;
return_value = set_palette(streamlines_colormap, value, streamlines_num_colors);
+ return_value.a = 1.0f;
return return_value;
}