X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=inline;f=universe.h;h=07cf7f02b28b50de0731fdca10ad52f41451ecc2;hb=599bf3fa2eb01b05ec677b628e65adb2fe4f91c3;hp=74339a35f7d209df46cacf2678903b709208a014;hpb=3e51d77116e49ba279a6cbbf1dbbc893c4117eb4;p=universe.git diff --git a/universe.h b/universe.h index 74339a3..07cf7f0 100644 --- a/universe.h +++ b/universe.h @@ -8,32 +8,54 @@ #include #include -using namespace std; - #include "misc.h" -#include "simple_window.h" +#include "canvas.h" #include "polygon.h" +#ifdef X11_SUPPORT +#include "simple_window.h" +#endif + +using namespace std; + class Universe { - scalar_t _xmax, _ymax; + scalar_t _width, _height; public: int _nb_max_polygons, _nb_polygons; Polygon **_polygons; - Universe(int nb_max_polygons, scalar_t xmax, scalar_t ymax); + + inline scalar_t width() { return _width; } + inline scalar_t height() { return _height; } + + Universe(int nb_max_polygons, scalar_t width, scalar_t height); // 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); + // Compute collisions between projections of the polygons on a few // axis to speed up the computation void compute_pseudo_collisions(int nb_axis, int *nb_colliding_axis); + void apply_gravity(scalar_t dt, scalar_t fx, scalar_t fy); void apply_collision_forces(scalar_t dt); bool update(scalar_t dt); + Polygon *pick_polygon(scalar_t x, scalar_t y); + +#ifdef XFIG_SUPPORT void print_xfig(XFigTracer *tracer); +#endif + +#ifdef X11_SUPPORT void draw(SimpleWindow *window); +#endif + +#ifdef CAIRO_SUPPORT + void draw(Canvas *canvas); }; +#endif #endif