p->set_vertex(3, 0, height);
p->set_position(x0 + deltax/2, y0 + deltay/2, 0);
p->set_speed(0, 0, 0);
- universe->initialize(p);
+ universe->initialize_polygon(p);
universe->add_polygon(p);
}
p->set_vertex(3, 0, height);
p->set_position(x0, y0 + deltay/2, 0);
p->set_speed(0, 0, 0);
- universe->initialize(p);
+ universe->initialize_polygon(p);
universe->add_polygon(p);
}
p->set_vertex(3, 0, height);
p->set_position(x0 + deltax, y0 + deltay/2, 0);
p->set_speed(0, 0, 0);
- universe->initialize(p);
+ universe->initialize_polygon(p);
universe->add_polygon(p);
p = new Polygon(1.0, 0.8, 0.2, 0.8, 0, 0, 8);
p->set_vertex(7, 0.0, 40.0);
p->set_position(120, 420, 0);
p->set_speed(0, 0, 0);
- universe->initialize(p);
+ universe->initialize_polygon(p);
universe->add_polygon(p);
int ne = 25;
}
p->set_position(400, 400, 0);
p->set_speed(0, 0, 0);
- universe->initialize(p);
+ universe->initialize_polygon(p);
universe->add_polygon(p);
}
}
int main(int argc, char **argv) {
+ scalar_t world_width = 400;
+ scalar_t world_height = 400;
+ scalar_t square_size = 100;
+ Universe *universe = new Universe(10, world_width, world_height);
+
+ scalar_t x[] = {
+ world_width * 0.5 - square_size * 0.5,
+ world_width * 0.5 + square_size * 0.5,
+ world_width * 0.5 + square_size * 0.5,
+ world_width * 0.5 - square_size * 0.5,
+ };
+
+ scalar_t y[] = {
+ world_height * 0.5 - square_size * 0.5,
+ world_height * 0.5 - square_size * 0.5,
+ world_height * 0.5 + square_size * 0.5,
+ world_height * 0.5 + square_size * 0.5,
+ };
+
+ Polygon *pol = new Polygon(0.5, 1.0, 1.0, 0.0, x, y, 4);
+ pol->set_position(world_width * 0.5, world_height * 0.5, M_PI/3);
+ pol->set_speed(0, 0, 0);
+ universe->initialize_polygon(pol);
+ universe->add_polygon(pol);
+
+ {
+ FILE *file = fopen("universe1.png", "w");
+ generate_png(universe, 0.25, file);
+ }
+
+ scalar_t hand_x = world_width * 0.5;
+ scalar_t hand_y = world_height * 0.5;
+ Polygon *grabbed_polygon = universe->pick_polygon(hand_x, hand_y);
+ scalar_t grab_relative_x = grabbed_polygon->relative_x(hand_x, hand_y);
+ scalar_t grab_relative_y = grabbed_polygon->relative_y(hand_x, hand_y);
+
+ {
+ FILE *file = fopen("universe2.png", "w");
+ generate_png(universe, 0.25, file);
+ }
+
+ delete universe;
}
margin + (world_height - 2 * margin) * drand48(),
2 * M_PI * drand48());
p->set_speed(0, 0, 0);
- universe->initialize(p);
+ universe->initialize_polygon(p);
p->_nailed = true;
if(universe->collide(p)) delete p;
else {
_target->set_position(_square_size/2, _square_size/2 + (world_height - _square_size) * drand48(), 0);
_target->set_speed(0, 0, 0);
- universe->initialize(_target);
+ universe->initialize_polygon(_target);
universe->add_polygon(_target);
if(degree == 4) {
obstacle->set_position(world_width/2, world_height/2, 0);
obstacle->set_speed(0, 0, 0);
obstacle->_nailed = true;
- universe->initialize(obstacle);
+ universe->initialize_polygon(obstacle);
universe->add_polygon(obstacle);
}
}
// The destructor deletes all the added polygons
~Universe();
- void initialize(Polygon *p);
+ void initialize_polygon(Polygon *p);
void clear();
void add_polygon(Polygon *p);
bool collide(Polygon *p);