summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilrik de Loose <wilrik@wilrik.nl>2007-12-14 08:35:25 (GMT)
committerWilrik de Loose <wilrik@wilrik.nl>2007-12-14 08:35:25 (GMT)
commit5601182e9456b3d4d782f135c8b151f5d9b021cd (patch)
treefe9e06a8a0f572dad622e8887732796a725887fe
parent2b49eb5eb684537c19d9f0eabdffad0ffcf196ac (diff)
download2iv35-5601182e9456b3d4d782f135c8b151f5d9b021cd.zip
2iv35-5601182e9456b3d4d782f135c8b151f5d9b021cd.tar.gz
2iv35-5601182e9456b3d4d782f135c8b151f5d9b021cd.tar.bz2
glyphs apart in een file gestopt
-rw-r--r--Smoke/Week 2.ncbbin14887936 -> 15518720 bytes
-rw-r--r--Smoke/Week 2.suobin26112 -> 28672 bytes
-rw-r--r--Smoke/Week 2.vcproj16
-rw-r--r--Smoke/fluids.c208
-rw-r--r--Smoke/fluids.h43
-rw-r--r--Smoke/funcs.c29
-rw-r--r--Smoke/funcs.h14
-rw-r--r--Smoke/glyphs.c156
-rw-r--r--Smoke/glyphs.h6
9 files changed, 296 insertions, 176 deletions
diff --git a/Smoke/Week 2.ncb b/Smoke/Week 2.ncb
index 73d9e5f..99fd4a7 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 3b8e114..0058556 100644
--- a/Smoke/Week 2.suo
+++ b/Smoke/Week 2.suo
Binary files differ
diff --git a/Smoke/Week 2.vcproj b/Smoke/Week 2.vcproj
index e0d727c..261e15c 100644
--- a/Smoke/Week 2.vcproj
+++ b/Smoke/Week 2.vcproj
@@ -687,10 +687,18 @@
>
</File>
<File
+ RelativePath=".\funcs.c"
+ >
+ </File>
+ <File
RelativePath="fftw-2.1.3\fftw\generic.c"
>
</File>
<File
+ RelativePath=".\glyphs.c"
+ >
+ </File>
+ <File
RelativePath=".\gtk.c"
>
</File>
@@ -784,6 +792,14 @@
>
</File>
<File
+ RelativePath=".\funcs.h"
+ >
+ </File>
+ <File
+ RelativePath=".\glyphs.h"
+ >
+ </File>
+ <File
RelativePath="fftw-2.1.3\rfftw\rfftw.h"
>
</File>
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
diff --git a/Smoke/fluids.h b/Smoke/fluids.h
index 7e306f7..96dd64f 100644
--- a/Smoke/fluids.h
+++ b/Smoke/fluids.h
@@ -1,3 +1,10 @@
+#ifndef _FLUIDS_H
+#define _FLUIDS_H
+
+#include <rfftw.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+
//--- SIMULATION PARAMETERS ------------------------------------------------------------------------
extern const int DIM; //size of simulation grid
@@ -86,8 +93,37 @@ void calculate_one_simulation_step(void);
int get_glyph_usage(void);
+//////////////////
+
+void init_simulation(int n);
+int rescale_to_winwidth(float value);
+void FFT(int direction,void* vx);
+int clamp(float x);
+void solve(int n, fftw_real* vx, fftw_real* vy, fftw_real* vx0, fftw_real* vy0, fftw_real visc, fftw_real dt);
+void diffuse_matter(int n, fftw_real *vx, fftw_real *vy, fftw_real *rho, fftw_real *rho0, fftw_real dt);
+void set_forces(void);
+void calculate_hight_plot(void);
+void copy_frame(void);
+void calculate_one_simulation_step(void);
+void rainbow(float value,float* R,float* G,float* B);
+void colormap_fire(float value,float* R,float* G,float* B);
+float remap(float value);
+struct color4f set_colormap(float vy, int draw_bar, float alpha);
+void direction_to_color(float x, float y, int method);
+float get_dataset(int index);
+void set_autoscaling(void);
+void draw_isolines(float threshold);
+void visualize(void);
+void keyboard(unsigned char key, int x, int y);
+void click(int button, int state, int mx, int my);
+void mouse_rotate(int mx, int my);
+void drag(int mx, int my);
+
+//////////////////
+
void zoom_in(void);
void zoom_out(void);
+int get_glyph_usage(void);
void selectColor(int arg);
void selectOliverscolor(int arg);
void select_dataset(int arg);
@@ -101,6 +137,11 @@ void toggle_seed_insert(void);
void set_glyph_scalar(int arg);
void set_glyph_vector(int arg);
+int get_var_dims(void);
+void set_var_dims(int);
+int get_glyph_sort(void);
+void set_glyph_sort(int sort);
+
struct point {
float x;
float y;
@@ -113,3 +154,5 @@ struct color4f {
float b;
float a;
};
+
+#endif \ No newline at end of file
diff --git a/Smoke/funcs.c b/Smoke/funcs.c
new file mode 100644
index 0000000..eb8cc2d
--- /dev/null
+++ b/Smoke/funcs.c
@@ -0,0 +1,29 @@
+// Includes
+
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN 1
+#include <windows.h>
+#endif
+
+#include "funcs.h"
+
+float square_root(float number)
+{
+ long i;
+ float x, y;
+ const float f = 1.5f;
+
+ x = number * 0.5f;
+ y = number;
+ i = * ( long * ) &y;
+ i = 0x5f3759df - ( i >> 1 );
+ y = * ( float * ) &i;
+ y = y * ( f - ( x * y * y ) );
+ y = y * ( f - ( x * y * y ) );
+ return number * y;
+}
+
+float vec_len(float x, float y)
+{
+ return (square_root((x * x) + (y * y)));
+} \ No newline at end of file
diff --git a/Smoke/funcs.h b/Smoke/funcs.h
new file mode 100644
index 0000000..f21011f
--- /dev/null
+++ b/Smoke/funcs.h
@@ -0,0 +1,14 @@
+#ifndef _FUNCS_H
+#define _FUNCS_H
+
+#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 FALSE 0
+#define TRUE !FALSE
+
+float square_root(float number);
+float vec_len(float x, float y);
+
+#endif
diff --git a/Smoke/glyphs.c b/Smoke/glyphs.c
new file mode 100644
index 0000000..9dd2914
--- /dev/null
+++ b/Smoke/glyphs.c
@@ -0,0 +1,156 @@
+// Includes
+
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN 1
+#include <windows.h>
+#endif
+
+#include "fluids.h"
+#include "glyphs.h"
+#include "funcs.h"
+
+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)get_var_dims()) / 6;
+ double theta, in_prod;
+ fftw_real wn, hn;
+
+ GLuint startList = glGenLists(1);
+ GLUquadricObj *qobj = gluNewQuadric();
+
+ gluQuadricDrawStyle(qobj, GLU_FILL);
+ gluQuadricNormals(qobj, GLU_SMOOTH);
+ glNewList(startList, GL_COMPILE);
+ gluCylinder(qobj, 10, 0.2, 8, 8, 8);
+ glEndList();
+
+ size = sqrt((x_value * x_value * 20) + (y_value * y_value * 20)) * 3 * scale;
+
+ wn = (fftw_real)winWidth / (fftw_real)(get_var_dims() + 1); // Grid cell width
+ hn = (fftw_real)winHeight / (fftw_real)(get_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(get_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)get_var_dims());
+ for (i = 0; i < get_var_dims(); i++)
+ {
+ for (j = 0; j < get_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;
+ }
+ }
+ }
+ }
+}
diff --git a/Smoke/glyphs.h b/Smoke/glyphs.h
new file mode 100644
index 0000000..5d61d98
--- /dev/null
+++ b/Smoke/glyphs.h
@@ -0,0 +1,6 @@
+#ifndef _GLYPHS_H
+#define _GLYPHS_H
+
+void draw_glyphs(void);
+
+#endif