diff options
author | Oliver Schinagl <oliver@schinagl.nl> | 2008-01-03 11:50:49 (GMT) |
---|---|---|
committer | Oliver Schinagl <oliver@schinagl.nl> | 2008-01-03 11:50:49 (GMT) |
commit | 4498f6514ddfd5bf825d7706a50958029998f512 (patch) | |
tree | 277271543d1d58fe1a638a06cff1cc9bf26096de /Smoke/interact.c | |
parent | ff646235f1ab52e6cb894eec0e93d6f00dc4d71c (diff) | |
download | 2iv35-4498f6514ddfd5bf825d7706a50958029998f512.zip 2iv35-4498f6514ddfd5bf825d7706a50958029998f512.tar.gz 2iv35-4498f6514ddfd5bf825d7706a50958029998f512.tar.bz2 |
interaction module
Diffstat (limited to 'Smoke/interact.c')
-rw-r--r-- | Smoke/interact.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/Smoke/interact.c b/Smoke/interact.c new file mode 100644 index 0000000..13e9a6b --- /dev/null +++ b/Smoke/interact.c @@ -0,0 +1,113 @@ +#include <rfftw.h> +#include "fluids.h" + +#include "renderer_gl.h" + +#define MOUSE_SMOKE 0 +#define MOUSE_SCALE_MIN 1 +#define MOUSE_SCALE_MAX 2 +#define MOUSE_CLAMP_MIN 3 +#define MOUSE_CLAMP_MAX 4 + +int prev_mov_mx = 0; +int prev_mov_my = 0; + +float x_rot = 0.0f; +float y_rot = 0.0f; +float z_rot = 0.0f; + +int prev_rot_mx = 0; +int prev_rot_my = 0; +int prev_rot_mz = 0; + + +void mouse_move(int mx, int my) +{ + x_pos += (float)(mx - prev_mov_mx); + y_pos -= (float)(my - prev_mov_my); + + prev_mov_mx = mx; + prev_mov_my = my; +} + +void mouse_rotate(int mx, int my) +{ + x_rot -= ((float)(my - prev_rot_my) / 5.0f); + y_rot -= ((float)(mx - prev_rot_mx) / 5.0f); + + prev_rot_mx = mx; + prev_rot_my = my; +} + +void mouse_roll(int mz) +{ + z_rot -= ((float)(mz -prev_rot_mz) / 5.0f); + + prev_rot_mz = mz; +} + +void click(int button, int state, int mx, int my) +{ + /* First check wether we are on the top half, or bottom half of the bar, if neither then + * the mouseinput is for the smoke + */ + if (!state) + { + prev_mov_mx = prev_rot_mx = mx; + prev_mov_my = prev_rot_my = my; + prev_rot_mz = mx; + } + + if (my <25) { + /* Click received on button bar */ + float min, max; + if (my <13) { + /* Upper half */ + /* check wether mx is min or max slider */ + min = colormap_get_scale_min(); + max = colormap_get_scale_max(); + if (mx <(rescale_to_winwidth(min +((max - min) /2)))) { + active_slider = MOUSE_SCALE_MIN; + } else if (mx >(rescale_to_winwidth(max -((max - min) /2)))) { + active_slider = MOUSE_SCALE_MAX; + } + } else { + /* Bottom half */ + min = colormap_get_clamp_min(); + max = colormap_get_clamp_max(); + /* check wether mx is min or max slider */ + if (mx <(rescale_to_winwidth(min +((max - min) /2)))) { + active_slider = MOUSE_CLAMP_MIN; + } else if (mx >(rescale_to_winwidth(max -((max - min) /2)))) { + active_slider = MOUSE_CLAMP_MAX; + } + } + } +} + +// drag: When the user drags with the mouse, add a force that corresponds to the direction of the mouse +// cursor movement. Also inject some new matter into the field at the mouse location. +void drag(int mx, int my) +{ + if (my > 25) { + fluids_insert_smoke(mx, my); + } else { + switch (active_slider) { + case MOUSE_SCALE_MIN: + colormap_set_scale_min((float)mx /winWidth); + break; + case MOUSE_SCALE_MAX: + colormap_set_scale_max((float)mx /winWidth); + break; + case MOUSE_CLAMP_MIN: + colormap_set_clamp_min((float)mx /winWidth); + break; + case MOUSE_CLAMP_MAX: + colormap_set_clamp_max((float)mx /winWidth); + break; + case MOUSE_SMOKE: + default: + break; + } + } +} |