summaryrefslogtreecommitdiffstats
path: root/Smoke/glyphs.c
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 /Smoke/glyphs.c
parent2b49eb5eb684537c19d9f0eabdffad0ffcf196ac (diff)
download2iv35-5601182e9456b3d4d782f135c8b151f5d9b021cd.zip
2iv35-5601182e9456b3d4d782f135c8b151f5d9b021cd.tar.gz
2iv35-5601182e9456b3d4d782f135c8b151f5d9b021cd.tar.bz2
glyphs apart in een file gestopt
Diffstat (limited to 'Smoke/glyphs.c')
-rw-r--r--Smoke/glyphs.c156
1 files changed, 156 insertions, 0 deletions
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;
+ }
+ }
+ }
+ }
+}