diff options
author | Wilrik de Loose <wilrik@wilrik.nl> | 2007-12-14 14:31:07 (GMT) |
---|---|---|
committer | Wilrik de Loose <wilrik@wilrik.nl> | 2007-12-14 14:31:07 (GMT) |
commit | 241bfc64ed6446c295846d5ae635f6ba4e25a666 (patch) | |
tree | e7984b4511e52770ff154f02e486f36030e0eb16 /Smoke/fluids.c | |
parent | 6c1d686104ee1ecc3cfdad13ee2177041928e58f (diff) | |
download | 2iv35-241bfc64ed6446c295846d5ae635f6ba4e25a666.zip 2iv35-241bfc64ed6446c295846d5ae635f6ba4e25a666.tar.gz 2iv35-241bfc64ed6446c295846d5ae635f6ba4e25a666.tar.bz2 |
lalala niet veel nieuws
Diffstat (limited to 'Smoke/fluids.c')
-rw-r--r-- | Smoke/fluids.c | 107 |
1 files changed, 60 insertions, 47 deletions
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(); |