diff options
author | Wilrik de Loose <wilrik@wilrik.nl> | 2007-12-14 08:35:25 (GMT) |
---|---|---|
committer | Wilrik de Loose <wilrik@wilrik.nl> | 2007-12-14 08:35:25 (GMT) |
commit | 5601182e9456b3d4d782f135c8b151f5d9b021cd (patch) | |
tree | fe9e06a8a0f572dad622e8887732796a725887fe /Smoke/fluids.c | |
parent | 2b49eb5eb684537c19d9f0eabdffad0ffcf196ac (diff) | |
download | 2iv35-5601182e9456b3d4d782f135c8b151f5d9b021cd.zip 2iv35-5601182e9456b3d4d782f135c8b151f5d9b021cd.tar.gz 2iv35-5601182e9456b3d4d782f135c8b151f5d9b021cd.tar.bz2 |
glyphs apart in een file gestopt
Diffstat (limited to 'Smoke/fluids.c')
-rw-r--r-- | Smoke/fluids.c | 208 |
1 files changed, 32 insertions, 176 deletions
diff --git a/Smoke/fluids.c b/Smoke/fluids.c index b40b507..e9756df 100644 --- a/Smoke/fluids.c +++ b/Smoke/fluids.c @@ -2,32 +2,18 @@ // the velocity field at the mouse location. Press the indicated keys to change options //-------------------------------------------------------------------------------------------------- -#define max(a, b) (a > b ? a : b) -#define min(a, b) (a < b ? a : b) -#define round(x) (int)(x < 0 ? x - 0.5 : x + 0.5) - -#define MAX_INFINITE (1.#INF000) -#define MIN_INFINITE (-1.#INF000) - -#define vec_len(x,y) (sqrt((x*x) + (y*y))) - -#define FALSE 0 -#define TRUE !FALSE - #ifdef G_OS_WIN32 #define WIN32_LEAN_AND_MEAN 1 #include <windows.h> #endif #include <math.h> -#include <rfftw.h> //the numerical simulation FFTW library -#include <stdio.h> //for printing the help text - -#include <GL/gl.h> -#include <GL/glu.h> +#include <stdio.h> #include "fluids.h" +#include "glyphs.h" #include "seedpoint.h" +#include "funcs.h" //--- SIMULATION PARAMETERS ------------------------------------------------------------------------ const int DIM = 50; //size of simulation grid @@ -97,7 +83,6 @@ void init_simulation(int n) float LightAmbient[] = { 0.25f, 0.25f, 0.25f, 1.0f }; // Ambient light values float LightPosition[] = { 0.0f, 0.0f, -900.0f, 1.0f }; // Position of the light source int i; size_t dim; - GLUquadricObj *qobj; dim = n * 2*(n/2+1)*sizeof(fftw_real); //Allocate data structures vx = (fftw_real*) malloc(dim); @@ -137,15 +122,6 @@ void init_simulation(int n) glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); - - startList = glGenLists(2); - qobj = gluNewQuadric(); - - gluQuadricDrawStyle(qobj, GLU_FILL); - gluQuadricNormals(qobj, GLU_SMOOTH); - glNewList(startList, GL_COMPILE); - gluCylinder(qobj, 10, 0.2, 8, 8, 8); - glEndList(); } int rescale_to_winwidth(float value) @@ -162,7 +138,9 @@ void FFT(int direction,void* vx) } int clamp(float x) -{ return ((x)>=0.0?((int)(x)):(-((int)(1-(x))))); } +{ + return ((x)>=0.0?((int)(x)):(-((int)(1-(x))))); +} //solve: Solve (compute) one step of the fluid flow simulation void solve(int n, fftw_real* vx, fftw_real* vy, fftw_real* vx0, fftw_real* vy0, fftw_real visc, fftw_real dt) @@ -294,19 +272,15 @@ void copy_frame(void) switch (vis_dataset) { case DATASET_FORCE: - // hight_array[i] = sqrt(fx[i] * fx[i] + fy[i] * fy[i]) * 100; break; case DATASET_VEL: - // hight_array[i] = sqrt(vx[i] * vx[i] + vy[i] * vy[i]) * 2000; break; case DATASET_RHO: - // hight_array[i] = rho[i] * 10; memcpy(frame_hist[frame_index], rho, sizeof(DIM * 2 * (DIM / 2 + 1) * sizeof(fftw_real))); break; default: case DATASET_DIVV: case DATASET_DIVF: - // hight_array[i] = 0.0f; break; } frame_index = (frame_index + 1) % DIM; @@ -374,8 +348,6 @@ float remap(float value) value -= scale_min; value /= (scale_max - scale_min); - //value = (value < 0) ? 0 : (value > 1) ? 1 : value; - return value; } @@ -485,7 +457,6 @@ 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 klote = 0; return_value = 0; @@ -534,143 +505,6 @@ void set_autoscaling(void) //rho_threshold = (scale_min + scale_max) / 2; } -void render_glyph(float x_value, float y_value, float i, float j) -{ - float x0, y0, z0, x1, y1, z1, x_dev, y_dev, z_dev, size, length; - float scale = (float)((float)DIM / (float)var_dims) / 6; - double theta, in_prod; - fftw_real wn, hn; - - size = sqrt((x_value * x_value * 20) + (y_value * y_value * 20)) * 3 * scale; - - wn = (fftw_real)winWidth / (fftw_real)(var_dims + 1); // Grid cell width - hn = (fftw_real)winHeight / (fftw_real)(var_dims + 1); // Grid cell heigh - - x0 = wn + (fftw_real)i * wn; - y0 = hn + (fftw_real)j * hn; - z0 = 0.0f; - - x1 = x0 + (vec_scale * x_value)/4; - y1 = y0 + (vec_scale * y_value)/4; - z1 = 0.0f; - - // inner product - x_dev = x1 - x0; - y_dev = y1 - y0; - length = sqrt(x_dev * x_dev + y_dev * y_dev); - - x_dev = (length == 0) ? 0 : x_dev / length; - y_dev = (length == 0) ? 1 : y_dev / length; - - in_prod = x_dev * 0 + y_dev * 1; - theta = acos(in_prod) * (180/3.141592654); - if (x1 > x0) { theta *= -1; } - - switch(glyph_sort) - { - default: - case GLYPH_LINES: - glBegin(GL_LINES); - glVertex3f(x0, y0, z0); - glVertex3f(x1, y1, z0); - glEnd(); - break; - - case GLYPH_ARROWS: - glPushMatrix(); - glTranslatef(x0, y0, z0); - glRotatef(theta, 0.0, 0.0, 1.0); - glTranslatef(-x0, -y0, -z0); - - glBegin(GL_TRIANGLES); - glVertex2d(-10 * size + x0, -25 * size + y0); - glVertex2d( 0 * size + x0, 25 * size + y0); - glVertex2d( 10 * size + x0, -25 * size + y0); - glEnd(); - - glRotatef(-theta, 0.0, 0.0, 1.0); - glPopMatrix(); - break; - - case GLYPH_CYLINDERS: - x_dev = x1 - x0; - y_dev = y1 - y0; - length = sqrt(x_dev * x_dev + y_dev * y_dev) / 8; - - glPushMatrix(); - - glTranslatef(x0, y0, -1.0); - glRotatef(theta, 0.0, 0.0, 1.0); - glRotatef(-90, 1.0, 0.0, 0.0); - glScalef(length, length, length); - glCallList(startList); - - glPopMatrix(); - break; - - case GLYPH_SPHERES: - glPushMatrix(); - - glTranslatef(x0, y0, -1.0); - glRotatef(theta, 0.0, 0.0, 1.0); - glRotatef(-90, 1.0, 0.0, 0.0); - glScalef(length, length, length); - glCallList(startList); - - glPopMatrix(); - break; - } -} - -void draw_glyphs(void) -{ - int i, j, idx; - float value, scale, idxcf, idxrf; - - if (use_glyphs) - { - scale = (float)((float)DIM / (float)var_dims); - for (i = 0; i < var_dims; i++) - { - for (j = 0; j < var_dims; j++) - { - idxcf = round(j * scale) * DIM; - idxrf = round(i * scale); - idx = idxcf + idxrf; - - switch (glyph_scalar) - { - default: - case SCALAR_RHO: - value = rho[idx]; - break; - - case SCALAR_VEL: - value = vec_len(vx[idx], vy[idx]); - break; - - case SCALAR_FORCE: - value = vec_len(fx[idx], fy[idx]); - break; - } - - set_colormap(value, FALSE, 0.5f); - switch (glyph_vector) - { - default: - case VECTOR_VEL: - render_glyph(vx[idx], vy[idx], i, j); - break; - - case VECTOR_FORCE: - render_glyph(fx[idx], fy[idx], i, j); - break; - } - } - } - } -} - #define percentage(a, b) (min(a, b) / max(a, b)) void draw_isolines(float threshold) @@ -786,8 +620,6 @@ void draw_isolines(float threshold) glEnd(); } -//W - //visualize: This is the main visualization function void visualize(void) { @@ -1101,11 +933,13 @@ void drag(int mx, int my) } } -void zoom_in(void) { +void zoom_in(void) +{ z_pos += 20; } -void zoom_out(void) { +void zoom_out(void) +{ z_pos -= 20; } @@ -1123,3 +957,25 @@ void toggle_mouse_rotate(void) { rotate_plane = (rotate_plane) ? FALSE : TRUE; void toggle_seed_insert(void) { seed_insert = (seed_insert) ? FALSE : TRUE; } void set_glyph_scalar(int arg) { glyph_scalar = arg; } void set_glyph_vector(int arg) { glyph_vector = arg; } + +// getters and setters + +int get_var_dims(void) +{ + return var_dims; +} + +void set_var_dims(int dims) +{ + var_dims = dims; +} + +int get_glyph_sort(void) +{ + return glyph_sort; +} + +void set_glyph_sort(int sort) +{ + glyph_sort = sort; +}
\ No newline at end of file |