summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilrik de Loose <wilrik@wilrik.nl>2007-12-20 12:33:17 (GMT)
committerWilrik de Loose <wilrik@wilrik.nl>2007-12-20 12:33:17 (GMT)
commit41c695d027b1b1d64015a62c58ad6cf00ac49833 (patch)
tree11e614917caf61f2a5957b6f87fb91a728923c21
parent6738787ce32ab3895241efed640cb95cdb3d1e32 (diff)
download2iv35-41c695d027b1b1d64015a62c58ad6cf00ac49833.zip
2iv35-41c695d027b1b1d64015a62c58ad6cf00ac49833.tar.gz
2iv35-41c695d027b1b1d64015a62c58ad6cf00ac49833.tar.bz2
-rw-r--r--Smoke/Week 2.ncbbin15518720 -> 15518720 bytes
-rw-r--r--Smoke/Week 2.suobin45056 -> 45056 bytes
-rw-r--r--Smoke/colormap.h4
-rw-r--r--Smoke/fluids.c2
-rw-r--r--Smoke/funcs.c7
-rw-r--r--Smoke/funcs.h3
-rw-r--r--Smoke/renderer_gl.c85
7 files changed, 89 insertions, 12 deletions
diff --git a/Smoke/Week 2.ncb b/Smoke/Week 2.ncb
index d061b17..1c906ff 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 13ef118..5c40e13 100644
--- a/Smoke/Week 2.suo
+++ b/Smoke/Week 2.suo
Binary files differ
diff --git a/Smoke/colormap.h b/Smoke/colormap.h
index ef6de52..81eb828 100644
--- a/Smoke/colormap.h
+++ b/Smoke/colormap.h
@@ -28,8 +28,8 @@ float colormap_get_clamp_min(void);
void colormap_set_clamp_max(float max_clamp);
float colormap_get_clamp_max(void);
-void colormap_set_frame(fftw_real *frame);
-fftw_real *colormap_get_frame(void);
+//void colormap_set_frame(fftw_real *frame);
+//fftw_real *colormap_get_frame(void);
struct color4f colormap_get_color(float value);
diff --git a/Smoke/fluids.c b/Smoke/fluids.c
index 5027700..4aa4b0e 100644
--- a/Smoke/fluids.c
+++ b/Smoke/fluids.c
@@ -446,7 +446,7 @@ void drag(int mx, int my)
// Add force at the cursor location
my = winHeight - my;
dx = mx - lmx; dy = my - lmy;
- len = vec_len(dx, dy);
+ len = vec_len2f(dx, dy);
if (len != 0.0) { dx *= 0.1 / len; dy *= 0.1 / len; }
fx[Y * DIM + X] += dx;
fy[Y * DIM + X] += dy;
diff --git a/Smoke/funcs.c b/Smoke/funcs.c
index e760c72..a991e42 100644
--- a/Smoke/funcs.c
+++ b/Smoke/funcs.c
@@ -23,7 +23,12 @@ float quake_root(float number)
return number * y;
}
-float vec_len(float x, float y)
+float vec_len2f(float x, float y)
{
return (quake_root((x * x) + (y * y)));
}
+
+float vec_len3f(float x, float y, float z)
+{
+ return (quake_root((x * x) + (y * y) + (z * z)));
+}
diff --git a/Smoke/funcs.h b/Smoke/funcs.h
index cfb0000..f4c4884 100644
--- a/Smoke/funcs.h
+++ b/Smoke/funcs.h
@@ -18,6 +18,7 @@
#define TRUE !FALSE
float quake_root(float number);
-float vec_len(float x, float y);
+float vec_len2f(float x, float y);
+float vec_len3f(float x, float y, float z);
#endif
diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c
index c5bf71c..2906125 100644
--- a/Smoke/renderer_gl.c
+++ b/Smoke/renderer_gl.c
@@ -35,13 +35,42 @@ float xPos = -298.0f;
float yPos = -295.0f;
float zPos = -725.0f;
+void vector_normal(struct point vert1, struct point vert2, struct point vert3, struct point *normal)
+{
+ struct point v1, v2;
+ float length;
+
+ v1.x = vert1.x - vert2.x;
+ v1.y = vert1.y - vert2.y;
+ v1.z = vert1.z - vert2.z;
+
+ v2.x = vert2.x - vert3.x;
+ v2.y = vert2.y - vert3.y;
+ v2.z = vert2.z - vert3.z;
+
+ normal->x = v1.y * v2.z - v1.z * v2.y;
+ normal->y = v1.z * v2.x - v1.x * v2.z;
+ normal->z = v1.x * v2.y - v1.y * v2.x;
+
+ length = vec_len3f(normal->x, normal->y, normal->z);
+
+ if(length == 0.0f)
+ length = 1.0f;
+
+ normal->x /= length;
+ normal->y /= length;
+ normal->z /= length;
+}
+
static void render_legend(void)
{
int i;
struct color4f color;
- for (i = 0; i < winWidth; i++)
+ glDisable(GL_LIGHTING);
+
+ for (i = 0; i < winWidth; i++)
{
float value, clamp_scaled_min, clamp_scaled_max, scale_scaled_min, scale_scaled_max;
@@ -108,6 +137,8 @@ static void render_legend(void)
}
glEnd();
}
+
+ glEnable(GL_LIGHTING);
}
@@ -117,6 +148,9 @@ static void render_smoke(void)
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
struct color4f color;
+ struct point vert[3];
+ struct point normal;
+ int vert_nr = 0;
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
@@ -129,9 +163,13 @@ static void render_smoke(void)
py = hn + (fftw_real)j * hn;
idx = (j * DIM) + i;
- glNormal3f(0.0f, 1.0f, 0.0f);
glColor3f(rho[idx],rho[idx],rho[idx]);
glVertex3f(px,py, height_array[idx]); // vertex 1
+
+ vert[0].x = px;
+ vert[0].y = px;
+ vert[0].z = height_array[idx];
+ vert_nr++;
for (i = 0; i < DIM - 1; i++)
{
@@ -141,12 +179,37 @@ static void render_smoke(void)
color = colormap_get_color(get_dataset(idx));
glColor4f(color.r, color.g, color.b, color.a);
glVertex3f(px, py, height_array[idx]); // vertex i + 1
+
+ if (vert_nr > 2)
+ {
+ vert[vert_nr % 3].x = px;
+ vert[vert_nr % 3].y = px;
+ vert[vert_nr % 3].z = height_array[idx];
+ } vert_nr++;
+
+ if (vert_nr % 3 == 0)
+ {
+ vector_normal(vert[0], vert[1], vert[2], &normal);
+ glNormal3f(normal.x, normal.y, normal.z);
+ }
+
px = wn + (fftw_real)(i + 1) * wn;
py = hn + (fftw_real)j * hn;
idx = (j * DIM) + (i + 1);
color = colormap_get_color(get_dataset(idx));
glColor4f(color.r, color.g, color.b, color.a);
glVertex3f(px, py, height_array[idx]); // vertex i + 2
+
+ vert[vert_nr % 3].x = px;
+ vert[vert_nr % 3].y = px;
+ vert[vert_nr % 3].z = height_array[idx];
+ vert_nr++;
+
+ if (vert_nr % 3 == 0)
+ {
+ vector_normal(vert[0], vert[1], vert[2], &normal);
+ glNormal3f(normal.x, normal.y, normal.z);
+ }
}
px = wn + (fftw_real)(DIM - 1) * wn;
@@ -155,6 +218,14 @@ static void render_smoke(void)
color = colormap_get_color(get_dataset(idx));
glColor4f(color.r, color.g, color.b, color.a);
glVertex3f(px, py, height_array[idx]); // vertex j
+ vert_nr++;
+
+ if (vert_nr % 3 == 0)
+ {
+ vector_normal(vert[0], vert[1], vert[2], &normal);
+ glNormal3f(normal.x, normal.y, normal.z);
+ }
+
glEnd();
}
}
@@ -269,11 +340,11 @@ static void render_glyphs(void)
break;
case SCALAR_VEL:
- value = vec_len(vx[idx], vy[idx]);
+ value = vec_len2f(vx[idx], vy[idx]);
break;
case SCALAR_FORCE:
- value = vec_len(fx[idx], fy[idx]);
+ value = vec_len2f(fx[idx], fy[idx]);
break;
}
@@ -514,9 +585,9 @@ void render_flowvis(fftw_real *field)
void init_gl(void)
{
- float LightAmbient[] = { 0.25f, 0.25f, 0.25f, 1.00f }; // Ambient light values
- float LightDiffuse[] = { 0.80f, 0.00f, 0.00f, 1.00f }; // Diffuse light values
- float LightPosition[] = { 0.0f, 0.0f, -700.0f, 1.00f }; // Position of the light source
+ float LightAmbient[] = { 0.25f, 0.25f, 0.25f, 1.00f }; // Ambient light values
+ float LightDiffuse[] = { 0.50f, 0.50f, 0.50f, 1.00f }; // Diffuse light values
+ float LightPosition[] = { 0.0f, 400.0f, -700, 1.00f }; // Position of the light source
glShadeModel(GL_SMOOTH); // Enable smooth shading
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black background