Subversion Repositories DIN Is Noise

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2059 jag 1
/*connect::connect (drone* _d1, drone* _d2) {
2
	dirty = 1;
3
	d1 = _d1;
4
	d2 = _d2;
5
	mag = magnitude (d1->cx, d1->cy, d2->cx, d2->cy);
6
	p1.x = d1->cx; p1.y = d1->cy;
7
	p2.x = d2->cx; p2.y = d2->cy;
8
	align_vel ();
9
}
10
 
11
void connect::align_vel () {
12
	unit_vector<float,float>(d1->vx, d1->vy, d1->cx, d1->cy, d2->cx, d2->cy);
13
	//d2->vx = d1->vx;
14
	//d2->vy = d1->vy;
15
}
16
 
17
int connect::eval (drone** ret) {
18
	double magnew = magnitude (d1->cx, d1->cy, d2->cx, d2->cy);
19
	if (magnew > mag) {
20
		float ux, uy; unit_vector (ux, uy, d1->cx, d1->cy, d2->cx, d2->cy);
21
		double lead = magnew - mag;
22
		int d1mov = ((p1.x != d1->cx) || (p1.y != d1->cy));
23
		int d2mov = ((p2.x != d2->cx) || (p2.y != d2->cy));
24
		int d12mov = d1mov && d2mov;
25
		if (d12mov) {
26
			lead /= 2.0;
27
			d1->set_center (d1->cx + lead * ux, d1->cy + lead * uy);
28
			d2->set_center (d2->cx - lead * ux, d2->cy - lead * uy);
29
			ret[0] = d1;
30
			ret[1] = d2;
31
		} else {
32
			if (d1mov) {
33
				d2->set_center (d2->cx - lead * ux, d2->cy - lead * uy);
34
				ret[0] = d2;
35
				ret[1] = 0;
36
			} else if (d2mov) {
37
				d1->set_center (d1->cx + lead * ux, d1->cy + lead * uy);
38
				ret[0] = d1;
39
				ret[1] = 0;
40
			}
41
		}
42
		align_vel ();
43
		p1.x = d1->cx; p1.y = d1->cy;
44
		p2.x = d2->cx; p2.y = d2->cy;
45
		dirty = 0;
46
		return 1;
47
	}
48
	dirty = 0;
49
	return 0;
50
}
51
 
52
void connect::draw () {
53
	glBegin (GL_LINES);
54
		glColor3f (d1->r, d1->g, d1->b);
55
		glVertex2i (d1->cx, d1->cy);
56
		glColor3f (d2->r, d2->g, d2->b);
57
		glVertex2i (d2->cx, d2->cy);
58
	glEnd ();
59
}*/
60
 
61
/*void din::eval_conns () {
62
	for (drone_iterator i = drones.begin (), j = drones.end (); i != j; ++i) {
63
		drone& di = *(*i);
64
		if (di.conn) {
65
			list<double>::iterator mi = di.mags.begin ();
66
			for (drone_iterator s = di.connections.begin (), t = di.connections.end(); s != t; ++s) {
67
				drone& dc = *(*s);
68
				double now = magnitude (dc.cx, dc.cy, di.cx, di.cy);
69
				double org = *mi;
70
				if (equals (now, org))
71
					;
72
				else if (now > org) {
73
					double lead = 0.01 * (now - org);
74
					float ux, uy; unit_vector<float, int> (ux, uy, dc.cx, dc.cy, di.cx, di.cy);
75
					dc.set_center (dc.cx + float (lead * ux), dc.cy + float(lead * uy), &di);
76
				}
77
			}
78
		}
79
	}
80
}*/
81
 
82
/*void din::butt_drones () {
83
	if ((win_mousex == prev_win_mousex) && (win_mousey == prev_win_mousey)) return;
84
	double mag;
85
	float ux, uy;
86
	for (int i = 0; i < num_selected_drones; ++i) {
87
		drone& di = *selected_drones[i];
88
		mag = unit_vector<float, int> (ux, uy, win_mousex, win_mousey, di.cx, di.cy);
89
		if (mag < butt) {
90
			double lead = drone::STIFFNESS * (butt - mag);
91
			float nx = di.cx + lead * ux, ny = di.cy + lead * uy;
92
			if (magnitude (nx, ny, ring.x, ring.y) < ring.r) {
93
				di.set_center (nx, ny);
94
				for (int j = 0; j < num_selected_drones; ++j) {
95
					if (i != j) {
96
						drone& dj = *selected_drones[j];
97
						mag = unit_vector<float, int> (ux, uy, dj.cx, dj.cy, di.cx, di.cy);
98
						if (mag < inter_butt) {
99
							double lead = drone::STIFFNESS * (inter_butt - mag);
100
							float nx = di.cx + lead * ux, ny = di.cy + lead * uy;
101
							if (magnitude (nx, ny, ring.x, ring.y) < ring.r) {
102
								di.set_center (nx, ny);
103
							}
104
						}
105
					}
106
				}
107
			}
108
		}
109
	}
110
}*/
111
 
