projects
/
universe.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Cleaning up.
[universe.git]
/
universe.cc
diff --git
a/universe.cc
b/universe.cc
index
92b7a1b
..
8dec7f5
100644
(file)
--- a/
universe.cc
+++ b/
universe.cc
@@
-7,18
+7,20
@@
#include "universe.h"
Universe::Universe(int nb_max_polygons,
#include "universe.h"
Universe::Universe(int nb_max_polygons,
- scalar_t width, scalar_t height) : _width(width), _height(height),
- _nb_max_polygons(nb_max_polygons), _nb_polygons(0) {
+ scalar_t width, scalar_t height) : _width(width),
+ _height(height),
+ _nb_max_polygons(nb_max_polygons),
+ _nb_polygons(0) {
_polygons = new Polygon *[_nb_max_polygons];
for(int n = 0; n < _nb_max_polygons; n++) _polygons[n] = 0;
}
Universe::~Universe() {
_polygons = new Polygon *[_nb_max_polygons];
for(int n = 0; n < _nb_max_polygons; n++) _polygons[n] = 0;
}
Universe::~Universe() {
-
for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) delete _polygons[n]
;
+
clear()
;
delete[] _polygons;
}
delete[] _polygons;
}
-void Universe::initialize(Polygon *p) {
+void Universe::initialize
_polygon
(Polygon *p) {
p->initialize(_nb_max_polygons);
}
p->initialize(_nb_max_polygons);
}
@@
-116,6
+118,7
@@
Polygon *Universe::pick_polygon(scalar_t x, scalar_t y) {
return 0;
}
return 0;
}
+#ifdef XFIG_SUPPORT
void Universe::print_xfig(XFigTracer *tracer) {
for(int n = 0; n < _nb_polygons; n++) {
if(_polygons[n]) {
void Universe::print_xfig(XFigTracer *tracer) {
for(int n = 0; n < _nb_polygons; n++) {
if(_polygons[n]) {
@@
-128,6
+131,7
@@
void Universe::print_xfig(XFigTracer *tracer) {
}
}
}
}
}
}
+#endif
#ifdef X11_SUPPORT
void Universe::draw(SimpleWindow *window) {
#ifdef X11_SUPPORT
void Universe::draw(SimpleWindow *window) {
@@
-145,21
+149,27
@@
void Universe::draw(SimpleWindow *window) {
}
#endif
}
#endif
-#ifdef CAIRO_SUPPORT
-void Universe::draw(cairo_t *context_resource) {
+void Universe::draw(Canvas *canvas) {
for(int n = 0; n < _nb_polygons; n++) {
if(_polygons[n]) {
for(int n = 0; n < _nb_polygons; n++) {
if(_polygons[n]) {
- _polygons[n]->draw(c
ontext_resource
);
+ _polygons[n]->draw(c
anvas
);
}
}
for(int n = 0; n < _nb_polygons; n++) {
if(_polygons[n]) {
}
}
for(int n = 0; n < _nb_polygons; n++) {
if(_polygons[n]) {
- _polygons[n]->draw_contours(c
ontext_resource
);
+ _polygons[n]->draw_contours(c
anvas
);
}
}
}
}
}
}
-#endif
+
+void Universe::apply_gravity(scalar_t dt, scalar_t fx, scalar_t fy) {
+ for(int n = 0; n < _nb_polygons; n++)
+ if(_polygons[n])
+ _polygons[n]->apply_force(dt,
+ _polygons[n]->_center_x, _polygons[n]->_center_y,
+ fx, fy);
+}
void Universe::apply_collision_forces(scalar_t dt) {
const int nb_axis = 2;
void Universe::apply_collision_forces(scalar_t dt) {
const int nb_axis = 2;