diff options
author | Wilrik de Loose <wilrik@wilrik.nl> | 2007-12-14 12:24:48 (GMT) |
---|---|---|
committer | Wilrik de Loose <wilrik@wilrik.nl> | 2007-12-14 12:24:48 (GMT) |
commit | ab8aa770afa4fd72e4078f5c8703f91817b2d6c5 (patch) | |
tree | c8a2c6643055ed430c00538e33b17295f7029102 | |
parent | dbc6530ef4b5a5ce4284b0cb32e2f61677b47b18 (diff) | |
download | 2iv35-ab8aa770afa4fd72e4078f5c8703f91817b2d6c5.zip 2iv35-ab8aa770afa4fd72e4078f5c8703f91817b2d6c5.tar.gz 2iv35-ab8aa770afa4fd72e4078f5c8703f91817b2d6c5.tar.bz2 |
streamlines + colormap files
-rw-r--r-- | Smoke/colormap.c | 122 | ||||
-rw-r--r-- | Smoke/colormap.h | 14 | ||||
-rw-r--r-- | Smoke/streamlines.c | 26 | ||||
-rw-r--r-- | Smoke/streamlines.h | 7 |
4 files changed, 169 insertions, 0 deletions
diff --git a/Smoke/colormap.c b/Smoke/colormap.c new file mode 100644 index 0000000..3620cb7 --- /dev/null +++ b/Smoke/colormap.c @@ -0,0 +1,122 @@ +#ifdef G_OS_WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include <windows.h> +#endif + +#include <math.h> + +#include "fluids.h" +#include "colormap.h" +#include "funcs.h" + +//rainbow: Implements a color palette, mapping the scalar 'value' to a rainbow color RGB +void rainbow(float value, float *R, float *G, float *B) +{ + const float dx = 0.8f; + + if (value < 0) value = 0; + if (value > 1) value = 1; + + value = (6 - 2 * dx) * value + dx; + + *R = (float)max(0.0f, (3 - fabs(value - 4.0f) - fabs(value - 5.0f)) / 2.0f); + *G = (float)max(0.0f, (4 - fabs(value - 2.0f) - fabs(value - 4.0f)) / 2.0f); + *B = (float)max(0.0f, (3 - fabs(value - 1.0f) - fabs(value - 2.0f)) / 2.0f); +} + +void colormap_fire(float value, float *R, float *G, float *B) +{ + /* Colormap Fire + * A fire effect deals with two parts, first a drop from red to yellow (halfway) + * during which time the Red component remains full e.g. 1. The Green component is + * slowly added to turn the red into orange, and then yellow (R & G =Y). After this + * point, the Red and Green component (e.g. yellow) have to drop simulataniously + * to go from yellow down to black. + */ + *B = 0; + *G = 0; + *R = 0; + + if (value <= (0.01)) { + /* whilst value is 0 - 0.5 both red and green equally change to create yellow */ + *R = *G = value; + } else { + /* whilst value is 0.5 - 1 Red is always fully on while the Green component is + * added in steps to go from red to orange to yellow. + */ + *G = 0.9f - value; + *R = 0.8f; // not 1, makes red deeper, more intense + } +} + +//set_colormap: Sets three different types of colormaps +struct color4f set_colormap(int colormap_sort, float vy, int draw_bar, float alpha) +{ + float R, G, B; + struct color4f return_value; + const int NLEVELS = 7; + + if (autoscale) + { + vy = remap(vy); + } + + if (!(draw_bar)) + { + if (vy < clamp_min) vy = clamp_min; + if (vy > clamp_max) vy = clamp_max; + } + + switch (colormap_sort) + { + case COLOR_BLACKWHITE: + R = G = B = vy; + break; + case COLOR_RAINBOW: + rainbow(vy,&R,&G,&B); + break; + case COLOR_BANDS: + vy *= NLEVELS; vy = (float)(int)(vy); vy/= NLEVELS; + rainbow(vy,&R,&G,&B); + break; + case COLOR_BLUE_GREEN_RED: + if (vy < -0.1) + { + R = G = 0; + vy -= -0.1f; + vy /= 0.9f; + B = -vy; + } + else if (vy < 0.1) + { + R = B = 0; + vy += 0.1f; + vy /= 0.2f; + G = vy; + } + else + { + vy -= 0.1f; + vy /= 0.9f; + R = vy; + G = B = 0; + } + break; + case COLOR_WILRIK: + colormap_fire(vy, &R, &G, &B); + break; + case COLOR_OLIVER: + rainbow(vy, &R, &G, &B); + break; + + } + + glColor4f(R, G, B, alpha); + + return_value.r = R; + return_value.g = G; + return_value.b = B; + return_value.a = alpha; + + return return_value; +}
\ No newline at end of file diff --git a/Smoke/colormap.h b/Smoke/colormap.h new file mode 100644 index 0000000..262a680 --- /dev/null +++ b/Smoke/colormap.h @@ -0,0 +1,14 @@ +#ifndef _COLORMAP_H
+#define _COLORMAP_H
+
+struct color4f {
+ float r;
+ float g;
+ float b;
+ float a;
+};
+
+struct color4f set_colormap(int colormap_sort, float vy, int draw_bar, float alpha);
+
+#endif
+
diff --git a/Smoke/streamlines.c b/Smoke/streamlines.c new file mode 100644 index 0000000..51e9fa0 --- /dev/null +++ b/Smoke/streamlines.c @@ -0,0 +1,26 @@ +// Includes
+
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN 1
+#include <windows.h>
+#endif
+
+#include "fluids.h"
+#include "streamlines.h"
+#include "seedpoint.h"
+
+void render_streamlines(void)
+{
+ int i, j, max;
+ i = j = max = 0;
+
+ max = get_cur_seedpoint();
+
+ for (i = 0; i < max; i++)
+ {
+ while (frame_hist[j] != NULL)
+ {
+ j++;
+ }
+ }
+}
\ No newline at end of file diff --git a/Smoke/streamlines.h b/Smoke/streamlines.h new file mode 100644 index 0000000..f2c2816 --- /dev/null +++ b/Smoke/streamlines.h @@ -0,0 +1,7 @@ +#ifndef _STREAMLINES_H
+#define _STREAMLINES_H
+
+void render_streamlines(void);
+
+#endif
+
|