www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit ab8622338e1130ef526466c2d34967a743c6030b
parent 46189836f548499ff77e33c4886db48b8b768e67
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Tue, 20 Dec 2011 15:38:28 +0100

Merge branch 'master' of github.com:jsmaniac/2011-m2s3-city-builder

Conflicts:
	rules/chose.hh

Diffstat:
Abugs/new/2011-18-12-1926-reperelocal.txt | 14++++++++++++++
Mmain.cpp | 4++--
Mrules/batiment/batimentquad.cpp | 32++++++++++++++++++++------------
Mrules/batiment/batimentquad.hh | 3++-
Mrules/batiment/batimentquadjardin.cpp | 20++++++++++++++++----
Mrules/batiment/batimentquadjardin.hh | 3++-
Mrules/batiment/batimentquadmaison.cpp | 32++++++++++++++++++++++----------
Mrules/batiment/batimentquadmaison.hh | 3++-
Mrules/chose.cpp | 8++++++--
Mrules/chose.hh | 5+++--
Mrules/quartier/quartierquad.cpp | 9++++++++-
Mrules/quartier/quartierquad.hh | 3++-
Mrules/quartier/quartierquadangle.cpp | 9++++++++-
Mrules/quartier/quartierquadangle.hh | 3++-
Mrules/quartier/quartierquadcarre.cpp | 9++++++++-
Mrules/quartier/quartierquadcarre.hh | 3++-
Mrules/quartier/quartierquadrect.cpp | 9++++++++-
Mrules/quartier/quartierquadrect.hh | 3++-
Mrules/quartier/quartiertri.cpp | 9++++++++-
Mrules/quartier/quartiertri.hh | 3++-
Mrules/route/routequadcarrefour.cpp | 9++++++++-
Mrules/route/routequadcarrefour.hh | 3++-
Mrules/route/routequadchaussee.cpp | 9++++++++-
Mrules/route/routequadchaussee.hh | 3++-
Mrules/route/trottoirquadnormal.cpp | 9++++++++-
Mrules/route/trottoirquadnormal.hh | 3++-
Mrules/terrain/terrainquadherbe.cpp | 9++++++++-
Mrules/terrain/terrainquadherbe.hh | 3++-
Mtriangle.cpp | 6+++---
Mtriangle.hh | 4++--
Mvertex.cpp | 70+++++++++++++++++++++++++++++++++-------------------------------------
Mvertex.hh | 48+++++++++++++++++++++++-------------------------
Mview.cpp | 44++++++++++++++++++++++----------------------
Mview.hh | 6+++---
34 files changed, 265 insertions(+), 145 deletions(-)