112
 
113
/*void din::orbit_reciprocal () { // attach selected drones to attractor
114
  int n = selected_drones.size ();
115
	if (n) {
116
		for (int i = 0, j = 1; i < n; ++i) {
117
			drone* di = selected_drones[i];
118
			drone* dj = selected_drones[j];
119
			list<attractee>& lae = dj->attractees;
120
			if (!di->orbiting) {
121
				push_back (attractors, dj);
122
				attractee ae (di->id, di);
123
				if (push_back (lae, ae)) {
124
					(*dj).attractor++;
125
					di->orbiting = 1;
126
				}
127
			}
128
			if (++j == n) j = 0;
129
		}
130
	} else cons << RED << "Please select at least 2 drones!" << eol;
131
}*/
132
 
133
 
134
	/*if (butting) {
135
		float r [] = {ring.r, butt, inter_butt};
136
		float cx [] = {ring.x, win_mousex, win_mousex};
137
		float cy [] = {ring.y, win_mousey, win_mousey};
138
 
139
		glColor3f (0.25f, 0.25f, 0.25f);
140
		extern const float TWO_PI;
141
		int npts = 33;
142
		for (int p = 0; p < 3; ++p) {
143
			float R = r[p];
144
			float a = 0, da = TWO_PI / (npts - 1);
145
			glBegin (GL_LINE_LOOP);
146
			for (int i = 0; i < npts; ++i, a += da) {
147
				glVertex2f (cx[p] + R * cos(a), cy[p] + R * sin (a));
148
			}
149
			glEnd ();
150
		}
151
	}*/
152
 
153
 
154
	/*void dirty_connection (drone* d);
155
	void dirty_connections ();
156
	vector<connect> conns;*/
157
 
158
	/*struct ringt {
159
		float x, y;
160
		float r;
161
	} ring;
162
	float butt;
163
	float inter_butt;
164
	int butting;
165
	void butt_drones ();
166
 
167
  point<int> wand0; */
168
 
169
 
170
  struct bannert {
171
    ifstream f;
172
    int p, q;
173
    string str;
174
    int read;
175
    float x0, y0, x, y, dx, dy;
176
    void eval ();
177
    void go (float wx, float wy);
178
  } banner;
179
  void namedrones (const string& s);
180
 
181
 
182
void din::namedrones (const string& s) {
183
  if (num_selected_drones) {
184
    tokenizer tz (s);
185
    for (int i = 0; i < num_selected_drones; ++i) {
186
      drone& di = *selected_drones[i];
187
      string si; tz >> si;
188
      di.lbl = si;
189
    }
190
  } else cons << RED_PSD << eol;
191
}
192
 
193
void din::bannert::go (float xx0, float yy0) {
194
  if (read) return;
195
  read = 1;
196
  x0 = xx0;
197
  y0 = yy0;
198
  dx = 20;
199
  dy = 20;
200
}
201
 
202
void din::bannert::eval () {
203
  if (read) {
204
    if (!f.is_open()) {
205
      f.open ((user_data_dir + "banner").c_str(), ios::in);
206
      if (!f.is_open()) {
207
        cons << RED << "couldnt open banner file!" << eol;
208
        read = 0;
209
        return;
210
      }
211
      y = y0;
212
      p = -1;
213
    }
214
 
215
    if (p == -1) {
216
      getline (f, str);
217
      q = str.length ();
218
      if (q == 0) {
219
        read = 0;
220
        p = -1;
221
        f.close ();
222
        return;
223
      }
224
      x = x0;
225
      p = 0;
226
    }
227
 
228
    if (p < q) {
229
      char& sp = str[p++];
230
      if (sp == '#' || sp == '@') din0.add_drone (x, y);
231
      x += dx;
232
    } else {
233
      y -= dy;
234
      p = -1;
235
    }
236
  }
237
}
238
 
239
 
240
      //fnt.draw_charz (di.lbl, di.sx, di.y, di.handle_size);
241
      //draw_string (di.lbl, di.sx, di.y);
242
 
243
			/*if (di.attractor) { // mark + on attractor
244
        dhp[0]=di.handle.midx; dhp[1] = di.handle.top; dhp[2]=di.handle.midx; dhp[3]=di.handle.bottom;
245
        dhp[4]=di.handle.left; dhp[5]=di.handle.midy; dhp[6]=di.handle.right; dhp[7]=di.handle.midy;
246
        glDrawArrays (GL_LINES, 0, 4);
247
			}
248
 
249
      if (di.launcher) { // mark x on launcher
250
        dhp[0]=di.handle.left; dhp[1] = di.y; dhp[2]=di.handle.right; dhp[3]=di.y;
251
        dhp[4]=di.sx; dhp[5]=di.handle.bottom; dhp[6]=di.sx; dhp[7]=di.handle.top;
252
        glDrawArrays (GL_LINES, 0, 4);
253
      }*/