From 80aad0bd141673316e9ef3b2bbb24e2c563cf6e7 Mon Sep 17 00:00:00 2001 From: Yoann Date: Sun, 18 Dec 2011 14:35:49 +0100 Subject: [PATCH 1/5] Renomage de la fonction subdivide en split et ajout de la fonction de merge. --- main.cpp | 4 ++-- rules/batiment/batimentquad.cpp | 17 ++++++++++++++++- rules/batiment/batimentquad.hh | 4 +++- rules/batiment/batimentquadjardin.cpp | 17 ++++++++++++++++- rules/batiment/batimentquadjardin.hh | 4 +++- rules/batiment/batimentquadmaison.cpp | 17 ++++++++++++++++- rules/batiment/batimentquadmaison.hh | 4 +++- rules/chose.hh | 3 ++- rules/quartier/quartierquad.cpp | 17 ++++++++++++++++- rules/quartier/quartierquad.hh | 4 +++- rules/quartier/quartierquadangle.cpp | 17 ++++++++++++++++- rules/quartier/quartierquadangle.hh | 4 +++- rules/quartier/quartierquadcarre.cpp | 17 ++++++++++++++++- rules/quartier/quartierquadcarre.hh | 4 +++- rules/quartier/quartierquadrect.cpp | 17 ++++++++++++++++- rules/quartier/quartierquadrect.hh | 4 +++- rules/quartier/quartiertri.cpp | 17 ++++++++++++++++- rules/quartier/quartiertri.hh | 4 +++- rules/route/routequadcarrefour.cpp | 17 ++++++++++++++++- rules/route/routequadcarrefour.hh | 4 +++- rules/route/routequadchaussee.cpp | 17 ++++++++++++++++- rules/route/routequadchaussee.hh | 4 +++- rules/route/trottoirquadnormal.cpp | 17 ++++++++++++++++- rules/route/trottoirquadnormal.hh | 4 +++- rules/terrain/terrainquadherbe.cpp | 17 ++++++++++++++++- rules/terrain/terrainquadherbe.hh | 4 +++- 26 files changed, 232 insertions(+), 27 deletions(-) diff --git a/main.cpp b/main.cpp index 1139556..0adb618 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); View *v = new View(c); diff --git a/rules/batiment/batimentquad.cpp b/rules/batiment/batimentquad.cpp index 73644cc..00e0555 100644 --- a/rules/batiment/batimentquad.cpp +++ b/rules/batiment/batimentquad.cpp @@ -10,6 +10,13 @@ BatimentQuad::BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal 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; } int BatimentQuad::height() { return this->ne.y - this->sw.y; } @@ -18,11 +25,19 @@ std::vector BatimentQuad::getBoundingBoxPoints() const { return list; } -bool BatimentQuad::subdivide() { +bool BatimentQuad::split() { factory(1,1,ne,se,sw,nw); return true; } +bool BatimentQuad::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + Chose* BatimentQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw) { int th = 20; // Terrain height. Quad q = Quad(ne,se,sw,nw); diff --git a/rules/batiment/batimentquad.hh b/rules/batiment/batimentquad.hh index 4308111..7337c39 100644 --- a/rules/batiment/batimentquad.hh +++ b/rules/batiment/batimentquad.hh @@ -17,9 +17,11 @@ 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 bool merge(); 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..fe9b94e 100644 --- a/rules/batiment/batimentquadjardin.cpp +++ b/rules/batiment/batimentquadjardin.cpp @@ -5,6 +5,13 @@ BatimentQuadJardin::BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex n 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,11 +21,19 @@ std::vector BatimentQuadJardin::getBoundingBoxPoints() const { return list; } -bool BatimentQuadJardin::subdivide() { +bool BatimentQuadJardin::split() { return true; } +bool BatimentQuadJardin::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + void BatimentQuadJardin::triangulation() { triangles.reserve(2); diff --git a/rules/batiment/batimentquadjardin.hh b/rules/batiment/batimentquadjardin.hh index 4be7156..b048706 100644 --- a/rules/batiment/batimentquadjardin.hh +++ b/rules/batiment/batimentquadjardin.hh @@ -16,9 +16,11 @@ 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 bool merge(); 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..5311552 100644 --- a/rules/batiment/batimentquadmaison.cpp +++ b/rules/batiment/batimentquadmaison.cpp @@ -5,6 +5,13 @@ BatimentQuadMaison::BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex n 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,11 +21,19 @@ std::vector BatimentQuadMaison::getBoundingBoxPoints() const { return list; } -bool BatimentQuadMaison::subdivide() { +bool BatimentQuadMaison::split() { return true; } +bool BatimentQuadMaison::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + void BatimentQuadMaison::triangulation() { triangles.reserve(12); diff --git a/rules/batiment/batimentquadmaison.hh b/rules/batiment/batimentquadmaison.hh index c9c69e9..f90356a 100644 --- a/rules/batiment/batimentquadmaison.hh +++ b/rules/batiment/batimentquadmaison.hh @@ -16,9 +16,11 @@ 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 bool merge(); 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.hh b/rules/chose.hh index 0ee2bb8..64fe8f5 100644 --- a/rules/chose.hh +++ b/rules/chose.hh @@ -16,7 +16,8 @@ class Chose { public : void display(); - virtual bool subdivide() = 0; + virtual bool split() = 0; + virtual bool merge() = 0; protected : Chose(); diff --git a/rules/quartier/quartierquad.cpp b/rules/quartier/quartierquad.cpp index 89ff6e8..6b076d7 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,10 +45,18 @@ Chose* QuartierQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, V } } -bool QuartierQuad::subdivide() { +bool QuartierQuad::split() { return false; } +bool QuartierQuad::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + void QuartierQuad::triangulation() { triangles.reserve(2); addTriangle(new Triangle(corner[NE], corner[NW], corner[SW], 0xc0, 0xc0, 0xc0)); diff --git a/rules/quartier/quartierquad.hh b/rules/quartier/quartierquad.hh index a527caf..5daa3e7 100644 --- a/rules/quartier/quartierquad.hh +++ b/rules/quartier/quartierquad.hh @@ -9,7 +9,9 @@ public: Vertex corner[4]; public: QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~QuartierQuad(); + virtual bool split(); + virtual bool merge(); 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..37ad470 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]); @@ -59,3 +66,11 @@ bool QuartierQuadAngle::subdivide() { addChild(new TerrainQuadHerbe(corner[NE], corner[SE], corner[SW], corner[NW])); return true; } + +bool QuartierQuadAngle::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} diff --git a/rules/quartier/quartierquadangle.hh b/rules/quartier/quartierquadangle.hh index d6993e1..35c555f 100644 --- a/rules/quartier/quartierquadangle.hh +++ b/rules/quartier/quartierquadangle.hh @@ -10,7 +10,9 @@ class QuartierQuadAngle : public QuartierQuad { public : QuartierQuadAngle(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~QuartierQuadAngle(); + virtual bool split(); + virtual bool merge(); virtual std::vector getBoundingBoxPoints() const; private : diff --git a/rules/quartier/quartierquadcarre.cpp b/rules/quartier/quartierquadcarre.cpp index 8a4979a..fd31532 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]; @@ -30,3 +37,11 @@ bool QuartierQuadCarre::subdivide() { } return true; } + +bool QuartierQuadCarre::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} diff --git a/rules/quartier/quartierquadcarre.hh b/rules/quartier/quartierquadcarre.hh index 02ff970..8d554c8 100644 --- a/rules/quartier/quartierquadcarre.hh +++ b/rules/quartier/quartierquadcarre.hh @@ -10,7 +10,9 @@ class QuartierQuadCarre : public QuartierQuad { public : QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~QuartierQuadCarre(); + virtual bool split(); + virtual bool merge(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/rules/quartier/quartierquadrect.cpp b/rules/quartier/quartierquadrect.cpp index bc93d39..bc79722 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); @@ -22,3 +29,11 @@ bool QuartierQuadRect::subdivide() { addChild(QuartierQuad::factory(seed, 3, qw.corner[0], qw.corner[1], qw.corner[2], qw.corner[3])); return true; } + +bool QuartierQuadRect::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} diff --git a/rules/quartier/quartierquadrect.hh b/rules/quartier/quartierquadrect.hh index 28c2f9a..fc5d5ea 100644 --- a/rules/quartier/quartierquadrect.hh +++ b/rules/quartier/quartierquadrect.hh @@ -10,7 +10,9 @@ class QuartierQuadRect : public QuartierQuad { public : QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~QuartierQuadRect(); + virtual bool split(); + virtual bool merge(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/rules/quartier/quartiertri.cpp b/rules/quartier/quartiertri.cpp index 41c669f..2fecf21 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,10 +27,18 @@ 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; } +bool QuartierTri::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + void QuartierTri::triangulation() { triangles.reserve(1); addTriangle(new Triangle(corner[0], corner[1], corner[2], 0xf0, 0xc0, 0xc0)); diff --git a/rules/quartier/quartiertri.hh b/rules/quartier/quartiertri.hh index dc12eb6..dcc3a13 100644 --- a/rules/quartier/quartiertri.hh +++ b/rules/quartier/quartiertri.hh @@ -10,7 +10,9 @@ class QuartierTri : public Chose { public : QuartierTri(Vertex left, Vertex top, Vertex right); - virtual bool subdivide(); + virtual ~QuartierTri(); + virtual bool split(); + virtual bool merge(); 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..14a1e5a 100644 --- a/rules/route/routequadcarrefour.cpp +++ b/rules/route/routequadcarrefour.cpp @@ -5,16 +5,31 @@ 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; } +bool RouteQuadCarrefour::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + void RouteQuadCarrefour::triangulation() { triangles.reserve(2); addTriangle(new Triangle(ne, nw, sw, 0x36, 0x36, 0x36)); diff --git a/rules/route/routequadcarrefour.hh b/rules/route/routequadcarrefour.hh index fed8082..5e74a17 100644 --- a/rules/route/routequadcarrefour.hh +++ b/rules/route/routequadcarrefour.hh @@ -12,7 +12,9 @@ class RouteQuadCarrefour : public Chose { public : RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~RouteQuadCarrefour(); + virtual bool split(); + virtual bool merge(); virtual void triangulation(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/rules/route/routequadchaussee.cpp b/rules/route/routequadchaussee.cpp index fc5e954..fd050ee 100644 --- a/rules/route/routequadchaussee.cpp +++ b/rules/route/routequadchaussee.cpp @@ -4,16 +4,31 @@ 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; } +bool RouteQuadChaussee::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + void RouteQuadChaussee::triangulation() { triangles.reserve(2); addTriangle(new Triangle(ne, nw, sw, 0x36, 0x36, 0x36)); diff --git a/rules/route/routequadchaussee.hh b/rules/route/routequadchaussee.hh index 65f769b..b9a3fec 100644 --- a/rules/route/routequadchaussee.hh +++ b/rules/route/routequadchaussee.hh @@ -12,7 +12,9 @@ class RouteQuadChaussee : public Chose { public : RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool subdivide(); + virtual ~RouteQuadChaussee(); + virtual bool split(); + virtual bool merge(); virtual void triangulation(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/rules/route/trottoirquadnormal.cpp b/rules/route/trottoirquadnormal.cpp index 74d0a9b..fd8d046 100644 --- a/rules/route/trottoirquadnormal.cpp +++ b/rules/route/trottoirquadnormal.cpp @@ -10,16 +10,31 @@ 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; } +bool TrottoirQuadNormal::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + void TrottoirQuadNormal::triangulation() { Vertex h = Vertex(0,0,height); Quad q = Quad(ne,se,sw,nw); diff --git a/rules/route/trottoirquadnormal.hh b/rules/route/trottoirquadnormal.hh index e1bf8a1..9d3cb29 100644 --- a/rules/route/trottoirquadnormal.hh +++ b/rules/route/trottoirquadnormal.hh @@ -14,7 +14,9 @@ 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 bool merge(); virtual void triangulation(); virtual std::vector getBoundingBoxPoints() const; }; diff --git a/rules/terrain/terrainquadherbe.cpp b/rules/terrain/terrainquadherbe.cpp index 1a3252c..e65d0a1 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,10 +30,18 @@ TerrainQuadHerbe::TerrainQuadHerbe(int red, Vertex ne, Vertex se, Vertex sw, Ver triangulation(); } -bool TerrainQuadHerbe::subdivide() { +bool TerrainQuadHerbe::split() { return false; } +bool TerrainQuadHerbe::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + void TerrainQuadHerbe::triangulation() { triangles.reserve(2); addTriangle(new Triangle(corner[NE], corner[NW], corner[SW], red, 0xaa, 0x22)); diff --git a/rules/terrain/terrainquadherbe.hh b/rules/terrain/terrainquadherbe.hh index 0a4ddad..9406db3 100644 --- a/rules/terrain/terrainquadherbe.hh +++ b/rules/terrain/terrainquadherbe.hh @@ -12,7 +12,9 @@ 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 bool merge(); virtual void triangulation(); virtual std::vector getBoundingBoxPoints() const; }; From 419db20c4a118d93bbfcf305056acc1ccf44dfcf Mon Sep 17 00:00:00 2001 From: Yoann Date: Sun, 18 Dec 2011 18:46:25 +0100 Subject: [PATCH 2/5] Passage des sommets en flottant. --- triangle.cpp | 6 +-- triangle.hh | 4 +- vertex.cpp | 134 +++++++++++++++++++++++++-------------------------- vertex.hh | 70 +++++++++++++-------------- view.cpp | 44 ++++++++--------- view.hh | 6 +-- 6 files changed, 129 insertions(+), 135 deletions(-) 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); From f7d889008a59cbe4a8860974bb9a229831853847 Mon Sep 17 00:00:00 2001 From: Yoann Date: Sun, 18 Dec 2011 19:08:36 +0100 Subject: [PATCH 3/5] =?UTF-8?q?Ajout=20de=20l'attribut=20lctr=20(local=20c?= =?UTF-8?q?enter)=20qui=20permet=20d'avoir=20un=20rep=C3=A8re=20local=20?= =?UTF-8?q?=C3=A0=20l'objet.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rules/batiment/batimentquad.cpp | 23 ++++++++++++----------- rules/chose.hh | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/rules/batiment/batimentquad.cpp b/rules/batiment/batimentquad.cpp index 00e0555..7e5a314 100644 --- a/rules/batiment/batimentquad.cpp +++ b/rules/batiment/batimentquad.cpp @@ -2,12 +2,13 @@ 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() { @@ -48,21 +49,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/chose.hh b/rules/chose.hh index 64fe8f5..0a04268 100644 --- a/rules/chose.hh +++ b/rules/chose.hh @@ -13,6 +13,7 @@ class Chose { int inCounter; int splitCube[6]; int mergeCube[6]; + Vertex lctr; // Local center; public : void display(); From 9c9b65e2c3c528118c2a63bbfbbe55d12f99a94b Mon Sep 17 00:00:00 2001 From: Yoann Date: Sun, 18 Dec 2011 19:24:44 +0100 Subject: [PATCH 4/5] =?UTF-8?q?Tous=20les=20batiments=20poss=C3=A8dent=20u?= =?UTF-8?q?n=20rep=C3=A8re=20local.=20Il=20faut=20par=20contre=20revoir=20?= =?UTF-8?q?l'impl=C3=A9mentation=20du=20rep=C3=A8re=20local=20voir=20fichi?= =?UTF-8?q?er=20bug=20correspondant.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rules/batiment/batimentquadjardin.cpp | 11 ++++++++--- rules/batiment/batimentquadmaison.cpp | 23 ++++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/rules/batiment/batimentquadjardin.cpp b/rules/batiment/batimentquadjardin.cpp index fe9b94e..33943e6 100644 --- a/rules/batiment/batimentquadjardin.cpp +++ b/rules/batiment/batimentquadjardin.cpp @@ -1,7 +1,12 @@ #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(); } @@ -37,6 +42,6 @@ bool BatimentQuadJardin::merge() { 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/batimentquadmaison.cpp b/rules/batiment/batimentquadmaison.cpp index 5311552..ca1b1eb 100644 --- a/rules/batiment/batimentquadmaison.cpp +++ b/rules/batiment/batimentquadmaison.cpp @@ -1,7 +1,12 @@ #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(); } @@ -46,14 +51,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)); } From 01dd83e78f6cd37e4b4b40c781609f62b83e6c11 Mon Sep 17 00:00:00 2001 From: Yoann Date: Sun, 18 Dec 2011 19:31:56 +0100 Subject: [PATCH 5/5] =?UTF-8?q?Ajout=20d'un=20=C3=A9l=C3=A9ment=20dans=20b?= =?UTF-8?q?ug/new=20sur=20l'impl=C3=A9mentation=20d'un=20rep=C3=A8re=20loc?= =?UTF-8?q?al.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bugs/new/2011-18-12-1926-reperelocal.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 bugs/new/2011-18-12-1926-reperelocal.txt 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.