diff options
author | Wilrik de Loose <wilrik@wilrik.nl> | 2008-01-03 13:11:52 (GMT) |
---|---|---|
committer | Wilrik de Loose <wilrik@wilrik.nl> | 2008-01-03 13:11:52 (GMT) |
commit | e1b9274194fcb0e5054948917628c5e1022b42c2 (patch) | |
tree | 9e6dfcebf178209df2a44d2656d42084583de108 | |
parent | 26824e6de9ff2a591a02770f19006d186b2e1c71 (diff) | |
download | 2iv35-e1b9274194fcb0e5054948917628c5e1022b42c2.zip 2iv35-e1b9274194fcb0e5054948917628c5e1022b42c2.tar.gz 2iv35-e1b9274194fcb0e5054948917628c5e1022b42c2.tar.bz2 |
-rw-r--r-- | Smoke/Week 2.ncb | bin | 15518720 -> 15518720 bytes | |||
-rw-r--r-- | Smoke/Week 2.suo | bin | 52736 -> 56832 bytes | |||
-rw-r--r-- | Smoke/Week 2.vcproj | 16 | ||||
-rw-r--r-- | Smoke/fluids.c | 21 | ||||
-rw-r--r-- | Smoke/funcs.h | 2 | ||||
-rw-r--r-- | Smoke/renderer_gl.c | 332 |
6 files changed, 202 insertions, 169 deletions
diff --git a/Smoke/Week 2.ncb b/Smoke/Week 2.ncb Binary files differindex a2ce9f8..cb81cd8 100644 --- a/Smoke/Week 2.ncb +++ b/Smoke/Week 2.ncb diff --git a/Smoke/Week 2.suo b/Smoke/Week 2.suo Binary files differindex 3f0e660..846d2e6 100644 --- a/Smoke/Week 2.suo +++ b/Smoke/Week 2.suo diff --git a/Smoke/Week 2.vcproj b/Smoke/Week 2.vcproj index 8a0b563..2c7c4db 100644 --- a/Smoke/Week 2.vcproj +++ b/Smoke/Week 2.vcproj @@ -751,6 +751,10 @@ >
</File>
<File
+ RelativePath=".\interact.c"
+ >
+ </File>
+ <File
RelativePath=".\isolines.c"
>
</File>
@@ -916,6 +920,10 @@ >
</File>
<File
+ RelativePath=".\interact.h"
+ >
+ </File>
+ <File
RelativePath=".\isolines.h"
>
</File>
@@ -958,19 +966,19 @@ >
</File>
<File
- RelativePath="fftw-2.1.3\rfftw\Makefile.am"
+ RelativePath="fftw-2.1.3\fftw\Makefile.am"
>
</File>
<File
- RelativePath="fftw-2.1.3\fftw\Makefile.am"
+ RelativePath="fftw-2.1.3\rfftw\Makefile.am"
>
</File>
<File
- RelativePath="fftw-2.1.3\fftw\Makefile.in"
+ RelativePath="fftw-2.1.3\rfftw\Makefile.in"
>
</File>
<File
- RelativePath="fftw-2.1.3\rfftw\Makefile.in"
+ RelativePath="fftw-2.1.3\fftw\Makefile.in"
>
</File>
<File
diff --git a/Smoke/fluids.c b/Smoke/fluids.c index 7476a6d..5e1f7a6 100644 --- a/Smoke/fluids.c +++ b/Smoke/fluids.c @@ -237,6 +237,11 @@ void vector_normal(struct point vert1, struct point vert2, struct point vert3, s normal->x /= length; normal->y /= length; normal->z /= length; + + if (normal->x == normal->y == normal->z == 0.0f) + { + normal->z = 1.0f; + } } @@ -244,6 +249,10 @@ void calculate_normal_vectors(void) { int i; struct point p1, p2, p3; + float 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 for (i = 0; i < DIM * DIM; i++) { @@ -268,13 +277,13 @@ void calculate_normal_vectors(void) p1.y = vy[i]; p1.z = height_array[i]; - p2.x = vx[i + 1]; - p2.y = vy[i + 1]; - p2.z = height_array[i + 1]; + p3.x = vx[i + 1]; + p3.y = vy[i + 1]; + p3.z = height_array[i + 1]; - p3.x = vx[i + DIM]; - p3.y = vy[i + DIM]; - p3.z = height_array[i + DIM]; + p2.x = vx[i + DIM]; + p2.y = vy[i + DIM]; + p2.z = height_array[i + DIM]; break; case DATASET_RHO: diff --git a/Smoke/funcs.h b/Smoke/funcs.h index f4c4884..7f1370e 100644 --- a/Smoke/funcs.h +++ b/Smoke/funcs.h @@ -12,8 +12,6 @@ #define round(x) (int)(x < 0 ? x - 0.5 : x + 0.5)
-#define percentage(a, b) (min(a, b) / max(a, b))
-
#define FALSE 0
#define TRUE !FALSE
diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c index ff8e908..c2c5a87 100644 --- a/Smoke/renderer_gl.c +++ b/Smoke/renderer_gl.c @@ -47,6 +47,7 @@ float y_pos = DEFAULT_Y_POS; float z_pos = DEFAULT_ZOOM; static int renderer_zoomspeed = DEFAULT_ZOOM_SPEED; +static int normals_render = TRUE; static void render_legend(void) { @@ -128,6 +129,35 @@ static void render_legend(void) glEnable(GL_LIGHTING); } +static void render_normal(void) +{ + 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 + float normal_scale = 10.0f; + + glDisable(GL_LIGHTING); + glBegin(GL_LINES); + glColor3f(1.0f, 0.2f, 0.0f); + + for (i = 0; i < DIM - 1; i++) + { + for (j = 0; j < DIM - 1; j++) + { + idx = (j * DIM) + i; + px = wn + (fftw_real)i * wn; + py = hn + (fftw_real)(j + 1) * hn; + + glVertex3f(px, py, height_array[idx]); + glVertex3f(px + normal_array[idx].x * normal_scale, + py + normal_array[idx].y * normal_scale, + height_array[idx] + normal_array[idx].z * normal_scale); + } + } + glEnable(GL_LIGHTING); + glEnd(); +} + static void render_smoke(void) { @@ -138,6 +168,8 @@ static void render_smoke(void) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + //glDisable(GL_LIGHTING); + for (j = 0; j < DIM - 1; j++) //draw smoke { glBegin(GL_TRIANGLE_STRIP); @@ -331,161 +363,142 @@ static void render_isolines(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 - if (glyph_scalar == SCALAR_RHO) - { - int count; - float iso_scale; + int count; + float iso_scale; - if (isolines_nr) { - iso_scale = (float)(fabs(threshold1 - threshold2) / (float)isolines_nr); - } else { - iso_scale = 0.0f; - } + if (isolines_nr) { + iso_scale = (float)(fabs(threshold1 - threshold2) / (float)isolines_nr); + } else { + iso_scale = 0.0f; + } - for (count = 0; count < isolines_nr; count++) + for (count = 0; count < isolines_nr; count++) + { + int idx; + int i, j; + float v0, v1, v2, v3; + float x0, y0, x1, y1, x_offset, y_offset; + int state = 0; + static int prev_state = 0; + struct color4f color; + float threshold; + + v0 = v1 = v2 = v3 = 0.0f; + x0 = y0 = x1 = y1 = 0.0f; + + threshold = min(threshold1, threshold2) + count * iso_scale; + + glDisable(GL_LIGHTING); + + glLineWidth(2.0f); + glBegin(GL_LINES); + + for (i = 0; i < DIM - 1; i++) { - int idx; - int i, j; - float v0, v1, v2, v3; - float x0, y0, x1, y1, x_offset, y_offset; - int state = 0; - static int prev_state = 0; - struct color4f color; - float threshold; - - v0 = v1 = v2 = v3 = 0.0f; - x0 = y0 = x1 = y1 = 0.0f; - - threshold = min(threshold1, threshold2) + count * iso_scale; - - glDisable(GL_LIGHTING); - - glLineWidth(2.0f); - glBegin(GL_LINES); - - for (i = 0; i < DIM - 1; i++) + for (j = 0; j < DIM - 1; j++) { - for (j = 0; j < DIM - 1; j++) + state = 0; + idx = (j * DIM) + i; + color = isolines_get_color(get_dataset(idx)); + //glColor4f(color.r, color.g, color.b, color.a); + glColor3f(1.0f, 0.0f, 0.0f); + + v0 = get_dataset(idx + DIM); + v1 = get_dataset(idx + 1 + DIM); + v2 = get_dataset(idx + 1); + v3 = get_dataset(idx); + + if (v0 >= threshold) { state += 1; } + if (v1 >= threshold) { state += 2; } + if (v2 >= threshold) { state += 4; } + if (v3 >= threshold) { state += 8; } + + x_offset = wn + (fftw_real)i * wn; + y_offset = hn + (fftw_real)j * hn; + + switch (state) { - state = 0; - idx = (j * DIM) + i; - color = isolines_get_color(get_dataset(idx)); - //glColor4f(color.r, color.g, color.b, color.a); - glColor3f(1.0f, 0.0f, 0.0f); - - v0 = get_dataset(idx + DIM); - v1 = get_dataset(idx + 1 + DIM); - v2 = get_dataset(idx + 1); - v3 = get_dataset(idx); - - if (v0 >= threshold) { state += 1; } - if (v1 >= threshold) { state += 2; } - if (v2 >= threshold) { state += 4; } - if (v3 >= threshold) { state += 8; } - - x_offset = wn + (fftw_real)i * wn; - y_offset = wn + (fftw_real)j * hn; - - switch (state) - { - case 5: - case 10: - x0 = 0; - //y0 = percentage(fabs(v3 - v0), threshold) * hn; - //x1 = percentage(fabs(v1 - v0), threshold) * wn; - y0 = 0.5f * hn; - x1 = 0.5f * wn; - //y0 = percentage(max(v3, v0) - min(v3, v0), threshold) * hn; - //x1 = percentage(max(v1, v0) - min(v1, v0), threshold) * wn; - y1 = hn; - if (x0 != y0 != x1 != y1 != 0.0f) { - glVertex3i(x_offset + x0, y_offset + y0, 5.0f); - glVertex3i(x_offset + x1, y_offset + y1, 5.0f); - } - // no break !! - case 4: - case 11: - //x0 = percentage(fabs(v3 - v2), threshold) * wn; - //x0 = percentage(max(v3, v0) - min(v3, v2), threshold) * wn; - x0 = 0.5f * wn; - y0 = 0; - x1 = wn; - //y1 = percentage(fabs(v2 - v1), threshold) * hn; - //y1 = percentage(max(v2, v1) - min(v2, v1), threshold) * hn; - y1 = 0.5f * hn; - break; - case 6: - case 9: - //x0 = percentage(fabs(v3 - v2), threshold) * wn; - //x0 = percentage(max(v3, v2) - min(v3, v2), threshold) * wn; - x0 = 0.5f * wn; - y0 = 0; - //x1 = percentage(fabs(v1 - v0), threshold) * wn; - //x1 = percentage(max(v1, v0) - min(v1, v0), threshold) * wn; - x1 = 0.5f * wn; - y1 = hn; - break; - case 7: - case 8: - //x0 = percentage(fabs(v3 - v2), threshold) * wn; - //x0 = percentage(max(v3, v2) - min(v3, v2), threshold) * wn; - x0 = 0.5f * wn; - y0 = 0; - x1 = 0; - //y1 = percentage(fabs(v3 - v0), threshold) * hn; - //y1 = percentage(max(v3, v0) - min(v3, v0), threshold) * hn; - y1 = 0.5f * hn; - break; - case 3: - case 12: - x0 = 0; - //y0 = percentage(fabs(v3 - v0), threshold) * hn; - //y0 = percentage(max(v3, v0) - min(v3, v0), threshold) * hn; - y0 = 0.5f * hn; - x1 = wn; - //y1 = percentage(fabs(v2 - v1), threshold) * hn; - //y1 = percentage(max(v2, v1) - min(v2, v1), threshold) * hn; - y1 = 0.5f * hn; - break; - case 2: - case 13: - //x0 = percentage(fabs(v1 - v0), threshold) * wn; - //x0 = percentage(max(v1, v0) - min(v1, v0), threshold) * wn; - x0 = 0.5f * wn; - y0 = hn; - x1 = wn; - //y1 = percentage(fabs(v2 - v1), threshold) * hn; - //y1 = percentage(max(v2, v1) - min(v2, v1), threshold) * hn; - y1 = 0.5f * hn; - break; - case 1: - case 14: - x0 = 0; - //y0 = percentage(fabs(v3 - v0), threshold) * hn; - //x1 = percentage(fabs(v1 - v0), threshold) * wn; - //y0 = percentage(max(v3, v0) - min(v3, v0), threshold) * hn; - //x1 = percentage(max(v1, v0) - min(v1, v0), threshold) * wn; - y0 = 0.5f * hn; - x1 = 0.5f * wn; - y1 = hn; - break; - case 0: case 15: default: - x0 = y0 = x1 = y1 = 0.0f; - break; - } - - // draw line - if (x0 != y0 != x1 != y1 != 0.0f) - { - glVertex3i(x_offset + x0, y_offset + y0, 5.0f); - glVertex3i(x_offset + x1, y_offset + y1, 5.0f); - } - + case 5: + case 10: + //y0 = 0.5f * hn; + //x1 = 0.5f * wn; + x0 = 0; + y0 = (threshold / max(v3, v0)) * hn; + x1 = (threshold / max(v1, v0)) * wn; + y1 = hn; + + if (x0 != y0 != x1 != y1 != 0.0f) + { + glVertex3i(x_offset + x0, y_offset + y0, 5.0f); + glVertex3i(x_offset + x1, y_offset + y1, 5.0f); + } + // no break !! + case 4: + case 11: + //x0 = 0.5f * wn; + //y1 = 0.5f * hn; + x0 = (threshold / max(v3, v2)) * wn; + y0 = 0; + x1 = wn; + y1 = (threshold / max(v2, v1)) * hn; + break; + case 6: + case 9: + //x0 = 0.5f * wn; + //x1 = 0.5f * wn; + x0 = (threshold / max(v3, v2)) * wn; + y0 = 0; + x1 = (threshold / max(v1, v0)) * wn; + y1 = hn; + break; + case 7: + case 8: + //x0 = 0.5f * wn; + //y1 = 0.5f * hn; + x0 = (threshold / max(v3, v2)) * wn; + y0 = 0; + x1 = 0; + y1 = (threshold / max(v3, v0)) * hn; + break; + case 3: + case 12: + //y0 = 0.5f * hn; + //y1 = 0.5f * hn; + x0 = 0; + y0 = (threshold / max(v3, v0)) * hn; + x1 = wn; + y1 = (threshold / max(v2, v1)) * hn; + break; + case 2: + case 13: + //x0 = 0.5f * wn; + //y1 = 0.5f * hn; + x0 = (threshold / max(v1, v0)) * wn; + y0 = hn; + x1 = wn; + y1 = (threshold / max(v2, v1)) * hn; + break; + case 1: + case 14: + //y0 = 0.5f * hn; + //x1 = 0.5f * wn; + x0 = 0; + y0 = (threshold / max(v3, v0)) * hn; + x1 = (threshold / max(v1, v0)) * wn; + y1 = hn; + break; + case 0: case 15: default: + x0 = y0 = x1 = y1 = 0.0f; + break; } - } - glEnd(); + // draw line + glVertex3i(x_offset + x0 + 0.2f, y_offset + y0 + 0.2f, 5.0f); + glVertex3i(x_offset + x1 + 0.2f, y_offset + y1 + 0.2f, 5.0f); + } } + + glEnd(); } glEnable(GL_LIGHTING); } @@ -574,9 +587,9 @@ void render_flowvis(fftw_real *field) void renderer_init_gl(void) { - 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 + float LightAmbient[] = { 0.00f, 0.00f, 0.00f, 1.00f }; // Ambient light values + float LightDiffuse[] = { 0.80f, 0.50f, 0.50f, 0.00f }; // Diffuse light values + float LightPosition[] = { -300.0f, -300.0f, -500.0f, 1.00f }; // Position of the light source glShadeModel(GL_SMOOTH); // Enable smooth shading glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black background @@ -651,20 +664,16 @@ void renderer_reset_roll(void) //visualize: This is the main visualization function void visualize(fftw_real *field) { - 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 + render_legend(); - render_legend(); - - /* Rotate field - */ + // Rotate field glLoadIdentity(); glTranslatef(x_pos, y_pos, z_pos); glRotatef(x_rot, 1.0f, 0.0f, 0.0f); glRotatef(y_rot, 0.0f, 1.0f, 0.0f); glRotatef(z_rot, 0.0f, 0.0f, 1.0f); - glTranslatef(-(wn*DIM)/2, -(hn*DIM)/2, 0.0f); + glTranslatef(-winWidth/2, -winHeight/2, 0.0f); if (isolines_get_render()) { render_isolines(); @@ -687,4 +696,13 @@ void visualize(fftw_real *field) if (flowvis_get_render()) { render_flowvis(field); } + + if (normals_get_render()) { + render_normal(); + } +} + +int normals_get_render(void) +{ + return normals_render; } |