From 3ea65d15a33cd73c71c0f9af0cc5d882ebd12265 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Fri, 9 Sep 2016 12:24:18 +0200 Subject: [PATCH] Update. --- dummy.cc | 10 +++++----- generate.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ hit_shape.cc | 2 +- move_square.cc | 4 ++-- universe.h | 2 +- 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/dummy.cc b/dummy.cc index f225285..67b2fd1 100644 --- a/dummy.cc +++ b/dummy.cc @@ -32,7 +32,7 @@ public: 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); } @@ -46,7 +46,7 @@ public: 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); } @@ -59,7 +59,7 @@ public: 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); @@ -73,7 +73,7 @@ public: 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; @@ -84,7 +84,7 @@ public: } p->set_position(400, 400, 0); p->set_speed(0, 0, 0); - universe->initialize(p); + universe->initialize_polygon(p); universe->add_polygon(p); } diff --git a/generate.cc b/generate.cc index e41fbe3..62b61ec 100644 --- a/generate.cc +++ b/generate.cc @@ -36,5 +36,47 @@ void generate_png(Universe *universe, scalar_t scale, FILE *file) { } 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; } diff --git a/hit_shape.cc b/hit_shape.cc index 1663064..344e45c 100644 --- a/hit_shape.cc +++ b/hit_shape.cc @@ -47,7 +47,7 @@ public: 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 { diff --git a/move_square.cc b/move_square.cc index a2bbda7..664b70f 100644 --- a/move_square.cc +++ b/move_square.cc @@ -44,7 +44,7 @@ public: _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) { @@ -57,7 +57,7 @@ public: 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); } } diff --git a/universe.h b/universe.h index a521f59..a48a3ba 100644 --- a/universe.h +++ b/universe.h @@ -31,7 +31,7 @@ public: // 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); -- 2.39.5