summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilrik de Loose <wilrik@wilrik.nl>2007-12-14 14:31:07 (GMT)
committerWilrik de Loose <wilrik@wilrik.nl>2007-12-14 14:31:07 (GMT)
commit241bfc64ed6446c295846d5ae635f6ba4e25a666 (patch)
treee7984b4511e52770ff154f02e486f36030e0eb16
parent6c1d686104ee1ecc3cfdad13ee2177041928e58f (diff)
download2iv35-241bfc64ed6446c295846d5ae635f6ba4e25a666.zip
2iv35-241bfc64ed6446c295846d5ae635f6ba4e25a666.tar.gz
2iv35-241bfc64ed6446c295846d5ae635f6ba4e25a666.tar.bz2
lalala niet veel nieuws
-rw-r--r--Smoke/Week 2.ncbbin15518720 -> 15518720 bytes
-rw-r--r--Smoke/Week 2.suobin44032 -> 44032 bytes
-rw-r--r--Smoke/fluids.c107
-rw-r--r--Smoke/fluids.h8
-rw-r--r--Smoke/seedpoint.c11
-rw-r--r--Smoke/seedpoint.h2
-rw-r--r--Smoke/streamlines.c27
7 files changed, 97 insertions, 58 deletions
diff --git a/Smoke/Week 2.ncb b/Smoke/Week 2.ncb
index cc88001..1680b8b 100644
--- a/Smoke/Week 2.ncb
+++ b/Smoke/Week 2.ncb
Binary files differ
diff --git a/Smoke/Week 2.suo b/Smoke/Week 2.suo
index 18403e8..04fe50a 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 8832a3a..0f46d84 100644
--- a/Smoke/fluids.c
+++ b/Smoke/fluids.c
@@ -26,7 +26,7 @@ fftw_real *vx, *vy; //(vx,vy) = velocity field at the current mome
fftw_real *vx0, *vy0; //(vx0,vy0) = velocity field at the previous moment
fftw_real *fx, *fy; //(fx,fy) = user-controlled simulation forces, steered with the mouse
fftw_real *rho, *rho0; //smoke density at the current (rho) and previous (rho0) moment
-fftw_real *hight_array; //used for hight plot
+fftw_real *height_array; //used for height plot
int *frame_hist;
int frame_index = 0;
rfftwnd_plan plan_rc, plan_cr; //simulation domain discretization
@@ -99,16 +99,16 @@ void init_simulation(int n)
plan_rc = rfftw2d_create_plan(n, n, FFTW_REAL_TO_COMPLEX, FFTW_IN_PLACE);
plan_cr = rfftw2d_create_plan(n, n, FFTW_COMPLEX_TO_REAL, FFTW_IN_PLACE);
- hight_array = (fftw_real*) malloc(dim);
- frame_hist = (int*) malloc(n * sizeof(int *));
+ height_array = (fftw_real*) malloc(dim);
+ frame_hist = (fftw_real*) malloc(dim * n);
for (i = 0; i <= n; i++)
{
- frame_hist[i] = (fftw_real*)malloc(n * 2*(n/2+1)*sizeof(fftw_real));
+ frame_hist[i] = (fftw_real*) malloc(dim);
}
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] = hight_array[i] = 0.0f; }
+ { vx[i] = vy[i] = vx0[i] = vy0[i] = fx[i] = fy[i] = rho[i] = rho0[i] = height_array[i] = 0.0f; }
glShadeModel(GL_SMOOTH); // Enable smooth shading
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black background
@@ -253,18 +253,18 @@ void calculate_hight_plot(void)
switch (vis_dataset)
{
case DATASET_FORCE:
- hight_array[i] = quake_root(fx[i] * fx[i] + fy[i] * fy[i]) * 100;
+ height_array[i] = quake_root(fx[i] * fx[i] + fy[i] * fy[i]) * 100;
break;
case DATASET_VEL:
- hight_array[i] = quake_root(vx[i] * vx[i] + vy[i] * vy[i]) * 2000;
+ height_array[i] = quake_root(vx[i] * vx[i] + vy[i] * vy[i]) * 5000;
break;
case DATASET_RHO:
- hight_array[i] = rho[i] * 10;
+ height_array[i] = rho[i] * 16;
break;
default:
case DATASET_DIVV:
case DATASET_DIVF:
- hight_array[i] = 0.0f;
+ height_array[i] = 0.0f;
break;
}
}
@@ -279,7 +279,8 @@ void copy_frame(void)
case DATASET_VEL:
break;
case DATASET_RHO:
- memcpy(frame_hist[frame_index], rho, sizeof(DIM * 2 * (DIM / 2 + 1) * sizeof(fftw_real)));
+ //memcpy(frame_hist[frame_index], rho, sizeof(DIM * 2 * (DIM / 2 + 1) * sizeof(fftw_real)));
+ memcpy(frame_hist[frame_index], rho, DIM * 2 * (DIM / 2 + 1) * sizeof(fftw_real));
break;
default:
case DATASET_DIVV:
@@ -305,7 +306,6 @@ void calculate_one_simulation_step(void)
copy_frame();
}
-
//------ VISUALIZATION CODE STARTS HERE -----------------------------------------------------------------
float remap(float value)
@@ -355,6 +355,7 @@ float get_dataset(int index)
fftw_real cell_x = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width
fftw_real cell_y = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell heigh
float return_value, par_der_x, par_der_y;
+ static int cur_fr = 0;
return_value = 0;
@@ -366,8 +367,8 @@ float get_dataset(int index)
case DATASET_VEL:
return_value = (float)quake_root((vx[index] * vx[index]) + (vy[index] * vy[index]));
break;
+ default:
case DATASET_RHO:
- default:
return_value = (float)rho[index];
break;
case DATASET_DIVV:
@@ -518,6 +519,52 @@ void draw_isolines(float threshold)
glEnd();
}
+void render_smoke(void)
+{
+ static float fadein = 0;
+ int i, j, idx; double px,py;
+ 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
+ static int delay = 0;
+ float hight_value = 0.0f;
+
+ 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;
+
+ glColor3f(rho[idx],rho[idx],rho[idx]);
+ glVertex3f(px,py, height_array[idx]);
+
+ 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;
+ set_colormap(scalar_col, get_dataset(idx), FALSE, 1.0f);
+ glVertex3f(px, py, height_array[idx]);
+ px = wn + (fftw_real)(i + 1) * wn;
+ py = hn + (fftw_real)j * hn;
+ idx = (j * DIM) + (i + 1);
+ set_colormap(scalar_col, get_dataset(idx), FALSE, 1.0f);
+ glVertex3f(px, py, height_array[idx]);
+ }
+
+ px = wn + (fftw_real)(DIM - 1) * wn;
+ py = hn + (fftw_real)(j + 1) * hn;
+ idx = ((j + 1) * DIM) + (DIM - 1);
+ set_colormap(scalar_col, get_dataset(idx), FALSE, 1.0f);
+ glVertex3f(px, py, height_array[idx]);
+ glEnd();
+ }
+}
+
//visualize: This is the main visualization function
void visualize(void)
{
@@ -618,41 +665,7 @@ void visualize(void)
// draw the smoke
if (draw_smoke)
{
- 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;
-
- glColor3f(rho[idx],rho[idx],rho[idx]);
- glVertex3f(px,py, hight_array[idx]);
-
- 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;
- set_colormap(scalar_col, get_dataset(idx), FALSE, 1.0f);
- glVertex3f(px, py, hight_array[idx]);
- px = wn + (fftw_real)(i + 1) * wn;
- py = hn + (fftw_real)j * hn;
- idx = (j * DIM) + (i + 1);
- set_colormap(scalar_col, get_dataset(idx), FALSE, 1.0f);
- glVertex3f(px, py, hight_array[idx]);
- }
-
- px = wn + (fftw_real)(DIM - 1) * wn;
- py = hn + (fftw_real)(j + 1) * hn;
- idx = ((j + 1) * DIM) + (DIM - 1);
- set_colormap(scalar_col, get_dataset(idx), FALSE, 1.0f);
- glVertex3f(px, py, hight_array[idx]);
- glEnd();
- }
+ render_smoke();
}
draw_glyphs();
diff --git a/Smoke/fluids.h b/Smoke/fluids.h
index 452f1c5..8ff6cbd 100644
--- a/Smoke/fluids.h
+++ b/Smoke/fluids.h
@@ -15,7 +15,7 @@ extern fftw_real *vx0, *vy0; //(vx0,vy0) = velocity field at the previ
extern fftw_real *fx, *fy; //(fx,fy) = user-controlled simulation forces, steered with the mouse
extern fftw_real *rho, *rho0; //smoke density at the current (rho) and previous (rho0) moment
extern rfftwnd_plan plan_rc, plan_cr; //simulation domain discretization
-extern fftw_real *hight_array; //used for hight plot
+extern fftw_real *height_array; //used for hight plot
extern int *frame_hist;
extern int frame_index;
@@ -81,8 +81,6 @@ extern float zPos;
void init_simulation(int n);
-void visualize(void);
-
int rescale_to_winwidth(float value);
void drag(int mx, int my);
@@ -91,8 +89,6 @@ 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);
-
int get_glyph_usage(void);
//////////////////
@@ -106,7 +102,7 @@ void diffuse_matter(int n, fftw_real *vx, fftw_real *vy, fftw_real *rho, fftw_re
void set_forces(void);
void calculate_hight_plot(void);
void copy_frame(void);
-void calculate_one_simulation_step(void);;
+void calculate_one_simulation_step(void);
float remap(float value);
void direction_to_color(float x, float y, int method);
float get_dataset(int index);
diff --git a/Smoke/seedpoint.c b/Smoke/seedpoint.c
index d285e84..a7bd04c 100644
--- a/Smoke/seedpoint.c
+++ b/Smoke/seedpoint.c
@@ -83,4 +83,15 @@ int get_cur_seedpoint(void)
void set_cur_seedpoint(int seed_nr)
{
cur_seedpoint = seed_nr;
+}
+
+struct point get_seedpoint(int index)
+{
+ struct point p;
+
+ p.x = seedpoints[index].x;
+ p.y = seedpoints[index].y;
+ p.z = seedpoints[index].z;
+
+ return p;
} \ No newline at end of file
diff --git a/Smoke/seedpoint.h b/Smoke/seedpoint.h
index 0bbbf47..557f59f 100644
--- a/Smoke/seedpoint.h
+++ b/Smoke/seedpoint.h
@@ -10,5 +10,7 @@ void render_seedpoints(void);
int get_cur_seedpoint(void);
void set_cur_seedpoint(int seed_nr);
+struct point get_seedpoint(int index);
+
#endif
diff --git a/Smoke/streamlines.c b/Smoke/streamlines.c
index 51e9fa0..2dc7714 100644
--- a/Smoke/streamlines.c
+++ b/Smoke/streamlines.c
@@ -8,18 +8,35 @@
#include "fluids.h"
#include "streamlines.h"
#include "seedpoint.h"
+#include "funcs.h"
void render_streamlines(void)
{
- int i, j, max;
- i = j = max = 0;
+ int i, j, k, l, idx;
+ float v;
+ struct point p;
+ int *frame_history;
+ fftw_real cell_x, cell_y;
- max = get_cur_seedpoint();
+ i = j = k = l = 0;
- for (i = 0; i < max; i++)
+ for (i = 0; i < get_cur_seedpoint(); i++)
{
- while (frame_hist[j] != NULL)
+ p = get_seedpoint(i);
+
+ while (j < DIM)
{
+ frame_history = frame_hist[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_x = round(p.x / cell_x);
+ cell_y = round(p.y / cell_y);
+
+ idx = cell_x + (cell_y * DIM) + (j * DIM * DIM);
+ //v = frame_history[idx];
+
j++;
}
}