diff --git a/bugs/new/2011-18-12-1926-reperelocal.txt 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 @@ -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<Chose*>::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 @@ -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<Vertex*> 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 @@ -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<Vertex*> getBoundingBoxPoints() const; diff --git 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<Vertex*> 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 @@ -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<Vertex*> getBoundingBoxPoints() const; diff --git 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<Vertex*> 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 @@ -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<Vertex*> getBoundingBoxPoints() const; diff --git 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 @@ -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 @@ -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<Vertex*> QuartierQuad::getBoundingBoxPoints() const { std::vector<Vertex*> 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 @@ -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<Vertex*> getBoundingBoxPoints() const; diff --git 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<Vertex*> QuartierQuadAngle::getBoundingBoxPoints() const { std::vector<Vertex*> 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 @@ -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<Vertex*> getBoundingBoxPoints() const; private : diff --git 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<Vertex*> QuartierQuadCarre::getBoundingBoxPoints() const { std::vector<Vertex*> 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 @@ -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<Vertex*> getBoundingBoxPoints() const; }; diff --git 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<Vertex*> QuartierQuadRect::getBoundingBoxPoints() const { std::vector<Vertex*> 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 @@ -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<Vertex*> getBoundingBoxPoints() const; }; diff --git 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<Vertex*> QuartierTri::getBoundingBoxPoints() const { std::vector<Vertex*> 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 @@ -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<Vertex*> getBoundingBoxPoints() const; diff --git 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<Vertex*> RouteQuadCarrefour::getBoundingBoxPoints() const { std::vector<Vertex*> list; return list; } -bool RouteQuadCarrefour::subdivide() { +bool RouteQuadCarrefour::split() { // TODO return false; } diff --git 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<Vertex*> getBoundingBoxPoints() const; }; diff --git 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<Vertex*> RouteQuadChaussee::getBoundingBoxPoints() const { std::vector<Vertex*> list; return list; } -bool RouteQuadChaussee::subdivide() { +bool RouteQuadChaussee::split() { // TODO return false; } diff --git 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<Vertex*> getBoundingBoxPoints() const; }; diff --git 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<Vertex*> TrottoirQuadNormal::getBoundingBoxPoints() const { std::vector<Vertex*> list; return list; } -bool TrottoirQuadNormal::subdivide() { +bool TrottoirQuadNormal::split() { // TODO return false; } diff --git 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<Vertex*> getBoundingBoxPoints() const; }; diff --git 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<Vertex*> TerrainQuadHerbe::getBoundingBoxPoints() const { std::vector<Vertex*> 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 @@ -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<Vertex*> getBoundingBoxPoints() const; }; diff --git 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 @@ -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 @@ -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,12 +45,13 @@ 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); } @@ -59,19 +60,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) { - return Vertex(u.x + v.x, u.y + v.y, u.z + v.z); -} - -Vertex operator-(const Vertex& u, const Vertexf& 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 int n) { +Vertex operator*(const Vertex& v, const float n) { return Vertex(v.x * n, v.y * n, v.z * n); } @@ -103,63 +96,66 @@ Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) { -Vertexf::Vertexf() {} +/* -Vertexf::Vertexf(float x, float y, float z): x(x), y(y), z(z) {} +Vertex::Vertex() {} + +Vertex::Vertex(float x, float y, float z): x(x), y(y), z(z) {} -float Vertexf::norm() { return std::sqrt(x*x + y*y + z*z); } +float Vertex::norm() { return std::sqrt(x*x + y*y + z*z); } -Vertexf::operator Vertex() { return Vertex(x,y,z); } +Vertex::operator Vertex() { return Vertex(x,y,z); } -std::ostream& operator<<(std::ostream& os, const Vertexf& v) { +std::ostream& operator<<(std::ostream& os, const Vertex& 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); +Vertex operator+(const Vertex& u, const Vertex& v) { + return Vertex(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); +Vertex operator-(const Vertex& u, const Vertex& v) { + return Vertex(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); +Vertex operator+(const Vertex& u, const Vertex& v) { + return Vertex(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); +Vertex operator-(const Vertex& u, const Vertex& v) { + return Vertex(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); +Vertex operator-(const Vertex& v) { + return Vertex(-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); +Vertex operator*(const Vertex& v, const int n) { + return Vertex(v.x * n, v.y * n, v.z * n); } -Vertexf operator*(const Vertexf& u, const Vertexf& v) { - return Vertexf( +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) ); } -Vertexf operator/(const Vertexf& v, const int n) { - return Vertexf(v.x / n, v.y / n, v.z / n); +Vertex operator/(const Vertex& v, const int n) { + return Vertex(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); +Vertex operator/(const Vertex& v, const float f) { + return Vertex(v.x / f, v.y / f, v.z / f); } -Vertexf Vertexf::fromSpherical(float r, float xAngle, float yAngle) { +Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) { // http://electron9.phys.utk.edu/vectors/3dcoordinates.htm - return Vertexf( + 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) ); } +*/ diff --git a/vertex.hh b/vertex.hh @@ -2,63 +2,61 @@ #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 int n); + 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); - friend Vertex operator+(const Vertex& u, const Vertexf& v); - friend Vertex operator-(const Vertex& u, const Vertexf& v); }; -class Vertexf { +/* +class Vertex { public : float x; float y; float z; public : - Vertexf(); - Vertexf(float x, float y, float z); + Vertex(); + Vertex(float x, float y, float z); float norm(); - static Vertexf fromSpherical(float r, float xAngle, float yAngle); + static Vertex 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); + 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 int 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); + friend Vertex operator+(const Vertex& u, const Vertex& v); + friend Vertex operator-(const Vertex& u, const Vertex& v); }; - +*/ #endif diff --git 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 @@ -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);