From 8addeabeb2498955ebb7b62f810fbf2781bcae59 Mon Sep 17 00:00:00 2001 From: Wilrik de Loose Date: Thu, 3 Jan 2008 15:03:55 +0000 Subject: betere belichting --- Smoke/Week 2.ncb | Bin 15518720 -> 15518720 bytes Smoke/Week 2.suo | Bin 56832 -> 56320 bytes Smoke/fluids.c | 87 +++++++++++++++------------------------------------- Smoke/gtk_main.c | 10 ++++++ Smoke/renderer_gl.c | 34 ++++++++++---------- 5 files changed, 51 insertions(+), 80 deletions(-) diff --git a/Smoke/Week 2.ncb b/Smoke/Week 2.ncb index cb81cd8..b98bf23 100644 Binary files a/Smoke/Week 2.ncb and b/Smoke/Week 2.ncb differ diff --git a/Smoke/Week 2.suo b/Smoke/Week 2.suo index 846d2e6..2f031f1 100644 Binary files a/Smoke/Week 2.suo and b/Smoke/Week 2.suo differ diff --git a/Smoke/fluids.c b/Smoke/fluids.c index 2223bde..c3c776a 100644 --- a/Smoke/fluids.c +++ b/Smoke/fluids.c @@ -237,79 +237,40 @@ 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; - } } void calculate_normal_vectors(void) { - int i; + int i, j, idx; 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 + 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++) + for (j = 0; j < DIM; j++) { - switch (vis_dataset) - { - case DATASET_FORCE: - p1.x = fx[i]; - p1.y = fy[i]; - p1.z = height_array[i]; - - p2.x = fx[i + 1]; - p2.y = fy[i + 1]; - p2.z = height_array[i + 1]; - - p3.x = fx[i + DIM]; - p3.y = fy[i + DIM]; - p3.z = height_array[i + DIM]; - break; - - case DATASET_VEL: - p1.x = vx[i]; - p1.y = vy[i]; - p1.z = height_array[i]; - - p3.x = vx[i + 1]; - p3.y = vy[i + 1]; - p3.z = height_array[i + 1]; - - p2.x = vx[i + DIM]; - p2.y = vy[i + DIM]; - p2.z = height_array[i + DIM]; - break; - - case DATASET_RHO: - p1.x = rho[i]; - p1.y = rho[i]; - p1.z = height_array[i]; - - p2.x = rho[i + 1]; - p2.y = rho[i + 1]; - p2.z = height_array[i + 1]; - - p3.x = rho[i + DIM]; - p3.y = rho[i + DIM]; - p3.z = height_array[i + DIM]; - break; - - default: - case DATASET_DIVV: - case DATASET_DIVF: - p1.x = 0.0f; p1.y = 0.0f; p1.z = 0.0f; - p2.x = 0.0f; p2.y = 0.0f; p2.z = 0.0f; - p3.x = 0.0f; p3.y = 0.0f; p3.z = 0.0f; - break; - } - - vector_normal(p1, p2, p3, &normal_array[i]); + for (i = 0; i < DIM; i++) + { + idx = (j * DIM) + i; + px = wn + (fftw_real)i * wn; + py = hn + (fftw_real)(j + 1) * hn; + + p1.x = px; + p1.y = py; + p1.z = height_array[idx]; + + p2.x = px; + p2.y = py + hn; + p2.z = height_array[idx + DIM]; + + p3.x = px + wn; + p3.y = py; + p3.z = height_array[idx + 1]; + + vector_normal(p2, p1, p3, &normal_array[idx]); + } } } diff --git a/Smoke/gtk_main.c b/Smoke/gtk_main.c index 6c9815f..242578f 100644 --- a/Smoke/gtk_main.c +++ b/Smoke/gtk_main.c @@ -42,6 +42,10 @@ static gboolean set_dataset(GtkButton *button, gpointer data) } } +static gboolean select_normals(GtkWidget *button, gpointer data) { + normals_set_render(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))); +} + static gboolean reset_zoom(GtkWidget *button, gpointer data) { renderer_reset_zoom(); } @@ -134,6 +138,12 @@ GtkWidget *create_main_page(void) gtk_box_pack_start (GTK_BOX(box), button, TRUE, TRUE, 0); gtk_widget_show(button); + button = gtk_check_button_new_with_label("Draw Normal Vectors"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), normals_get_render()); + g_signal_connect (G_OBJECT(button), "clicked", G_CALLBACK(select_normals), NULL); + gtk_box_pack_start (GTK_BOX(box), button, TRUE, TRUE, 0); + gtk_widget_show(button); + gtk_box_pack_start (GTK_BOX(page), box, FALSE, TRUE, 0); gtk_widget_show(box); diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c index 19b982b..7bbf044 100644 --- a/Smoke/renderer_gl.c +++ b/Smoke/renderer_gl.c @@ -134,7 +134,8 @@ static void render_legend(void) static void render_normal(void) { - int i, j, idx; double px,py; + 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; @@ -143,9 +144,9 @@ static void render_normal(void) glBegin(GL_LINES); glColor3f(1.0f, 0.2f, 0.0f); - for (i = 0; i < DIM - 1; i++) + for (j = 0; j < DIM - 1; j++) { - for (j = 0; j < DIM - 1; j++) + for (i = 0; i < DIM; i++) { idx = (j * DIM) + i; px = wn + (fftw_real)i * wn; @@ -171,8 +172,6 @@ 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); @@ -184,9 +183,8 @@ 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 1 - glNormal3f(normal_array[idx].x, normal_array[idx].y, normal_array[idx].z); + glVertex3f(px, py, height_array[idx]); // vertex 1 for (i = 0; i < DIM - 1; i++) { @@ -196,18 +194,16 @@ static void render_smoke(void) get_dataset(idx); color = colormap_get_color(get_dataset(idx)); glColor4f(color.r, color.g, color.b, color.a); - glVertex3f(px, py, height_array[idx]); // vertex 2 - glNormal3f(normal_array[idx].x, normal_array[idx].y, normal_array[idx].z); + glVertex3f(px, py, height_array[idx]); // vertex 2 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 3 - glNormal3f(normal_array[idx].x, normal_array[idx].y, normal_array[idx].z); + glVertex3f(px, py, height_array[idx]); // vertex 3 } px = wn + (fftw_real)(DIM - 1) * wn; @@ -215,9 +211,8 @@ static void render_smoke(void) idx = ((j + 1) * DIM) + (DIM - 1); color = colormap_get_color(get_dataset(idx)); glColor4f(color.r, color.g, color.b, color.a); - glVertex3f(px, py, height_array[idx]); // vertex 4 - glNormal3f(normal_array[idx].x, normal_array[idx].y, normal_array[idx].z); + glVertex3f(px, py, height_array[idx]); // vertex 4 glEnd(); } @@ -590,9 +585,9 @@ void render_flowvis(fftw_real *field) void renderer_init_gl(void) { - 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 + float LightAmbient[] = { 0.10f, 0.10f, 0.10f, 1.00f }; // Ambient light values + float LightDiffuse[] = { 0.40f, 0.40f, 0.40f, 0.00f }; // Diffuse light values + float LightPosition[] = { -300.0f, -300.0f, -300.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 @@ -600,7 +595,7 @@ void renderer_init_gl(void) glDepthFunc(GL_LESS); // The type of depth testing to do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really nice perspective calculations glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); // Really nice point smoothing - //glEnable(GL_BLEND); + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); @@ -710,3 +705,8 @@ int normals_get_render(void) { return normals_render; } + +void normals_set_render(int normals) +{ + normals_render = normals; +} -- cgit v0.12