#include #include "fluids.h" #include "funcs.h" #include "renderer_gl.h" #include "streamlines.h" #include "colormap.h" #include "seedpoint.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; static int active_slider = 0; int rescale_to_winwidth(float value) { return round(value *winWidth); } 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 (streamlines_get_render()) { create_seedpoint(mx, my); } 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; } } }