Rev 2059 | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*connect::connect (drone* _d1, drone* _d2) {
dirty = 1;
d1 = _d1;
d2 = _d2;
mag = magnitude (d1->cx, d1->cy, d2->cx, d2->cy);
p1.x = d1->cx; p1.y = d1->cy;
p2.x = d2->cx; p2.y = d2->cy;
align_vel ();
}
void connect::align_vel () {
unit_vector<float,float>(d1->vx, d1->vy, d1->cx, d1->cy, d2->cx, d2->cy);
//d2->vx = d1->vx;
//d2->vy = d1->vy;
}
int connect::eval (drone** ret) {
double magnew = magnitude (d1->cx, d1->cy, d2->cx, d2->cy);
if (magnew > mag) {
float ux, uy; unit_vector (ux, uy, d1->cx, d1->cy, d2->cx, d2->cy);
double lead = magnew - mag;
int d1mov = ((p1.x != d1->cx) || (p1.y != d1->cy));
int d2mov = ((p2.x != d2->cx) || (p2.y != d2->cy));
int d12mov = d1mov && d2mov;
if (d12mov) {
lead /= 2.0;
d1->set_center (d1->cx + lead * ux, d1->cy + lead * uy);
d2->set_center (d2->cx - lead * ux, d2->cy - lead * uy);
ret[0] = d1;
ret[1] = d2;
} else {
if (d1mov) {
d2->set_center (d2->cx - lead * ux, d2->cy - lead * uy);
ret[0] = d2;
ret[1] = 0;
} else if (d2mov) {
d1->set_center (d1->cx + lead * ux, d1->cy + lead * uy);
ret[0] = d1;
ret[1] = 0;
}
}
align_vel ();
p1.x = d1->cx; p1.y = d1->cy;
p2.x = d2->cx; p2.y = d2->cy;
dirty = 0;
return 1;
}
dirty = 0;
return 0;
}
void connect::draw () {
glBegin (GL_LINES);
glColor3f (d1->r, d1->g, d1->b);
glVertex2i (d1->cx, d1->cy);
glColor3f (d2->r, d2->g, d2->b);
glVertex2i (d2->cx, d2->cy);
glEnd ();
}*/
/*void din::eval_conns () {
for (drone_iterator i = drones.begin (), j = drones.end (); i != j; ++i) {
drone& di = *(*i);
if (di.conn) {
list<double>::iterator mi = di.mags.begin ();
for (drone_iterator s = di.connections.begin (), t = di.connections.end(); s != t; ++s) {
drone& dc = *(*s);
double now = magnitude (dc.cx, dc.cy, di.cx, di.cy);
double org = *mi;
if (equals (now, org))
;
else if (now > org) {
double lead = 0.01 * (now - org);
float ux, uy; unit_vector<float, int> (ux, uy, dc.cx, dc.cy, di.cx, di.cy);
dc.set_center (dc.cx + float (lead * ux), dc.cy + float(lead * uy), &di);
}
}
}
}
}*/
/*void din::butt_drones () {
if ((win_mousex == prev_win_mousex) && (win_mousey == prev_win_mousey)) return;
double mag;
float ux, uy;
for (int i = 0; i < num_selected_drones; ++i) {
drone& di = *selected_drones[i];
mag = unit_vector<float, int> (ux, uy, win_mousex, win_mousey, di.cx, di.cy);
if (mag < butt) {
double lead = drone::STIFFNESS * (butt - mag);
float nx = di.cx + lead * ux, ny = di.cy + lead * uy;
if (magnitude (nx, ny, ring.x, ring.y) < ring.r) {
di.set_center (nx, ny);
for (int j = 0; j < num_selected_drones; ++j) {
if (i != j) {
drone& dj = *selected_drones[j];
mag = unit_vector<float, int> (ux, uy, dj.cx, dj.cy, di.cx, di.cy);
if (mag < inter_butt) {
double lead = drone::STIFFNESS * (inter_butt - mag);
float nx = di.cx + lead * ux, ny = di.cy + lead * uy;
if (magnitude (nx, ny, ring.x, ring.y) < ring.r) {
di.set_center (nx, ny);
}
}
}
}
}
}
}
}*/
/*void din::orbit_reciprocal () { // attach selected drones to attractor
int n = selected_drones.size ();
if (n) {
for (int i = 0, j = 1; i < n; ++i) {
drone* di = selected_drones[i];
drone* dj = selected_drones[j];
list<attractee>& lae = dj->attractees;
if (!di->orbiting) {
push_back (attractors, dj);
attractee ae (di->id, di);
if (push_back (lae, ae)) {
(*dj).attractor++;
di->orbiting = 1;
}
}
if (++j == n) j = 0;
}
} else cons << RED << "Please select at least 2 drones!" << eol;
}*/
/*if (butting) {
float r [] = {ring.r, butt, inter_butt};
float cx [] = {ring.x, win_mousex, win_mousex};
float cy [] = {ring.y, win_mousey, win_mousey};
glColor3f (0.25f, 0.25f, 0.25f);
extern const float TWO_PI;
int npts = 33;
for (int p = 0; p < 3; ++p) {
float R = r[p];
float a = 0, da = TWO_PI / (npts - 1);
glBegin (GL_LINE_LOOP);
for (int i = 0; i < npts; ++i, a += da) {
glVertex2f (cx[p] + R * cos(a), cy[p] + R * sin (a));
}
glEnd ();
}
}*/
/*void dirty_connection (drone* d);
void dirty_connections ();
vector<connect> conns;*/
/*struct ringt {
float x, y;
float r;
} ring;
float butt;
float inter_butt;
int butting;
void butt_drones ();
point<int> wand0; */
struct bannert {
ifstream f;
int p, q;
string str;
int read;
float x0, y0, x, y, dx, dy;
void eval ();
void go (float wx, float wy);
} banner;
void namedrones (const string& s);
void din::namedrones (const string& s) {
if (num_selected_drones) {
tokenizer tz (s);
for (int i = 0; i < num_selected_drones; ++i) {
drone& di = *selected_drones[i];
string si; tz >> si;
di.lbl = si;
}
} else cons << RED_PSD << eol;
}
void din::bannert::go (float xx0, float yy0) {
if (read) return;
read = 1;
x0 = xx0;
y0 = yy0;
dx = 20;
dy = 20;
}
void din::bannert::eval () {
if (read) {
if (!f.is_open()) {
f.open ((user_data_dir + "banner").c_str(), ios::in);
if (!f.is_open()) {
cons << RED << "couldnt open banner file!" << eol;
read = 0;
return;
}
y = y0;
p = -1;
}
if (p == -1) {
getline (f, str);
q = str.length ();
if (q == 0) {
read = 0;
p = -1;
f.close ();
return;
}
x = x0;
p = 0;
}
if (p < q) {
char& sp = str[p++];
if (sp == '#' || sp == '@') din0.add_drone (x, y);
x += dx;
} else {
y -= dy;
p = -1;
}
}
}
//fnt.draw_charz (di.lbl, di.sx, di.y, di.handle_size);
//draw_string (di.lbl, di.sx, di.y);
/*if (di.attractor) { // mark + on attractor
dhp[0]=di.handle.midx; dhp[1] = di.handle.top; dhp[2]=di.handle.midx; dhp[3]=di.handle.bottom;
dhp[4]=di.handle.left; dhp[5]=di.handle.midy; dhp[6]=di.handle.right; dhp[7]=di.handle.midy;
glDrawArrays (GL_LINES, 0, 4);
}
if (di.launcher) { // mark x on launcher
dhp[0]=di.handle.left; dhp[1] = di.y; dhp[2]=di.handle.right; dhp[3]=di.y;
dhp[4]=di.sx; dhp[5]=di.handle.bottom; dhp[6]=di.sx; dhp[7]=di.handle.top;
glDrawArrays (GL_LINES, 0, 4);
}*/