summaryrefslogtreecommitdiffstats
path: root/Smoke/interact.c
blob: 7671cb8c2b78415fadfe28b2b322cf0bf168101b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <rfftw.h>
#include "fluids.h"

#include "funcs.h"

#include "renderer_gl.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;



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;
  }

  //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;
			}
	 }
}