diff --git a/bugs/new/2011-18-12-1926-reperelocal.txt b/bugs/new/2011-18-12-1926-reperelocal.txt new file mode 100644 index 0000000..56beba1 --- /dev/null +++ b/bugs/new/2011-18-12-1926-reperelocal.txt @@ -0,0 +1,14 @@ +Il faut redéfinir la notion et implémentation du repère local dans +l'abre. pour ne pas avoir de problème de taille d'entier, et utiliser +correctement le repère local mis en place il faut que chaque élément +dépendent du repère local de l'élément qui lui est parent. +Par conséquent pour dessiner la ville il faudra effectuer un changement +de repère à chaque dscente dans l'abre pour décaller au fur et à mesure +le repère jusqu'a atteindre le repère de l'objet que l'on veut placer +sur la "carte". + +Pour le moment les repères "locaux" ne le sont pas vraiment, je place un +point qui sert de repère local en fonction des autres points disponibles +(pas de soucis pour çaà sauf je passe les coordonnées absolue de cet +objet au sous objets que je crée au lieu de passer les coordonnées +locales. diff --git a/main.cpp b/main.cpp index 9966c33..04e4441 100644 --- a/main.cpp +++ b/main.cpp @@ -10,7 +10,7 @@ // -> bâtiment dans le "bout" le plus "étroit", et lignes dans une seule direction dans le reste. void recursiveSubdivide(Chose* c) { - if (c->subdivide()) { + if (c->split()) { std::vector::iterator it; for (it = c->children.begin(); it != c->children.end(); ++it) { recursiveSubdivide(*it); @@ -27,7 +27,7 @@ int main() { Vertex sw(0, 0, 0); Vertex nw(0, size, 0); Chose* c = QuartierQuad::factory(Chose::initialSeed, 0, ne, se, sw, nw); - // c->subdivide(); + // c->split(); recursiveSubdivide(c); Heap h(1); diff --git a/rules/batiment/batimentquad.cpp b/rules/batiment/batimentquad.cpp index 73644cc..1349f6f 100644 --- a/rules/batiment/batimentquad.cpp +++ b/rules/batiment/batimentquad.cpp @@ -2,12 +2,20 @@ BatimentQuad::BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal entry) : Chose(), ne(ne) { addEntropy(ne, se, sw, nw); - this->ne = ne; - this->se = se; - this-> sw = sw; - this->nw = nw; this->entry = entry; - triangulation(); + lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f); + this->ne = ne-lctr; + this->se = se-lctr; + this-> sw = sw-lctr; + this->nw = nw-lctr; + triangulation(); +} + +BatimentQuad::~BatimentQuad() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); } int BatimentQuad::width() { return this->ne.x - this->sw.x; } @@ -18,7 +26,7 @@ std::vector BatimentQuad::getBoundingBoxPoints() const { return list; } -bool BatimentQuad::subdivide() { +bool BatimentQuad::split() { factory(1,1,ne,se,sw,nw); return true; } @@ -33,21 +41,21 @@ Chose* BatimentQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, V q.offset(S,-140); q.offset(W,-140); - addChild(new TrottoirQuadNormal(ne,se,q.corner[1],q.corner[0],th,E)); - addChild(new TrottoirQuadNormal(se,sw,q.corner[2],q.corner[1],th,E)); - addChild(new TrottoirQuadNormal(sw,nw,q.corner[3],q.corner[2],th,E)); - addChild(new TrottoirQuadNormal(nw,ne,q.corner[0],q.corner[3],th,E)); + addChild(new TrottoirQuadNormal(lctr+ne,lctr+se,lctr+q.corner[1],lctr+q.corner[0],th,E)); + addChild(new TrottoirQuadNormal(lctr+se,lctr+sw,lctr+q.corner[2],lctr+q.corner[1],th,E)); + addChild(new TrottoirQuadNormal(lctr+sw,lctr+nw,lctr+q.corner[3],lctr+q.corner[2],th,E)); + addChild(new TrottoirQuadNormal(lctr+nw,lctr+ne,lctr+q.corner[0],lctr+q.corner[3],th,E)); q.corner[0] = q.corner[0] + Vertex(0,0,th); q.corner[1] = q.corner[1] + Vertex(0,0,th); q.corner[2] = q.corner[2] + Vertex(0,0,th); q.corner[3] = q.corner[3] + Vertex(0,0,th); - addChild(new BatimentQuadJardin(q.corner[0],q.corner[1],q.corner[2],q.corner[3])); + addChild(new BatimentQuadJardin(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3])); q.offset(this->entry,-400); - addChild(new BatimentQuadMaison(q.corner[0],q.corner[1],q.corner[2],q.corner[3])); + addChild(new BatimentQuadMaison(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3])); return NULL; // pour compilation, à virer. } diff --git a/rules/batiment/batimentquad.hh b/rules/batiment/batimentquad.hh index 4308111..a622f5c 100644 --- a/rules/batiment/batimentquad.hh +++ b/rules/batiment/batimentquad.hh @@ -17,9 +17,10 @@ class BatimentQuad : public Chose { static const int maxHeight = 800; BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal door); + virtual ~BatimentQuad(); int width(); int height(); - virtual bool subdivide(); + virtual bool split(); virtual void triangulation(); Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual std::vector getBoundingBoxPoints() const; diff --git a/rules/batiment/batimentquadjardin.cpp b/rules/batiment/batimentquadjardin.cpp index 932a040..112b1f8 100644 --- a/rules/batiment/batimentquadjardin.cpp +++ b/rules/batiment/batimentquadjardin.cpp @@ -1,10 +1,22 @@ #include "all_includes.hh" -BatimentQuadJardin::BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) { +BatimentQuadJardin::BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { addEntropy(ne, se, sw, nw); + lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f); + this->ne = ne-lctr; + this->se = se-lctr; + this-> sw = sw-lctr; + this->nw = nw-lctr; triangulation(); } +BatimentQuadJardin::~BatimentQuadJardin() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + int BatimentQuadJardin::width() { return this->ne.x - this->sw.x; } int BatimentQuadJardin::height() { return this->ne.y - this->sw.y; } @@ -14,7 +26,7 @@ std::vector BatimentQuadJardin::getBoundingBoxPoints() const { return list; } -bool BatimentQuadJardin::subdivide() { +bool BatimentQuadJardin::split() { return true; } @@ -22,6 +34,6 @@ bool BatimentQuadJardin::subdivide() { void BatimentQuadJardin::triangulation() { triangles.reserve(2); - addTriangle(new Triangle(ne,nw,sw,0x12,0x64,0x12)); - addTriangle(new Triangle(sw,se,ne,0x10,0x60,0x10)); + addTriangle(new Triangle(lctr+ne,lctr+nw,lctr+sw,0x12,0x64,0x12)); + addTriangle(new Triangle(lctr+sw,lctr+se,lctr+ne,0x10,0x60,0x10)); } diff --git a/rules/batiment/batimentquadjardin.hh b/rules/batiment/batimentquadjardin.hh index 4be7156..9c332ab 100644 --- a/rules/batiment/batimentquadjardin.hh +++ b/rules/batiment/batimentquadjardin.hh @@ -16,9 +16,10 @@ class BatimentQuadJardin : public Chose { static const int maxHeight = 800; BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw); + virtual ~BatimentQuadJardin(); int width(); int height(); - virtual bool subdivide(); + virtual bool split(); virtual void triangulation(); Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual std::vector getBoundingBoxPoints() const; diff --git a/rules/batiment/batimentquadmaison.cpp b/rules/batiment/batimentquadmaison.cpp index 49dca45..e2251fe 100644 --- a/rules/batiment/batimentquadmaison.cpp +++ b/rules/batiment/batimentquadmaison.cpp @@ -1,10 +1,22 @@ #include "all_includes.hh" -BatimentQuadMaison::BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) { +BatimentQuadMaison::BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { addEntropy(ne, se, sw, nw); + lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f); + this->ne = ne-lctr; + this->se = se-lctr; + this-> sw = sw-lctr; + this->nw = nw-lctr; triangulation(); } +BatimentQuadMaison::~BatimentQuadMaison() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + int BatimentQuadMaison::width() { return this->ne.x - this->sw.x; } int BatimentQuadMaison::height() { return this->ne.y - this->sw.y; } @@ -14,7 +26,7 @@ std::vector BatimentQuadMaison::getBoundingBoxPoints() const { return list; } -bool BatimentQuadMaison::subdivide() { +bool BatimentQuadMaison::split() { return true; } @@ -31,14 +43,14 @@ void BatimentQuadMaison::triangulation() { Vertex toit = (neh + seh + nwh + swh) / 4 + Vertex(0,0,htoit); // 4 Murs - addTriangle(new Triangle(neh,seh,ne,0xf1,0xe3,0xad)); addTriangle(new Triangle(seh,se,ne,0xf1,0xe3,0xad)); // ne-se-seh-neh - addTriangle(new Triangle(seh,swh,se,0xf1,0xe3,0xad)); addTriangle(new Triangle(swh,sw,se,0xf1,0xe3,0xad)); // se-sw-swh-seh - addTriangle(new Triangle(swh,nwh,sw,0xf1,0xe3,0xad)); addTriangle(new Triangle(nwh,nw,sw,0xf1,0xe3,0xad)); // sw-nw-nwh-swh - addTriangle(new Triangle(nwh,neh,nw,0xf1,0xe3,0xad)); addTriangle(new Triangle(neh,ne,nw,0xf1,0xe3,0xad)); // nw-ne-neh-nwh + addTriangle(new Triangle(lctr+neh,lctr+seh,lctr+ne,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+seh,lctr+se,lctr+ne,0xf1,0xe3,0xad)); // ne-se-seh-neh + addTriangle(new Triangle(lctr+seh,lctr+swh,lctr+se,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+swh,lctr+sw,lctr+se,0xf1,0xe3,0xad)); // se-sw-swh-seh + addTriangle(new Triangle(lctr+swh,lctr+nwh,lctr+sw,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+nwh,lctr+nw,lctr+sw,0xf1,0xe3,0xad)); // sw-nw-nwh-swh + addTriangle(new Triangle(lctr+nwh,lctr+neh,lctr+nw,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+neh,lctr+ne,lctr+nw,0xf1,0xe3,0xad)); // nw-ne-neh-nwh // 1 Toit - addTriangle(new Triangle(neh,toit,seh,0x9a,0x48,0x3c)); - addTriangle(new Triangle(seh,toit,swh,0x9a,0x48,0x3c)); - addTriangle(new Triangle(swh,toit,nwh,0x9a,0x48,0x3c)); - addTriangle(new Triangle(nwh,toit,neh,0x9a,0x48,0x3c)); + addTriangle(new Triangle(lctr+neh,lctr+toit,lctr+seh,0x9a,0x48,0x3c)); + addTriangle(new Triangle(lctr+seh,lctr+toit,lctr+swh,0x9a,0x48,0x3c)); + addTriangle(new Triangle(lctr+swh,lctr+toit,lctr+nwh,0x9a,0x48,0x3c)); + addTriangle(new Triangle(lctr+nwh,lctr+toit,lctr+neh,0x9a,0x48,0x3c)); } diff --git a/rules/batiment/batimentquadmaison.hh b/rules/batiment/batimentquadmaison.hh index c9c69e9..437c376 100644 --- a/rules/batiment/batimentquadmaison.hh +++ b/rules/batiment/batimentquadmaison.hh @@ -16,9 +16,10 @@ class BatimentQuadMaison : public Chose { static const int maxHeight = 800; BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw); + virtual ~BatimentQuadMaison(); int width(); int height(); - virtual bool subdivide(); + virtual bool split(); virtual void triangulation(); Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual std::vector getBoundingBoxPoints() const; diff --git a/rules/chose.cpp b/rules/chose.cpp index 88d103c..ab73b72 100644 --- a/rules/chose.cpp +++ b/rules/chose.cpp @@ -10,8 +10,12 @@ void Chose::addTriangle(Triangle* t) { triangles.push_back(t); } -void Chose::merge() { - triangles.clear(); +bool Chose::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + // triangles.clear(); + return true; } void Chose::display() { diff --git a/rules/chose.hh b/rules/chose.hh index 475d8aa..796b76b 100644 --- a/rules/chose.hh +++ b/rules/chose.hh @@ -14,11 +14,12 @@ class Chose { int inCounter; int splitCube[6]; int mergeCube[6]; + Vertex lctr; // Local center; public : void display(); - virtual bool subdivide() = 0; - virtual void merge(); + virtual bool split() = 0; + virtual bool merge(); protected : Chose(); diff --git a/rules/quartier/quartierquad.cpp b/rules/quartier/quartierquad.cpp index 89ff6e8..0e0a993 100644 --- a/rules/quartier/quartierquad.cpp +++ b/rules/quartier/quartierquad.cpp @@ -8,6 +8,13 @@ QuartierQuad::QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() corner[NW] = nw; } +QuartierQuad::~QuartierQuad() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + std::vector QuartierQuad::getBoundingBoxPoints() const { std::vector list; return list; @@ -38,7 +45,7 @@ Chose* QuartierQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, V } } -bool QuartierQuad::subdivide() { +bool QuartierQuad::split() { return false; } diff --git a/rules/quartier/quartierquad.hh b/rules/quartier/quartierquad.hh index a527caf..e0a03f0 100644 --- a/rules/quartier/quartierquad.hh +++ b/rules/quartier/quartierquad.hh @@ -9,7 +9,8 @@ public: Vertex corner[4]; public: QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~QuartierQuad(); + virtual bool split(); virtual void triangulation(); static Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual std::vector getBoundingBoxPoints() const; diff --git a/rules/quartier/quartierquadangle.cpp b/rules/quartier/quartierquadangle.cpp index a7eb863..a05c182 100644 --- a/rules/quartier/quartierquadangle.cpp +++ b/rules/quartier/quartierquadangle.cpp @@ -4,12 +4,19 @@ QuartierQuadAngle::QuartierQuadAngle(Vertex ne, Vertex se, Vertex sw, Vertex nw) triangulation(); } +QuartierQuadAngle::~QuartierQuadAngle() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + std::vector QuartierQuadAngle::getBoundingBoxPoints() const { std::vector list; return list; } -bool QuartierQuadAngle::subdivide() { +bool QuartierQuadAngle::split() { for (int i = 0; i < 4; i++) { if (Triangle(corner[NW+i], corner[NE+i], corner[SE+i]).angle() >= Angle::d2r(130)) { Triangle t1(corner[NE+i], corner[SE+i], corner[SW+i]); diff --git a/rules/quartier/quartierquadangle.hh b/rules/quartier/quartierquadangle.hh index d6993e1..020bf0e 100644 --- a/rules/quartier/quartierquadangle.hh +++ b/rules/quartier/quartierquadangle.hh @@ -10,7 +10,8 @@ class QuartierQuadAngle : public QuartierQuad { public : QuartierQuadAngle(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~QuartierQuadAngle(); + virtual bool split(); virtual std::vector getBoundingBoxPoints() const; private : diff --git a/rules/quartier/quartierquadcarre.cpp b/rules/quartier/quartierquadcarre.cpp index 8a4979a..1e43473 100644 --- a/rules/quartier/quartierquadcarre.cpp +++ b/rules/quartier/quartierquadcarre.cpp @@ -3,12 +3,19 @@ QuartierQuadCarre::QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw) : QuartierQuad(ne, se, sw, nw) { } +QuartierQuadCarre::~QuartierQuadCarre() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + std::vector QuartierQuadCarre::getBoundingBoxPoints() const { std::vector list; return list; } -bool QuartierQuadCarre::subdivide() { +bool QuartierQuadCarre::split() { Vertex middle[4]; Quad q[4]; diff --git a/rules/quartier/quartierquadcarre.hh b/rules/quartier/quartierquadcarre.hh index 02ff970..427e0ff 100644 --- a/rules/quartier/quartierquadcarre.hh +++ b/rules/quartier/quartierquadcarre.hh @@ -10,7 +10,8 @@ class QuartierQuadCarre : public QuartierQuad { public : QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~QuartierQuadCarre(); + virtual bool split(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/rules/quartier/quartierquadrect.cpp b/rules/quartier/quartierquadrect.cpp index bc93d39..1f8fe3b 100644 --- a/rules/quartier/quartierquadrect.cpp +++ b/rules/quartier/quartierquadrect.cpp @@ -3,12 +3,19 @@ QuartierQuadRect::QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw) : QuartierQuad(ne, se, sw, nw) { } +QuartierQuadRect::~QuartierQuadRect() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + std::vector QuartierQuadRect::getBoundingBoxPoints() const { std::vector list; return list; } -bool QuartierQuadRect::subdivide() { +bool QuartierQuadRect::split() { Vertex n = Segment(corner[NW], corner[NE]).randomPos(seed, 0, 33, 67); Vertex s = Segment(corner[SE], corner[SW]).randomPos(seed, 1, 33, 67); diff --git a/rules/quartier/quartierquadrect.hh b/rules/quartier/quartierquadrect.hh index 28c2f9a..d5c8e31 100644 --- a/rules/quartier/quartierquadrect.hh +++ b/rules/quartier/quartierquadrect.hh @@ -10,7 +10,8 @@ class QuartierQuadRect : public QuartierQuad { public : QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~QuartierQuadRect(); + virtual bool split(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/rules/quartier/quartiertri.cpp b/rules/quartier/quartiertri.cpp index 41c669f..5864df2 100644 --- a/rules/quartier/quartiertri.cpp +++ b/rules/quartier/quartiertri.cpp @@ -8,6 +8,13 @@ QuartierTri::QuartierTri(Vertex left, Vertex top, Vertex right) : Chose() { triangulation(); } +QuartierTri::~QuartierTri() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + std::vector QuartierTri::getBoundingBoxPoints() const { std::vector list; return list; @@ -20,7 +27,7 @@ Chose* QuartierTri::factory(int seed, int n, Vertex left, Vertex top, Vertex rig return new QuartierTri(left, top, right); } -bool QuartierTri::subdivide() { +bool QuartierTri::split() { return false; } diff --git a/rules/quartier/quartiertri.hh b/rules/quartier/quartiertri.hh index dc12eb6..b2f92aa 100644 --- a/rules/quartier/quartiertri.hh +++ b/rules/quartier/quartiertri.hh @@ -10,7 +10,8 @@ class QuartierTri : public Chose { public : QuartierTri(Vertex left, Vertex top, Vertex right); - virtual bool subdivide(); + virtual ~QuartierTri(); + virtual bool split(); virtual void triangulation(); static Chose* factory(int seed, int n, Vertex left, Vertex top, Vertex right); virtual std::vector getBoundingBoxPoints() const; diff --git a/rules/route/routequadcarrefour.cpp b/rules/route/routequadcarrefour.cpp index 20503a5..f2f29a8 100644 --- a/rules/route/routequadcarrefour.cpp +++ b/rules/route/routequadcarrefour.cpp @@ -5,12 +5,19 @@ RouteQuadCarrefour::RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex n triangulation(); } +RouteQuadCarrefour::~RouteQuadCarrefour() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + std::vector RouteQuadCarrefour::getBoundingBoxPoints() const { std::vector list; return list; } -bool RouteQuadCarrefour::subdivide() { +bool RouteQuadCarrefour::split() { // TODO return false; } diff --git a/rules/route/routequadcarrefour.hh b/rules/route/routequadcarrefour.hh index fed8082..7239834 100644 --- a/rules/route/routequadcarrefour.hh +++ b/rules/route/routequadcarrefour.hh @@ -12,7 +12,8 @@ class RouteQuadCarrefour : public Chose { public : RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~RouteQuadCarrefour(); + virtual bool split(); virtual void triangulation(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/rules/route/routequadchaussee.cpp b/rules/route/routequadchaussee.cpp index fc5e954..2f6d4e1 100644 --- a/rules/route/routequadchaussee.cpp +++ b/rules/route/routequadchaussee.cpp @@ -4,12 +4,19 @@ RouteQuadChaussee::RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw) triangulation(); } +RouteQuadChaussee::~RouteQuadChaussee() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + std::vector RouteQuadChaussee::getBoundingBoxPoints() const { std::vector list; return list; } -bool RouteQuadChaussee::subdivide() { +bool RouteQuadChaussee::split() { // TODO return false; } diff --git a/rules/route/routequadchaussee.hh b/rules/route/routequadchaussee.hh index 65f769b..1d28f1e 100644 --- a/rules/route/routequadchaussee.hh +++ b/rules/route/routequadchaussee.hh @@ -12,7 +12,8 @@ class RouteQuadChaussee : public Chose { public : RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~RouteQuadChaussee(); + virtual bool split(); virtual void triangulation(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/rules/route/trottoirquadnormal.cpp b/rules/route/trottoirquadnormal.cpp index 74d0a9b..817cd5a 100644 --- a/rules/route/trottoirquadnormal.cpp +++ b/rules/route/trottoirquadnormal.cpp @@ -10,12 +10,19 @@ TrottoirQuadNormal::TrottoirQuadNormal(Vertex ne, Vertex se, Vertex sw, Vertex n triangulation(); } +TrottoirQuadNormal::~TrottoirQuadNormal() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + std::vector TrottoirQuadNormal::getBoundingBoxPoints() const { std::vector list; return list; } -bool TrottoirQuadNormal::subdivide() { +bool TrottoirQuadNormal::split() { // TODO return false; } diff --git a/rules/route/trottoirquadnormal.hh b/rules/route/trottoirquadnormal.hh index e1bf8a1..0d81644 100644 --- a/rules/route/trottoirquadnormal.hh +++ b/rules/route/trottoirquadnormal.hh @@ -14,7 +14,8 @@ class TrottoirQuadNormal : public Chose { public : TrottoirQuadNormal(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height, Cardinal border); - virtual bool subdivide(); + virtual ~TrottoirQuadNormal(); + virtual bool split(); virtual void triangulation(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/rules/terrain/terrainquadherbe.cpp b/rules/terrain/terrainquadherbe.cpp index 1a3252c..6e7662b 100644 --- a/rules/terrain/terrainquadherbe.cpp +++ b/rules/terrain/terrainquadherbe.cpp @@ -9,6 +9,13 @@ TerrainQuadHerbe::TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw) : triangulation(); } +TerrainQuadHerbe::~TerrainQuadHerbe() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + std::vector TerrainQuadHerbe::getBoundingBoxPoints() const { std::vector list; return list; @@ -23,7 +30,7 @@ TerrainQuadHerbe::TerrainQuadHerbe(int red, Vertex ne, Vertex se, Vertex sw, Ver triangulation(); } -bool TerrainQuadHerbe::subdivide() { +bool TerrainQuadHerbe::split() { return false; } diff --git a/rules/terrain/terrainquadherbe.hh b/rules/terrain/terrainquadherbe.hh index 0a4ddad..a052588 100644 --- a/rules/terrain/terrainquadherbe.hh +++ b/rules/terrain/terrainquadherbe.hh @@ -12,7 +12,8 @@ class TerrainQuadHerbe : public Chose { public : TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw); TerrainQuadHerbe(int red, Vertex ne, Vertex se, Vertex sw, Vertex nw); // DEBUG - virtual bool subdivide(); + virtual ~TerrainQuadHerbe(); + virtual bool split(); virtual void triangulation(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/triangle.cpp b/triangle.cpp index 299973c..637f520 100644 --- a/triangle.cpp +++ b/triangle.cpp @@ -21,8 +21,8 @@ std::ostream& operator<<(std::ostream& os, const Triangle& t) { return os << "Triangle " << t.v1 << "--" << t.v2 << "--" << t.v3 << "-- cycle"; } -Vertexf Triangle::normal(Vertex v1, Vertex v2, Vertex v3) { - Vertexf normal = (v1 - v2)*(v2 - v3); +Vertex Triangle::normal(Vertex v1, Vertex v2, Vertex v3) { + Vertex normal = (v1 - v2)*(v2 - v3); return normal / normal.norm(); } @@ -59,7 +59,7 @@ void Triangle::display() { // glVertex3d(v.x+vnormal.x*50,v.y+vnormal.y*50,v.z+vnormal.z*50); // glEnd( ); // glEnable(GL_LIGHTING); - + View::setColor(r,g,b); glNormal3d(vnormal.x,vnormal.y,vnormal.z); // glBegin(GL_TRIANGLES); diff --git a/triangle.hh b/triangle.hh index 7e4f852..07ed97b 100644 --- a/triangle.hh +++ b/triangle.hh @@ -11,7 +11,7 @@ class Triangle { unsigned char r; unsigned char g; unsigned char b; - Vertexf vnormal; + Vertex vnormal; public : friend std::ostream& operator<<(std::ostream& os, const Triangle* t); @@ -26,7 +26,7 @@ class Triangle { void display(); private : - Vertexf normal(Vertex v1, Vertex v2, Vertex v3); + Vertex normal(Vertex v1, Vertex v2, Vertex v3); }; #endif diff --git a/vertex.cpp b/vertex.cpp index 0ab77a0..40ee0e3 100644 --- a/vertex.cpp +++ b/vertex.cpp @@ -2,7 +2,7 @@ Vertex::Vertex() {} -Vertex::Vertex(int x, int y, int z): x(x), y(y), z(z) {} +Vertex::Vertex(float x, float y, float z): x(x), y(y), z(z) {} float Vertex::norm() { return std::sqrt(x*x + y*y + z*z); } @@ -31,7 +31,7 @@ Vertex Vertex::projectOn(Vertex v) { return Vertex(((int64)v.x) * scalaire / normecarre, ((int64)v.y) * scalaire / normecarre, 0); } -Vertex Vertex::setNorm(int n) { +Vertex Vertex::setNorm(float n) { int64 current = norm(); return Vertex((int64)x * (int64)n / current, (int64)y * (int64)n / current, 0); } @@ -45,7 +45,66 @@ float Vertex::cosAngle(Vertex v) { return ((double)(this->x*v.x + this->y*v.y)) / (((double)norm())*((double)v.norm())); } -Vertex::operator Vertexf() { return Vertexf(x,y,z); } +Vertex::operator Vertex() { return Vertex(x,y,z); } + +std::ostream& operator<<(std::ostream& os, const Vertex& v) { + return os << "(" << v.x << "," << v.y << "," << v.z << ")"; +} + + +Vertex operator+(const Vertex& u, const Vertex& v) { + return Vertex(u.x + v.x, u.y + v.y, u.z + v.z); +} + +Vertex operator-(const Vertex& u, const Vertex& v) { + return Vertex(u.x - v.x, u.y - v.y, u.z - v.z); +} + +Vertex operator-(const Vertex& v) { + return Vertex(-v.x, -v.y, -v.z); +} + +Vertex operator*(const Vertex& v, const float n) { + return Vertex(v.x * n, v.y * n, v.z * n); +} + +Vertex operator*(const Vertex& u, const Vertex& v) { + return Vertex( + (u.y * v.z) - (u.z * v.y), + (u.z * v.x) - (u.x * v.z), + (u.x * v.y) - (u.y * v.x) + ); +} + +Vertex operator/(const Vertex& v, const int n) { + return Vertex(v.x / n, v.y / n, v.z / n); +} + +Vertex operator/(const Vertex& v, const float f) { + return Vertex(v.x / f, v.y / f, v.z / f); +} + +Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) { + // http://electron9.phys.utk.edu/vectors/3dcoordinates.htm + return Vertex( + r * std::sin(xAngle / 180 * 3.14159) * std::cos(yAngle / 180 * 3.14159), + r * std::sin(xAngle / 180 * 3.14159) * std::sin(yAngle / 180 * 3.14159), + r * std::cos(xAngle / 180 * 3.14159) + ); +} + + + + +/* + +Vertex::Vertex() {} + +Vertex::Vertex(float x, float y, float z): x(x), y(y), z(z) {} + +float Vertex::norm() { return std::sqrt(x*x + y*y + z*z); } + +Vertex::operator Vertex() { return Vertex(x,y,z); } std::ostream& operator<<(std::ostream& os, const Vertex& v) { return os << "(" << v.x << "," << v.y << "," << v.z << ")"; @@ -59,11 +118,11 @@ Vertex operator-(const Vertex& u, const Vertex& v) { return Vertex(u.x - v.x, u.y - v.y, u.z - v.z); } -Vertex operator+(const Vertex& u, const Vertexf& v) { +Vertex operator+(const Vertex& u, const Vertex& v) { return Vertex(u.x + v.x, u.y + v.y, u.z + v.z); } -Vertex operator-(const Vertex& u, const Vertexf& v) { +Vertex operator-(const Vertex& u, const Vertex& v) { return Vertex(u.x - v.x, u.y - v.y, u.z - v.z); } @@ -99,67 +158,4 @@ Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) { r * std::cos(xAngle / 180 * 3.14159) ); } - - - - -Vertexf::Vertexf() {} - -Vertexf::Vertexf(float x, float y, float z): x(x), y(y), z(z) {} - -float Vertexf::norm() { return std::sqrt(x*x + y*y + z*z); } - -Vertexf::operator Vertex() { return Vertex(x,y,z); } - -std::ostream& operator<<(std::ostream& os, const Vertexf& v) { - return os << "(" << v.x << "," << v.y << "," << v.z << ")"; -} - -Vertexf operator+(const Vertexf& u, const Vertexf& v) { - return Vertexf(u.x + v.x, u.y + v.y, u.z + v.z); -} - -Vertexf operator-(const Vertexf& u, const Vertex& v) { - return Vertexf(u.x - v.x, u.y - v.y, u.z - v.z); -} - -Vertexf operator+(const Vertexf& u, const Vertex& v) { - return Vertexf(u.x + v.x, u.y + v.y, u.z + v.z); -} - -Vertexf operator-(const Vertexf& u, const Vertexf& v) { - return Vertexf(u.x - v.x, u.y - v.y, u.z - v.z); -} - -Vertexf operator-(const Vertexf& v) { - return Vertexf(-v.x, -v.y, -v.z); -} - -Vertexf operator*(const Vertexf& v, const int n) { - return Vertexf(v.x * n, v.y * n, v.z * n); -} - -Vertexf operator*(const Vertexf& u, const Vertexf& v) { - return Vertexf( - (u.y * v.z) - (u.z * v.y), - (u.z * v.x) - (u.x * v.z), - (u.x * v.y) - (u.y * v.x) - ); -} - -Vertexf operator/(const Vertexf& v, const int n) { - return Vertexf(v.x / n, v.y / n, v.z / n); -} - -Vertexf operator/(const Vertexf& v, const float f) { - return Vertexf(v.x / f, v.y / f, v.z / f); -} - -Vertexf Vertexf::fromSpherical(float r, float xAngle, float yAngle) { - // http://electron9.phys.utk.edu/vectors/3dcoordinates.htm - return Vertexf( - r * std::sin(xAngle / 180 * 3.14159) * std::cos(yAngle / 180 * 3.14159), - r * std::sin(xAngle / 180 * 3.14159) * std::sin(yAngle / 180 * 3.14159), - r * std::cos(xAngle / 180 * 3.14159) - ); -} +*/ diff --git a/vertex.hh b/vertex.hh index 246ad6d..ca371f7 100644 --- a/vertex.hh +++ b/vertex.hh @@ -2,27 +2,51 @@ #define _VERTEX_HH_ #include "all_includes.hh" -class Vertexf; class Vertex { public : - int x; - int y; - int z; + float x; + float y; + float z; public : Vertex(); - Vertex(int x, int y, int z); + Vertex(float x, float y, float z); float norm(); Vertex projectOn(Vertex v); - Vertex setNorm(int n); + Vertex setNorm(float n); Vertex perpendicular(); // Perpendiculaire 2D dans le sens contraire des aiguilles d'une montre. float cosAngle(Vertex v); // cosinus de l'angle entre this et v. static Vertex fromSpherical(float r, float xAngle, float yAngle); friend Vertex intersection(Vertex a, Vertex b, Vertex c, Vertex d); // Intersection entre (a,b) et (c,d). public : - operator Vertexf(); + operator Vertex(); + friend std::ostream& operator<<(std::ostream& os, const Vertex& v); + friend Vertex operator+(const Vertex& u, const Vertex& v); + friend Vertex operator-(const Vertex& u, const Vertex& v); + friend Vertex operator-(const Vertex& v); + friend Vertex operator*(const Vertex& v, const float n); + friend Vertex operator*(const Vertex& u, const Vertex& v); + friend Vertex operator/(const Vertex& v, const int n); + friend Vertex operator/(const Vertex& v, const float f); +}; + +/* +class Vertex { + public : + float x; + float y; + float z; + + public : + Vertex(); + Vertex(float x, float y, float z); + float norm(); + static Vertex fromSpherical(float r, float xAngle, float yAngle); + + public : + operator Vertex(); friend std::ostream& operator<<(std::ostream& os, const Vertex& v); friend Vertex operator+(const Vertex& u, const Vertex& v); friend Vertex operator-(const Vertex& u, const Vertex& v); @@ -31,34 +55,8 @@ class Vertex { friend Vertex operator*(const Vertex& u, const Vertex& v); friend Vertex operator/(const Vertex& v, const int n); friend Vertex operator/(const Vertex& v, const float f); - friend Vertex operator+(const Vertex& u, const Vertexf& v); - friend Vertex operator-(const Vertex& u, const Vertexf& v); + friend Vertex operator+(const Vertex& u, const Vertex& v); + friend Vertex operator-(const Vertex& u, const Vertex& v); }; - -class Vertexf { - public : - float x; - float y; - float z; - - public : - Vertexf(); - Vertexf(float x, float y, float z); - float norm(); - static Vertexf fromSpherical(float r, float xAngle, float yAngle); - - public : - operator Vertex(); - friend std::ostream& operator<<(std::ostream& os, const Vertexf& v); - friend Vertexf operator+(const Vertexf& u, const Vertexf& v); - friend Vertexf operator-(const Vertexf& u, const Vertexf& v); - friend Vertexf operator-(const Vertexf& v); - friend Vertexf operator*(const Vertexf& v, const int n); - friend Vertexf operator*(const Vertexf& u, const Vertexf& v); - friend Vertexf operator/(const Vertexf& v, const int n); - friend Vertexf operator/(const Vertexf& v, const float f); - friend Vertexf operator+(const Vertexf& u, const Vertex& v); - friend Vertexf operator-(const Vertexf& u, const Vertex& v); -}; - +*/ #endif diff --git a/view.cpp b/view.cpp index e37cc80..51be1a6 100644 --- a/view.cpp +++ b/view.cpp @@ -1,7 +1,7 @@ #include "all_includes.hh" -// camera(Camera(Vertexf(1000,1000,2000),45,100,1000,0.6) -View::View(Chose* root) : root(root), camera(Camera(Vertexf(9600,10000,15300),0,179,1000,0.6)) { +// camera(Camera(Vertex(1000,1000,2000),45,100,1000,0.6) +View::View(Chose* root) : root(root), camera(Camera(Vertex(9600,10000,15300),0,179,1000,0.6)) { initWindow(); mainLoop(); } @@ -25,17 +25,17 @@ void View::initWindow() { gluPerspective(70,(double)windowWidth/windowHeight,1,100000); // back frustum : 1km glEnable(GL_DEPTH_TEST); glewInit(); - + float MatSpec[4] = {0.0f, 0.0f, 0.0f, 1.0f}; float MatDif[4] = {0.5f, 0.5f, 0.5f, 1.0f}; float MatAmb[4] = {0.3f, 0.3f, 0.6f, 1.0f}; float shininess = 128.0f; - + glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,MatSpec); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MatDif); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,MatAmb); glMaterialfv(GL_FRONT,GL_SHININESS,&shininess); - + glEnable(GL_LIGHTING); // Active l'éclairage glEnable(GL_LIGHT0); // Active la lumière 0; } @@ -62,13 +62,13 @@ void View::displayAxes() { glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line glVertex3f(2500.0f, 0.0f, 0.0f); // ending point of the line glEnd( ); - + glBegin(GL_LINES); glColor3ub(0,255,0); glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line glVertex3f(0.0f, 2500.0f, 0.0f); // ending point of the line glEnd( ); - + glBegin(GL_LINES); glColor3ub(0,0,255); glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line @@ -81,18 +81,18 @@ void View::displayAxes() { void View::renderScene(int lastTime, int currentTime) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ; - + camera.animation(currentTime-lastTime); camera.setCamera(); - + setLight(); //displayAxes(); glBegin(GL_TRIANGLES); root->display(); glEnd(); - + glFlush(); SDL_GL_SwapBuffers(); } @@ -107,7 +107,7 @@ void View::mainLoop() { int lastTime = SDL_GetTicks() - 30; int currentTime = 0; - + while (continuer) { lastTime = currentTime; currentTime = SDL_GetTicks(); @@ -133,9 +133,9 @@ void View::mainLoop() { SDL_Quit(); } -Camera::Camera(Vertexf pos, float xA, float yA, int moveSensitivity, float mouseSensitivity) +Camera::Camera(Vertex pos, float xA, float yA, int moveSensitivity, float mouseSensitivity) : cameraCenter(pos), - cameraSight(cameraCenter + Vertexf::fromSpherical(100,yA,xA)), + cameraSight(cameraCenter + Vertex::fromSpherical(100,yA,xA)), xAngle(xA), yAngle(yA), moveDist(moveSensitivity), @@ -151,7 +151,7 @@ std::ostream& Camera::print(std::ostream& os) const { } void Camera::setCamera() { - cameraSight = cameraCenter + Vertexf::fromSpherical(100, yAngle, xAngle); + cameraSight = cameraCenter + Vertex::fromSpherical(100, yAngle, xAngle); gluLookAt(cameraCenter.x,cameraCenter.y,cameraCenter.z, cameraSight.x, cameraSight.y, cameraSight.z,0,0,1); } @@ -214,17 +214,17 @@ void Camera::keyboard(const SDL_KeyboardEvent &eventKey) { void Camera::animation(int elapsedTime) { float diff = ((float)(elapsedTime+1)/1000.)*(float)moveDist; - + if(up) - cameraCenter = cameraCenter + Vertexf::fromSpherical(diff, yAngle, xAngle); + cameraCenter = cameraCenter + Vertex::fromSpherical(diff, yAngle, xAngle); if(down) - cameraCenter = cameraCenter - Vertexf::fromSpherical(diff, yAngle, xAngle); + cameraCenter = cameraCenter - Vertex::fromSpherical(diff, yAngle, xAngle); if(left) - cameraCenter = cameraCenter - Vertexf::fromSpherical(diff, 90, xAngle - 90); + cameraCenter = cameraCenter - Vertex::fromSpherical(diff, 90, xAngle - 90); if(right) - cameraCenter = cameraCenter + Vertexf::fromSpherical(diff, 90, xAngle - 90); + cameraCenter = cameraCenter + Vertex::fromSpherical(diff, 90, xAngle - 90); if(pageUp) - cameraCenter = cameraCenter - Vertexf::fromSpherical(diff, yAngle + 90, xAngle); + cameraCenter = cameraCenter - Vertex::fromSpherical(diff, yAngle + 90, xAngle); if(pageDown) - cameraCenter = cameraCenter + Vertexf::fromSpherical(diff, yAngle + 90, xAngle); + cameraCenter = cameraCenter + Vertex::fromSpherical(diff, yAngle + 90, xAngle); } diff --git a/view.hh b/view.hh index 65b015e..2f5cfba 100644 --- a/view.hh +++ b/view.hh @@ -11,8 +11,8 @@ class Camera { public : - Vertexf cameraCenter; - Vertexf cameraSight; + Vertex cameraCenter; + Vertex cameraSight; private : float xAngle; @@ -27,7 +27,7 @@ class Camera { bool pageDown; public : - Camera(Vertexf pos, float xA, float yA, int moveSensitivity, float mouseSensitivity); + Camera(Vertex pos, float xA, float yA, int moveSensitivity, float mouseSensitivity); void setCamera(); void mouseMotion(const SDL_MouseMotionEvent &event); void keyboard(const SDL_KeyboardEvent &event);