diff options
author | Oliver Schinagl <oliver@schinagl.nl> | 2008-01-07 03:40:59 (GMT) |
---|---|---|
committer | Oliver Schinagl <oliver@schinagl.nl> | 2008-01-07 03:40:59 (GMT) |
commit | 8dc29e0202fb48c078aebf271b31e903a1076d95 (patch) | |
tree | 6c0dc33a9ddc7ce1fcee675df16fb70a785af95c /Smoke/fluids.c | |
parent | 5297d5f9565da695a6a9891f829118ecaea6ad8a (diff) | |
download | 2iv35-8dc29e0202fb48c078aebf271b31e903a1076d95.zip 2iv35-8dc29e0202fb48c078aebf271b31e903a1076d95.tar.gz 2iv35-8dc29e0202fb48c078aebf271b31e903a1076d95.tar.bz2 |
more normal drawing
Diffstat (limited to 'Smoke/fluids.c')
-rw-r--r-- | Smoke/fluids.c | 70 |
1 files changed, 54 insertions, 16 deletions
diff --git a/Smoke/fluids.c b/Smoke/fluids.c index dcf0a08..eece203 100644 --- a/Smoke/fluids.c +++ b/Smoke/fluids.c @@ -220,8 +220,9 @@ void set_forces(void) -void vector_normal(struct point vert1, struct point vert2, struct point vert3, struct point *normal) +struct point vector_normal(struct point vert1, struct point vert2, struct point vert3) { + struct point return_value; struct point v1, v2; float length; @@ -236,11 +237,11 @@ void vector_normal(struct point vert1, struct point vert2, struct point vert3, s v2.z = vert2.z - vert3.z; // calculate cross produkt - 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; + return_value.x = v1.y * v2.z - v1.z * v2.y; + return_value.y = v1.z * v2.x - v1.x * v2.z; + return_value.z = v1.x * v2.y - v1.y * v2.x; - length = vec_len3f(normal->x, normal->y, normal->z); + length = vec_len3f(return_value.x, return_value.y, return_value.z); if(length == 0.0f) { @@ -248,9 +249,11 @@ void vector_normal(struct point vert1, struct point vert2, struct point vert3, s } // normalize - normal->x /= length; - normal->y /= length; - normal->z /= length; + return_value.x /= length; + return_value.y /= length; + return_value.z /= length; + + return return_value; } @@ -283,17 +286,40 @@ void calculate_normal_vectors(void) p3.y = py; p3.z = height_array[idx + 1]; - vector_normal(p2, p1, p3, &normal_array[idx]); + normal_array[idx] = vector_normal(p2, p1, p3); } } } +struct point calculate_normal_vector(fftw_real *height, int index, int i, int j) +{ + struct point p1, p2, p3; + + 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 px = wn + (fftw_real)i * wn; + float py = hn + (fftw_real)(j + 1) * hn; + + p1.x = px; + p1.y = py + hn; + p1.z = height[index + DIM]; + + p2.x = px; + p2.y = py; + p2.z = height[index]; + + p3.x = px + wn; + p3.y = py; + p3.z = height[index + 1]; + + return vector_normal(p1, p2, p3); +} void calculate_height_plots(void) { int i; for (i = 0; i < DIM * DIM; i++) - { + { switch (vis_dataset) { case DATASET_FORCE: @@ -314,21 +340,29 @@ void calculate_height_plots(void) } } -void calculate_height_plot(struct vis_data_arrays *vis_data, int dataset, int index) +fftw_real calculate_height_plot(int dataset, int index) { + fftw_real return_value; + switch(dataset) { default: case DATASET_RHO: - vis_data->height[index] = rho[index]; + return_value = rho[index]; break; case DATASET_VEL: - vis_data->height[index] = vec_len2f(vx[index], vy[index]); + return_value = vec_len2f(vx[index], vy[index]); break; case DATASET_FORCE: - vis_data->height[index] = vec_len2f(fx[index], fy[index]); + return_value = vec_len2f(fx[index], fy[index]); + break; + case DATASET_DIVV: + case DATASET_DIVF: + return_value = 0.0f; break; } + + return return_value; } void copy_frames(fftw_real *dataset) @@ -347,7 +381,7 @@ void populate_arrays(struct vis_data_arrays *vis_data) 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 (j = 0; j < DIM; j++) { for (i = 0; i < DIM; i++) @@ -362,7 +396,11 @@ void populate_arrays(struct vis_data_arrays *vis_data) vis_data->div_force[idx] = par_der(fx[idx +1], fx[idx], hn) +par_der(fy[idx +1], fy[idx], winHeight); - calculate_height_plot(vis_data, heightplots_get_dataset(), idx); + vis_data->height[idx] = calculate_height_plot(heightplots_get_dataset(), idx); + + //vis_data->normals[idx] = calculate_normal_vector(vis_data->height, idx, i, j); + // printf("vis: h: %lf n: %lf; old: h: %lf n: %lf\n", + // vis_data->height[idx], vis_data->normals[idx].x, height_array[idx], normal_array[idx].x); } } } |